Skip to content

Commit cd1c9dc

Browse files
authored
(chore) apply lint to our tooling scripts also (highlightjs#3380)
1 parent 2ccec7e commit cd1c9dc

File tree

13 files changed

+130
-143
lines changed

13 files changed

+130
-143
lines changed

.eslintrc.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ module.exports = {
2828
// for now ignore diff between types of quoting
2929
quotes: "off",
3030
// this is the style we are already using
31-
"operator-linebreak": ["error", "before", { overrides: {
32-
"=": "after"
33-
}
31+
"operator-linebreak": ["error", "before", {
32+
overrides: {
33+
"=": "after"
34+
}
3435
}],
3536
// sometimes we declare variables with extra spacing
3637
indent: ["error", 2, { VariableDeclarator: 2 }],

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"types": "./types/index.d.ts",
3838
"scripts": {
3939
"mocha": "mocha",
40-
"lint": "eslint src/*.js src/lib/*.js demo/*.js",
40+
"lint": "eslint src/*.js src/lib/*.js demo/*.js tools/**/*.js --ignore-pattern vendor",
4141
"lint-languages": "eslint --no-eslintrc -c .eslintrc.lang.js src/languages/**/*.js",
4242
"build_and_test": "npm run build && npm run test",
4343
"build_and_test_browser": "npm run build-browser && npm run test-browser",

tools/build.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262

6363
const commander = require('commander');
6464
const path = require('path');
65-
const { clean } = require("./lib/makestuff");
65+
const { clean } = require("./lib/makestuff.js");
6666
const log = (...args) => console.log(...args);
6767

6868
const TARGETS = ["cdn", "browser", "node"];
@@ -73,8 +73,8 @@ commander
7373
.option('-n, --no-minify', 'Disable minification')
7474
.option('-ne, --no-esm', 'Disable building ESM')
7575
.option('-t, --target <name>',
76-
'Build for target ' +
77-
'[all, browser, cdn, node]',
76+
'Build for target '
77+
+ '[all, browser, cdn, node]',
7878
'browser')
7979
.parse(process.argv);
8080

tools/build_browser.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,27 @@ const path = require("path");
66
const zlib = require('zlib');
77
const Terser = require("terser");
88
const child_process = require('child_process');
9-
const { getLanguages } = require("./lib/language");
10-
const { filter } = require("./lib/dependencies");
11-
const config = require("./build_config");
12-
const { install, installCleanCSS, mkdir, renderTemplate } = require("./lib/makestuff");
9+
const { getLanguages } = require("./lib/language.js");
10+
const { filter } = require("./lib/dependencies.js");
11+
const config = require("./build_config.js");
12+
const { install, installCleanCSS, mkdir, renderTemplate } = require("./lib/makestuff.js");
1313
const log = (...args) => console.log(...args);
1414
const { rollupCode } = require("./lib/bundling.js");
1515
const bundling = require('./lib/bundling.js');
1616
const Table = require('cli-table');
1717

1818
const getDefaultHeader = () => ({
1919
...require('../package.json'),
20-
git_sha : child_process
20+
git_sha: child_process
2121
.execSync("git rev-parse --short=10 HEAD")
22-
.toString().trim(),
22+
.toString().trim()
2323
});
2424
function buildHeader(args = getDefaultHeader()) {
25-
return "/*!\n" +
26-
` Highlight.js v${args.version} (git: ${args.git_sha})\n` +
27-
` (c) ${config.copyrightYears} ${args.author.name} and other contributors\n` +
28-
` License: ${args.license}\n` +
29-
` */`;
25+
return "/*!\n"
26+
+ ` Highlight.js v${args.version} (git: ${args.git_sha})\n`
27+
+ ` (c) ${config.copyrightYears} ${args.author.name} and other contributors\n`
28+
+ ` License: ${args.license}\n`
29+
+ ` */`;
3030
}
3131

3232
function sortByKey(array, key) {
@@ -41,9 +41,9 @@ function detailedGrammarSizes(languages) {
4141
if (languages.length > 180) return;
4242

4343
const resultTable = new Table({
44-
head: ['lang','minified'],
44+
head: ['lang', 'minified'],
4545
// colWidths: [20,20,10,20,10,20],
46-
chars: {'mid': '', 'left-mid': '', 'mid-mid': '', 'right-mid': ''},
46+
chars: { mid: '', 'left-mid': '', 'mid-mid': '', 'right-mid': '' },
4747
style: {
4848
head: ['grey']
4949
}
@@ -230,19 +230,19 @@ async function buildCore(name, languages, options) {
230230
const sizeInfo = { shas: [] };
231231
const writePromises = [];
232232
if (options.minify) {
233-
const { code } = await Terser.minify(index, {...config.terser, module: (options.format === "es") });
233+
const { code } = await Terser.minify(index, { ...config.terser, module: (options.format === "es") });
234234
const src = `${header}\n${code}`;
235235
writePromises.push(fs.writeFile(output.file.replace(/js$/, "min.js"), src));
236236
sizeInfo.minified = src.length;
237237
sizeInfo.minifiedSrc = src;
238-
sizeInfo.shas[`${relativePath}${name}.min.js`] = bundling.sha384(src)
238+
sizeInfo.shas[`${relativePath}${name}.min.js`] = bundling.sha384(src);
239239
}
240240
{
241241
const src = `${header}\n${index}`;
242242
writePromises.push(fs.writeFile(output.file, src));
243243
sizeInfo.fullSize = src.length;
244244
sizeInfo.fullSrc = src;
245-
sizeInfo.shas[`${relativePath}${name}.js`] = bundling.sha384(src)
245+
sizeInfo.shas[`${relativePath}${name}.js`] = bundling.sha384(src);
246246
}
247247
await Promise.all(writePromises);
248248
return sizeInfo;

tools/build_cdn.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async function buildCDN(options) {
5757
if (options.esm) {
5858
mkdir("es");
5959
await fs.writeFile(`${process.env.BUILD_DIR}/es/package.json`, `{ "type": "module" }`);
60-
esmCoreSize = await buildCore("core", [], {minify: options.minify, format: "es"});
60+
esmCoreSize = await buildCore("core", [], { minify: options.minify, format: "es" });
6161
esmCommonSize = await buildCore("highlight", embedLanguages, { minify: options.minify, format: "es" });
6262
}
6363
shas = {
@@ -157,7 +157,7 @@ async function buildDistributable(language, options) {
157157
await fs.mkdir(distDir, { recursive: true });
158158
await fs.writeFile(path.join(language.moduleDir, "dist", filename), language.minified);
159159
if (options.esm) {
160-
await fs.writeFile(path.join(language.moduleDir, "dist", filename.replace(".min.js",".es.min.js")), language.minifiedESM);
160+
await fs.writeFile(path.join(language.moduleDir, "dist", filename.replace(".min.js", ".es.min.js")), language.minifiedESM);
161161
}
162162
}
163163

tools/build_node.js

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
const fs = require("fs").promises;
22
const fss = require("fs");
3-
const config = require("./build_config");
3+
const config = require("./build_config.js");
44
const glob = require("glob-promise");
5-
const { getLanguages } = require("./lib/language");
6-
const { install, mkdir, installCleanCSS } = require("./lib/makestuff");
7-
const { filter } = require("./lib/dependencies");
5+
const { getLanguages } = require("./lib/language.js");
6+
const { install, mkdir, installCleanCSS } = require("./lib/makestuff.js");
7+
const { filter } = require("./lib/dependencies.js");
88
const { rollupWrite } = require("./lib/bundling.js");
99
const log = (...args) => console.log(...args);
1010

1111
// https://nodejs.org/api/packages.html#packages_writing_dual_packages_while_avoiding_or_minimizing_hazards
1212
async function buildESMStub(name) {
1313
const code =
14-
`// https://nodejs.org/api/packages.html#packages_writing_dual_packages_while_avoiding_or_minimizing_hazards\n` +
15-
`import HighlightJS from '../lib/${name}.js';\n` +
16-
`export { HighlightJS };\n` +
17-
`export default HighlightJS;\n`;
14+
`// https://nodejs.org/api/packages.html#packages_writing_dual_packages_while_avoiding_or_minimizing_hazards\n`
15+
+ `import HighlightJS from '../lib/${name}.js';\n`
16+
+ `export { HighlightJS };\n`
17+
+ `export default HighlightJS;\n`;
1818
await fs.writeFile(`${process.env.BUILD_DIR}/es/${name}.js`, code);
1919
}
2020

2121
async function buildCJSIndex(name, languages) {
2222
const header = "var hljs = require('./core');";
2323
const footer =
24-
`hljs.HighlightJS = hljs\n` +
25-
`hljs.default = hljs\n` +
26-
`module.exports = hljs;`;
24+
`hljs.HighlightJS = hljs\n`
25+
+ `hljs.default = hljs\n`
26+
+ `module.exports = hljs;`;
2727

2828
const registration = languages.map((lang) => {
2929
const require = `require('./languages/${lang.name}')`;
@@ -57,7 +57,8 @@ async function buildNodeLanguage(language, options) {
5757
if (options.esm) {
5858
await fs.writeFile(`${process.env.BUILD_DIR}/es/languages/${language.name}.js.js`,
5959
ES_STUB.replace(/%%%%/g, language.name));
60-
await rollupWrite(input, {...output,
60+
await rollupWrite(input, {
61+
...output,
6162
format: "es",
6263
file: output.file.replace("/lib/", "/es/")
6364
});
@@ -108,7 +109,7 @@ const generatePackageExports = () => ({
108109
"./lib/languages/*": dual("./lib/languages/*.js"),
109110
"./scss/*": "./scss/*",
110111
"./styles/*": "./styles/*",
111-
"./types/*": "./types/*",
112+
"./types/*": "./types/*"
112113
});
113114
function buildPackageJSON(options) {
114115
const packageJson = require("../package.json");

tools/checkAutoDetect.js

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/usr/bin/env node
22
'use strict';
33

4-
let fs = require('fs')
5-
let hljs = require('../build');
6-
let path = require('path');
7-
let utility = require('../test/utility');
8-
let Table = require('cli-table');
9-
let colors = require('colors/safe');
4+
const fs = require('fs');
5+
const hljs = require('../build.js');
6+
const path = require('path');
7+
const utility = require('../test/utility.js');
8+
const Table = require('cli-table');
9+
const colors = require('colors/safe.js');
1010

11-
let resultTable = new Table({
12-
head: ['expected', 'actual', 'score', '2nd best', 'score','info'],
13-
colWidths: [20,20,10,20,10,20],
11+
const resultTable = new Table({
12+
head: ['expected', 'actual', 'score', '2nd best', 'score', 'info'],
13+
colWidths: [20, 20, 10, 20, 10, 20],
1414
style: {
1515
head: ['grey']
1616
}
@@ -24,8 +24,8 @@ function testAutoDetection(language, index, languages) {
2424
return fs.readFileSync(filename, 'utf-8');
2525
})
2626
.forEach(function(content) {
27-
const expected = language,
28-
actual = hljs.highlightAuto(content);
27+
const expected = language;
28+
const actual = hljs.highlightAuto(content);
2929
if (actual.language !== expected && actual.secondBest.language !== expected) {
3030
return resultTable.push([
3131
expected,
@@ -45,7 +45,7 @@ function testAutoDetection(language, index, languages) {
4545
]);
4646
}
4747
// equal relevance is flagged
48-
if (actual.relevance == actual.secondBest.relevance) {
48+
if (actual.relevance === actual.secondBest.relevance) {
4949
return resultTable.push([
5050
expected,
5151
actual.language,
@@ -68,18 +68,16 @@ if (process.env.ONLY_LANGUAGES) {
6868
console.log('Checking auto-highlighting for ' + colors.grey(languages.length) + ' languages...');
6969
languages.forEach((lang, index) => {
7070
if (index % 60 === 0) { console.log(""); }
71-
testAutoDetection(lang)
71+
testAutoDetection(lang);
7272
process.stdout.write(".");
7373
});
74-
console.log("\n")
74+
console.log("\n");
7575

7676
if (resultTable.length === 0) {
77-
console.log(colors.green('SUCCESS') + ' - ' + colors.green(languages.length) + ' of ' + colors.gray(languages.length) + ' languages passed auto-highlight check!')
77+
console.log(colors.green('SUCCESS') + ' - ' + colors.green(languages.length) + ' of ' + colors.gray(languages.length) + ' languages passed auto-highlight check!');
7878
} else {
7979
console.log(
80-
colors.red('ISSUES') + ' - ' + colors.red(resultTable.length) + ' of ' + colors.gray(languages.length) + ' languages have potential issues.' +
81-
'\n' +
82-
resultTable.toString());
80+
colors.red('ISSUES') + ' - ' + colors.red(resultTable.length) + ' of ' + colors.gray(languages.length) + ' languages have potential issues.'
81+
+ '\n'
82+
+ resultTable.toString());
8383
}
84-
85-

tools/checkTheme.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const fs = require("fs");
44
const css = require("css");
5-
const { match } = require("assert");
65
require("colors");
76

87
const CODE = {
@@ -166,19 +165,19 @@ function check_group(group, rules) {
166165
});
167166

168167

169-
let doesNotSupport = has_rules.map(x => x[1]).includes(false);
170-
let skipped = has_rules.find(x => x[2]);
168+
const doesNotSupport = has_rules.map(x => x[1]).includes(false);
169+
const skipped = has_rules.find(x => x[2]);
171170
if (doesNotSupport || skipped) {
172171
console.log(group.name.yellow);
173172
if (doesNotSupport) {
174173
console.log(`- Theme does not fully support.`.brightMagenta);
175174
}
176175

177-
has_rules.filter(x => !x[1]).forEach(([scope,_]) => {
176+
has_rules.filter(x => !x[1]).forEach(([scope, _]) => {
178177
const selector = scopeToSelector(scope);
179178
console.log(`- scope ${scope.cyan} is not highlighted\n (css: ${selector.green})`);
180179
});
181-
has_rules.filter(x => x[2]).forEach(([scope,_]) => {
180+
has_rules.filter(x => x[2]).forEach(([scope, _]) => {
182181
console.log(` - scope ${scope.cyan} [purposely] un-highlighted.`.cyan);
183182
});
184183
console.log();

tools/lib/bundling.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
const rollup = require('rollup')
1+
const rollup = require('rollup');
22
const crypto = require("crypto");
33

44
async function rollupCode(inputOptions, outputOptions) {
5-
const output = await generate(inputOptions, outputOptions)
5+
const output = await generate(inputOptions, outputOptions);
66
return output[0].code;
77
}
88

0 commit comments

Comments
 (0)