Skip to content

Commit

Permalink
eslint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
atherdon committed Sep 3, 2021
1 parent 34512c3 commit 4398b3f
Show file tree
Hide file tree
Showing 52 changed files with 188 additions and 279 deletions.
35 changes: 16 additions & 19 deletions src/_depricated-helpers.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,26 @@
function replaceMarkdown(regexp, callback) {

// console.log('helpers- replace markdown method')
// console.log(typeof callback)
// console.log('helpers- replace markdown method')
// console.log(typeof callback)

var fixedCallbackMethod = false;
let fixedCallbackMethod = false;
switch (typeof callback) {
case 'string':
fixedCallbackMethod = callback;
break;
case 'string':
fixedCallbackMethod = callback;
break;

case 'undefined':
console.log("ERRROROROR HERE!!!!")
case 'undefined':
console.log('ERRROROROR HERE!!!!');

break;
break;

default:
fixedCallbackMethod = callback.bind(this)
break;
default:
fixedCallbackMethod = callback.bind(this);
break;
}

this.content = this.content.replace(regexp, fixedCallbackMethod);
}


// @TODO find out if we really using this method or not?
function replaceMarkdownPreviewText(regexp) {
const config = {
Expand All @@ -40,13 +38,12 @@ function replaceMarkdownPreviewText(regexp) {
this.errors.previewText = true;

this.content = this.content.replace(
regexp,
() => this.previewText
);
regexp,
() => this.previewText,
);
}


module.exports = {
replaceMarkdown,
replaceMarkdownPreviewText
replaceMarkdownPreviewText,
};
70 changes: 31 additions & 39 deletions src/command-line-methods.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
const chalk = require('chalk');
const { forEach } = require('lodash');
const { readSourceFile } = require('./utils');

function checkWarnings(warnings) {

function checkWarnings(warnings) {
forEach(warnings, (index, element) => {
if (index) {
const message = `WARNING source.md has ${index} ${element}. Replace it with memes`;
Expand All @@ -14,12 +14,11 @@ function checkWarnings(warnings) {

function checkErrors(errors) {
if (Object.values(errors).includes(false)) {

// @TODO replace with lodash
forEach(errors, (_, error) => {
if (!errors[error]) {
const message = `ERROR source.md doesn't have ${error}`;

// printMessage();
console.log(chalk.red(message));
}
Expand All @@ -28,7 +27,7 @@ function checkErrors(errors) {
const message = 'The full template has not been parsed!';
// printMessage();
console.log(chalk.red.bold(message));

return true;
}
return false;
Expand All @@ -42,11 +41,10 @@ function displayCLIErrors(errors, warnings) {
}
}



function checkHtml(content) {
const searchPattern = new RegExp('(<table|<tr>|<td|<tbody>)', 'i');
let ind, tempStr = '';
let ind; let
tempStr = '';

if (process.env.noAdv) {
ind = content.indexOf('<h1 class="mc-toc-title"');
Expand All @@ -61,45 +59,41 @@ function checkHtml(content) {

if (searchPattern.test(tempStr)) {
// printMessage();
console.log(chalk.green("Content has correct html!!!"));
console.log(chalk.green('Content has correct html!!!'));
} else {
// printMessage();
console.log(chalk.yellow("Content has not correct html!!!"));
console.log(chalk.yellow('Content has not correct html!!!'));
}
}

const printMessage = ({ message, type }) => {

if (!message) return;

if (type == 'yellow') {
console.log(chalk.yellow(message));
console.log(chalk.yellow(message));
}

if (type == 'red'){
console.log(chalk.red(message));
if (type == 'red') {
console.log(chalk.red(message));
}
if (type == 'red2'){
console.log(chalk.red.bold(message));

if (type == 'red2') {
console.log(chalk.red.bold(message));
}
if (type == 'green1'){
console.log(chalk.green(message));

if (type == 'green1') {
console.log(chalk.green(message));
}
if (type == 'green2'){
console.log(chalk.green.bold(message));
if (type == 'green2') {
console.log(chalk.green.bold(message));
}

}


const stateInit = ( source ) => {
};

let markdown = readSourceFile(source);
const stateInit = (source) => {
const markdown = readSourceFile(source);
// @TODO should we move out state from this file?
let stateObject = {

const stateObject = {
content: markdown,
previewText: '',
warnings: {
Expand All @@ -111,13 +105,13 @@ const stateInit = ( source ) => {
sponsorshipBottom: false,
},

innerCheckErrors: function (){
innerCheckErrors() {
checkErrors(this.errors);
}
},
};

return stateObject;
}
};

const MESSAGE_HTML_CONTENT_ONLY = 'The content has been parsed successfully';
const MESSAGE_HTML_FULL_TEMPLATE = 'The full-template has been parsed successfully';
Expand All @@ -126,21 +120,19 @@ const MESSAGE_HTML_FULL_TEMPLATE2 = 'The full-template has been parsed successfu
const MESSAGE_REACT_FULL_TEMPLATE = 'The FullTemplate has been parsed successfully';
const MESSAGE_REACT_CONTENT = 'The Content has been parsed successfully';


module.exports = {
displayCLIErrors,
checkErrors,
checkWarnings,
checkHtml,

printMessage,
stateInit,


MESSAGE_HTML_CONTENT_ONLY,
MESSAGE_HTML_FULL_TEMPLATE,
MESSAGE_HTML_FULL_TEMPLATE2,

MESSAGE_REACT_FULL_TEMPLATE,
MESSAGE_REACT_CONTENT
MESSAGE_REACT_CONTENT,
};
12 changes: 6 additions & 6 deletions src/converter/body.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@ const {

const ConverterBody = {
header: {
key: "REGEXP_HEADER",
value: header,
key: 'REGEXP_HEADER',
value: header,
// title: "xxx",
},
comments: {
key: "REGEXP_HTML_COMMENTS",
key: 'REGEXP_HTML_COMMENTS',
// value: 1,
// title: "xxx",
},
memes: {
key: "REGEXP_MEM",
value: mem,
key: 'REGEXP_MEM',
value: mem,
// title: "xxx",
},
previewText: {
Expand All @@ -37,7 +37,7 @@ const ConverterBody = {
},
sponsor: {
key: 'REGEXP_SPONSORSHIP',
value: sponsorship,
value: sponsorship,
// title: "xxx",
},
};
Expand Down
1 change: 0 additions & 1 deletion src/converter/full-we-need-to-move-missing-parts.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ const {

// const layouts = require("atherdon-newsletter-constants");


const ConverterTypography = {
heading: {
// key: "REGEXP_H3",
Expand Down
2 changes: 1 addition & 1 deletion src/converter/indeh.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@
// completed_HTML += element;

// });
// }
// }
4 changes: 2 additions & 2 deletions src/converter/typography.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const {
italic,
del,
q,
code
code,
} = require('../callbacks');

// const layouts = require("atherdon-newsletter-constants");
Expand Down Expand Up @@ -89,4 +89,4 @@ const ConverterTypography = {
};

// export data
// export default ConverterTypography
// export default ConverterTypography
28 changes: 28 additions & 0 deletions src/html/parse.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
const { isObject } = require('lodash');
const { parse } = require('../../parse');

const { FULL_SOURCE } = require('../utils');

describe('testing parse.js', () => {
const p = parse(FULL_SOURCE);

test('parse should return an object', () => {
expect(isObject(p)).toBe(true);
});

test('parse should return an object with content key', () => {
expect(p.hasOwnProperty('content')).toBe(true);
});

test('parse should return an object with errors key', () => {
expect(p.hasOwnProperty('errors')).toBe(true);
});

test('parse should return an object with previewText key', () => {
expect(p.hasOwnProperty('previewText')).toBe(true);
});

test('parse should return an object with warnings key', () => {
expect(p.hasOwnProperty('warnings')).toBe(true);
});
});
File renamed without changes.
38 changes: 16 additions & 22 deletions src/html/parseHTML.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,25 @@
const {
stateInit
} = require('../command-line-methods');

const {
Replacer,
replaceMarkdown,
replaceMarkdownPreviewText
} = require("atherdon-callbacks");
Replacer,
replaceMarkdown,
replaceMarkdownPreviewText,
} = require('atherdon-callbacks');

// TODO: something wrong with newsletter-constants module
const {
REGEXP_PREVIEW_TEXT
} = require("atherdon-newsletter-constants");

const {
REGEXP_PREVIEW_TEXT,
} = require('atherdon-newsletter-constants');
const {
stateInit,
} = require('../command-line-methods');

// TODO update this method. I'm sure it can be improved.
function parse(source) {

// passing content into the state,
// so we can do our updates step by step and track any errors
let state = stateInit(source);
// passing content into the state,
// so we can do our updates step by step and track any errors
const state = stateInit(source);

Replacer.replaceMDBinded = replaceMarkdown.bind(state);
Replacer.replaceMDBindedPreviewText =
replaceMarkdownPreviewText.bind(state);
Replacer.replaceMDBindedPreviewText = replaceMarkdownPreviewText.bind(state);

Replacer.previewText();
Replacer.replaceMDBindedPreviewText(REGEXP_PREVIEW_TEXT);
Expand Down Expand Up @@ -52,22 +48,20 @@ function parse(source) {
if (!process.env.PARSE === 'noAdv' || process.env.PARSE === 'full') {
Replacer.sponsorship();
}

Replacer.memes();
Replacer.separator();

//i'm adding it only because error warning didnt return red stuff
// i'm adding it only because error warning didnt return red stuff
// checkErrors(state.errors);
state.innerCheckErrors();


// console.log(state)

return state;
}

function parseFullTHing(params) {

// console.log(params);

const { source } = params;
Expand Down
Loading

0 comments on commit 4398b3f

Please sign in to comment.