Skip to content

Commit

Permalink
chore: use @markedjs/eslint-config (#381)
Browse files Browse the repository at this point in the history
  • Loading branch information
UziTech authored Aug 6, 2024
1 parent 1caf6d1 commit cf504f4
Show file tree
Hide file tree
Showing 18 changed files with 2,013 additions and 3,633 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

25 changes: 0 additions & 25 deletions .eslintrc.json

This file was deleted.

16 changes: 16 additions & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import markedEslintConfig from '@markedjs/eslint-config';
import globals from 'globals';

export default [
{
ignores: ['**/coverage'],
},
...markedEslintConfig,
{
languageOptions: {
globals: {
...globals.mocha,
},
},
},
];
8 changes: 5 additions & 3 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import coa from 'coa';
import { HtmlDiffer } from './index.js';
import * as diffLogger from './logger.js';
import { defaults, presets } from './defaults.js';
import { createRequire } from 'module';
const require = createRequire(import.meta.url);

const boldGreen = chalk.green.bold;
const boldRed = chalk.red.bold;
Expand Down Expand Up @@ -50,7 +52,7 @@ export function run(argv) {
.title('Name of a preset')
.short('p').long('preset')
.val(function(val) {
if (!presets.hasOwnProperty(val)) {
if (!Object.hasOwnProperty.call(presets, val)) {
console.log(boldRed(val) + ' is an invalid preset name. Available presets are: '
+ Object.keys(presets).map(function(preset) {
return boldGreen(preset);
Expand Down Expand Up @@ -83,7 +85,7 @@ export function run(argv) {
const [html1, html2, configFile] = await Promise.all([
readAsync(path.resolve(args.path1), 'utf8'),
readAsync(path.resolve(args.path2), 'utf8'),
opts.config ? readAsync(path.resolve(opts.config), 'utf8') : undefined
opts.config ? readAsync(path.resolve(opts.config), 'utf8') : undefined,
]);

const config = configFile ? JSON.parse(configFile) : {};
Expand All @@ -98,7 +100,7 @@ export function run(argv) {
const diff = await htmlDiffer.diffHtml(html1, html2);

const loggerOptions = {
charsAroundDiff: opts.charsAroundDiff
charsAroundDiff: opts.charsAroundDiff,
};
if (!diffLogger.logDiffText(diff, loggerOptions)) {
process.exit(1);
Expand Down
8 changes: 4 additions & 4 deletions lib/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { createRequire } from 'module';
const require = createRequire(import.meta.url);

export const presets = {
bem: require('../presets/bem.json')
bem: require('../presets/bem.json'),
};

/**
Expand All @@ -28,7 +28,7 @@ export function defaults(options = {}) {

if (options.preset) {
const preset = String(options.preset);
if (!presets.hasOwnProperty(preset)) {
if (!Object.hasOwnProperty.call(presets, preset)) {
throw Error(preset + ' is an invalid preset name.');
}

Expand All @@ -46,6 +46,6 @@ export function defaults(options = {}) {
ignoreEndTags: false,
ignoreSelfClosingSlash: false,

...options
...options,
};
};
}
4 changes: 2 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export class HtmlDiffer {
// the sax parser is async
const tokens = {
html1: await getModifiedTokens(html1, this.options),
html2: await getModifiedTokens(html2, this.options)
html2: await getModifiedTokens(html2, this.options),
};

const htmlDiffer = new HtmlDiff(this.options, tokens);
Expand All @@ -47,7 +47,7 @@ export class HtmlDiffer {
const diff = htmlDiffer.diff('html1', 'html2');

return handleMasks(diff);
};
}

/**
* Compares two given chunks of HTML
Expand Down
6 changes: 4 additions & 2 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const grey = chalk.grey;
*/
export function getDiffText(diff, options) {
options = options || {
charsAroundDiff: 40
charsAroundDiff: 40,
};

let charsAroundDiff = options.charsAroundDiff,
Expand Down Expand Up @@ -48,7 +48,9 @@ export function getDiffText(diff, options) {
if (partValue.length < charsAroundDiff * 2) {
output += (index !== 0 ? '' : '\n') + grey(partValue);
} else {
index !== 0 && (output += grey(partValue.substr(0, charsAroundDiff)));
if (index !== 0) {
output += grey(partValue.substr(0, charsAroundDiff));
}

if (index < diff.length - 1) {
output += '\n...\n' + grey(partValue.substr(partValue.length - charsAroundDiff));
Expand Down
2 changes: 1 addition & 1 deletion lib/utils/mask.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ export default function(diff) {
diff = _revealMasks(diff);

return _concatNotDiffParts(diff);
};
}
4 changes: 3 additions & 1 deletion lib/utils/modify.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ export default function modify(value, options) {
parser.on('text', function(textToken) {
let text = textToken.text;

options.ignoreWhitespaces && (text = utils.removeWhitespaces(text));
if (options.ignoreWhitespaces) {
text = utils.removeWhitespaces(text);
}

modifiedValues.push(serialize.text(text));
});
Expand Down
4 changes: 3 additions & 1 deletion lib/utils/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ export function startTag(tagName, attrs, selfClosing) {
res += ' ' + attr.name + '="' + utils.htmlEntities(attr.value) + '"';
});

selfClosing && (res += '/');
if (selfClosing) {
res += '/';
}

return res + '>';
}
Expand Down
4 changes: 2 additions & 2 deletions lib/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export function sortAttrsValues(attrs, compareAttributesAsJSON) {
}

return JSON.parse(val);
} catch (err) {
} catch {
return undefined;
}
}
Expand Down Expand Up @@ -198,7 +198,7 @@ export function htmlEntities(str) {
"'": '&#39;',
'"': '&quot;',
'<': '&lt;',
'>': '&gt;'
'>': '&gt;',
};
return str.replace(/[&"'<>]/g, function(c) {
return map[c];
Expand Down
Loading

0 comments on commit cf504f4

Please sign in to comment.