From 16dfa25af93aba5425eefc13850493c56f599e12 Mon Sep 17 00:00:00 2001 From: Daniel Nalborczyk Date: Tue, 28 Dec 2021 11:55:54 -0500 Subject: [PATCH] Consolidate eslint setup --- .eslintignore | 2 ++ .eslintrc.js | 52 ++++++++++++++++++++++++++++++++ acorn-loose/package.json | 4 ++- acorn-loose/rollup.config.js | 1 - acorn-loose/src/.eslintrc | 34 --------------------- acorn-walk/package.json | 4 ++- acorn-walk/src/.eslintrc | 34 --------------------- acorn/package.json | 8 +++-- acorn/src/.eslintrc | 36 ---------------------- acorn/src/bin/.eslintrc | 6 ---- bin/generate-identifier-regex.js | 16 +++++----- bin/run_test262.js | 10 +++--- package.json | 12 ++++---- test/lint.js | 13 -------- 14 files changed, 84 insertions(+), 148 deletions(-) create mode 100644 .eslintignore create mode 100644 .eslintrc.js delete mode 100644 acorn-loose/src/.eslintrc delete mode 100644 acorn-walk/src/.eslintrc delete mode 100644 acorn/src/.eslintrc delete mode 100644 acorn/src/bin/.eslintrc delete mode 100644 test/lint.js diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 000000000..be3f0c7e2 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,2 @@ +dist +test \ No newline at end of file diff --git a/.eslintrc.js b/.eslintrc.js new file mode 100644 index 000000000..aadf0e5e9 --- /dev/null +++ b/.eslintrc.js @@ -0,0 +1,52 @@ +"use strict" + +module.exports = { + extends: [ + "eslint:recommended", + "standard", + "plugin:import/errors", + "plugin:import/warnings" + ], + globals: { + BigInt: false, + Packages: false + }, + overrides: [ + { + files: ["acorn/src/bin/*.js", "bin/generate-identifier-regex.js"], + rules: { + "no-console": "off" + } + } + ], + plugins: ["eslint-plugin-import"], + rules: { + curly: "off", + eqeqeq: ["error", "always", {null: "ignore"}], + indent: [ + "error", + 2, + { + SwitchCase: 0, + VariableDeclarator: 2, + CallExpression: {arguments: "off"} + } + ], + "new-parens": "off", + "no-case-declarations": "off", + "no-cond-assign": "off", + "no-console": ["error", {allow: ["warn", "error"]}], + "no-fallthrough": "off", + "no-labels": "off", + "no-mixed-operators": "off", + "no-return-assign": "off", + "no-unused-labels": "error", + "no-var": "error", + "object-curly-spacing": ["error", "never"], + "one-var": "off", + "prefer-const": "off", + quotes: ["error", "double"], + "semi-spacing": "off", + "space-before-function-paren": ["error", "never"] + } +} diff --git a/acorn-loose/package.json b/acorn-loose/package.json index 1bd1961a3..121f81bff 100644 --- a/acorn-loose/package.json +++ b/acorn-loose/package.json @@ -16,7 +16,9 @@ "./package.json": "./package.json" }, "version": "8.3.0", - "engines": {"node": ">=0.4.0"}, + "engines": { + "node": ">=0.4.0" + }, "dependencies": { "acorn": "^8.5.0" }, diff --git a/acorn-loose/rollup.config.js b/acorn-loose/rollup.config.js index 969f24478..83eb7afaf 100644 --- a/acorn-loose/rollup.config.js +++ b/acorn-loose/rollup.config.js @@ -8,7 +8,6 @@ export default { file: "acorn-loose/dist/acorn-loose.js", format: "umd", name: "acorn.loose", - globals: {acorn: "acorn"} }, { diff --git a/acorn-loose/src/.eslintrc b/acorn-loose/src/.eslintrc deleted file mode 100644 index 9ca5ee222..000000000 --- a/acorn-loose/src/.eslintrc +++ /dev/null @@ -1,34 +0,0 @@ -{ - "extends": [ - "eslint:recommended", - "standard", - "plugin:import/errors", - "plugin:import/warnings" - ], - "rules": { - "curly": "off", - "eqeqeq": ["error", "always", { "null": "ignore" }], - "indent": ["error", 2, { "SwitchCase": 0, "VariableDeclarator": 2, "CallExpression": { "arguments": "off" } }], - "new-parens": "off", - "no-case-declarations": "off", - "no-cond-assign": "off", - "no-fallthrough": "off", - "no-labels": "off", - "no-mixed-operators": "off", - "no-return-assign": "off", - "no-unused-labels": "error", - "no-var": "error", - "object-curly-spacing": ["error", "never"], - "one-var": "off", - "prefer-const": "off", - "quotes": ["error", "double"], - "semi-spacing": "off", - "space-before-function-paren": ["error", "never"] - }, - "globals": { - "Packages": false - }, - "plugins": [ - "import" - ] -} diff --git a/acorn-walk/package.json b/acorn-walk/package.json index 8d75b9711..1a718380a 100644 --- a/acorn-walk/package.json +++ b/acorn-walk/package.json @@ -17,7 +17,9 @@ "./package.json": "./package.json" }, "version": "8.2.0", - "engines": {"node": ">=0.4.0"}, + "engines": { + "node": ">=0.4.0" + }, "maintainers": [ { "name": "Marijn Haverbeke", diff --git a/acorn-walk/src/.eslintrc b/acorn-walk/src/.eslintrc deleted file mode 100644 index 9ca5ee222..000000000 --- a/acorn-walk/src/.eslintrc +++ /dev/null @@ -1,34 +0,0 @@ -{ - "extends": [ - "eslint:recommended", - "standard", - "plugin:import/errors", - "plugin:import/warnings" - ], - "rules": { - "curly": "off", - "eqeqeq": ["error", "always", { "null": "ignore" }], - "indent": ["error", 2, { "SwitchCase": 0, "VariableDeclarator": 2, "CallExpression": { "arguments": "off" } }], - "new-parens": "off", - "no-case-declarations": "off", - "no-cond-assign": "off", - "no-fallthrough": "off", - "no-labels": "off", - "no-mixed-operators": "off", - "no-return-assign": "off", - "no-unused-labels": "error", - "no-var": "error", - "object-curly-spacing": ["error", "never"], - "one-var": "off", - "prefer-const": "off", - "quotes": ["error", "double"], - "semi-spacing": "off", - "space-before-function-paren": ["error", "never"] - }, - "globals": { - "Packages": false - }, - "plugins": [ - "import" - ] -} diff --git a/acorn/package.json b/acorn/package.json index 8e2edc65c..d7948c8b4 100644 --- a/acorn/package.json +++ b/acorn/package.json @@ -17,7 +17,9 @@ "./package.json": "./package.json" }, "version": "8.7.0", - "engines": {"node": ">=0.4.0"}, + "engines": { + "node": ">=0.4.0" + }, "maintainers": [ { "name": "Marijn Haverbeke", @@ -42,5 +44,7 @@ "scripts": { "prepare": "cd ..; npm run build:main" }, - "bin": {"acorn": "./bin/acorn"} + "bin": { + "acorn": "./bin/acorn" + } } diff --git a/acorn/src/.eslintrc b/acorn/src/.eslintrc deleted file mode 100644 index 4752192b6..000000000 --- a/acorn/src/.eslintrc +++ /dev/null @@ -1,36 +0,0 @@ -{ - "extends": [ - "eslint:recommended", - "standard", - "plugin:import/errors", - "plugin:import/warnings" - ], - "rules": { - "curly": "off", - "eqeqeq": ["error", "always", { "null": "ignore" }], - "indent": ["error", 2, { "SwitchCase": 0, "VariableDeclarator": 2, "CallExpression": { "arguments": "off" } }], - "new-parens": "off", - "no-case-declarations": "off", - "no-cond-assign": "off", - "no-console": ["error", { allow: ["warn", "error"] }], - "no-fallthrough": "off", - "no-labels": "off", - "no-mixed-operators": "off", - "no-return-assign": "off", - "no-unused-labels": "error", - "no-var": "error", - "object-curly-spacing": ["error", "never"], - "one-var": "off", - "prefer-const": "off", - "quotes": ["error", "double"], - "semi-spacing": "off", - "space-before-function-paren": ["error", "never"] - }, - "globals": { - "Packages": false, - "BigInt": false - }, - "plugins": [ - "import" - ] -} diff --git a/acorn/src/bin/.eslintrc b/acorn/src/bin/.eslintrc deleted file mode 100644 index 2598b25f5..000000000 --- a/acorn/src/bin/.eslintrc +++ /dev/null @@ -1,6 +0,0 @@ -{ - "extends": "../.eslintrc", - "rules": { - "no-console": "off" - } -} \ No newline at end of file diff --git a/bin/generate-identifier-regex.js b/bin/generate-identifier-regex.js index afb26c2ba..a0bfbfdf8 100644 --- a/bin/generate-identifier-regex.js +++ b/bin/generate-identifier-regex.js @@ -1,14 +1,14 @@ -'use strict'; +"use strict" // Which Unicode version should be used? -let pkg = require('../package.json') +let pkg = require("../package.json") let dependencies = Object.keys(pkg.devDependencies) let unicodeVersion = dependencies.find((name) => /^@unicode\/unicode-\d/.test(name)) -let start = require(unicodeVersion + '/Binary_Property/ID_Start/code-points.js').filter(ch => ch > 0x7f) +let start = require(unicodeVersion + "/Binary_Property/ID_Start/code-points.js").filter(ch => ch > 0x7f) let last = -1 -let cont = [0x200c, 0x200d].concat(require(unicodeVersion + '/Binary_Property/ID_Continue/code-points.js') - .filter(ch => ch > 0x7f && search(start, ch, last + 1) === -1)) +let cont = [0x200c, 0x200d].concat(require(unicodeVersion + "/Binary_Property/ID_Continue/code-points.js") + .filter(ch => ch > 0x7f && search(start, ch, last + 1) === -1)) function search(arr, ch, starting) { for (let i = starting; arr[i] <= ch && i < arr.length; last = i++) @@ -25,7 +25,7 @@ function generate(chars) { let astral = [], re = "" for (let i = 0, at = 0x10000; i < chars.length; i++) { let from = chars[i], to = from - while (i < chars.length - 1 && chars[i + 1] === to + 1) {i++; to++} + while (i < chars.length - 1 && chars[i + 1] === to + 1) { i++; to++ } if (to <= 0xffff) { if (from === to) re += esc(from) else if (from + 1 === to) re += esc(from) + esc(to) @@ -47,10 +47,10 @@ let code = [ ` const astralIdentifierCodes = ${JSON.stringify(contData.astral)}` ] -if (process.argv.length != 3) { +if (process.argv.length !== 3) { console.log(code.join("\n")) } else { - let {readFile} = require('fs') + let {readFile} = require("fs") readFile(process.argv[2], "utf8", function(err, data) { if (err) throw err for (let line of code) diff --git a/bin/run_test262.js b/bin/run_test262.js index cfa0380aa..0241ca259 100644 --- a/bin/run_test262.js +++ b/bin/run_test262.js @@ -5,8 +5,8 @@ const parse = require("../acorn").parse function loadList(filename) { return fs.readFileSync(filename, "utf8") - .split("\n") - .filter(Boolean) + .split("\n") + .filter(Boolean) } run( @@ -14,10 +14,8 @@ run( { testsDirectory: path.dirname(require.resolve("test262/package.json")), skip: test => test.attrs.features && - loadList("./bin/test262.unsupported-features").some(f => test.attrs.features.includes(f) - ), + loadList("./bin/test262.unsupported-features").some(f => test.attrs.features.includes(f)), whitelist: loadList("./bin/test262.whitelist") - .map(filename => path.sep === "/" ? filename : filename.split("/").join(path.sep) - ) + .map(filename => path.sep === "/" ? filename : filename.split("/").join(path.sep)) } ) diff --git a/package.json b/package.json index 09a185787..4488e40d9 100644 --- a/package.json +++ b/package.json @@ -21,15 +21,15 @@ }, "license": "MIT", "scripts": { - "prepare": "npm run test", - "test": "node test/run.js && node test/lint.js", - "pretest": "npm run build:main && npm run build:loose", - "test:test262": "node bin/run_test262.js", "build": "npm run build:main && npm run build:walk && npm run build:loose", + "build:loose": "rollup -c acorn-loose/rollup.config.js", "build:main": "rollup -c acorn/rollup.config.js", "build:walk": "rollup -c acorn-walk/rollup.config.js", - "build:loose": "rollup -c acorn-loose/rollup.config.js", - "lint": "eslint acorn/src/ acorn-walk/src/ acorn-loose/src/" + "lint": "eslint .", + "prepare": "npm run test", + "pretest": "npm run build:main && npm run build:loose", + "test": "node test/run.js && npm run lint", + "test:test262": "node bin/run_test262.js" }, "devDependencies": { "@rollup/plugin-buble": "^0.21.3", diff --git a/test/lint.js b/test/lint.js deleted file mode 100644 index 27935069c..000000000 --- a/test/lint.js +++ /dev/null @@ -1,13 +0,0 @@ -if (parseInt(process.versions.node) > 4) { - console.log("Linting...") - var join = require("path").join - try { - require("child_process").execSync( - join("node_modules", ".bin", "eslint") + " " + join(__dirname, "..", "*", "src"), - {encoding: "utf8", stdio: "inherit"} - ) - console.log("OK") - } catch (_) { - process.exit(1) - } -}