From 771072b0a494906a2b8b3dc81358ebb5ea85ce72 Mon Sep 17 00:00:00 2001 From: shao Date: Wed, 21 Aug 2019 21:54:38 +0800 Subject: [PATCH 1/4] optimize eslint script --- .eslintignore | 6 ++++++ .eslintrc.js | 21 ++++++++++++++------- _SETUP.md | 2 +- azure-pipelines.yml | 2 +- package.json | 6 +++--- 5 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 .eslintignore diff --git a/.eslintignore b/.eslintignore new file mode 100644 index 00000000000..0d996a52564 --- /dev/null +++ b/.eslintignore @@ -0,0 +1,6 @@ +node_modules +test/** +*.d.ts +examples/**/*.js +!examples/*/webpack.config.js +!.*.js diff --git a/.eslintrc.js b/.eslintrc.js index 8f7b5b0426e..4533d48fe19 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,7 +11,10 @@ module.exports = { es6: true }, parserOptions: { - ecmaVersion: 2017 + ecmaVersion: 2017, + ecmaFeatures: { + experimentalObjectRestSpread: true + } }, rules: { "prettier/prettier": "error", @@ -55,12 +58,16 @@ module.exports = { jsdoc: { // supported tags https://github.com/microsoft/TypeScript-wiki/blob/master/JSDoc-support-in-JavaScript.md tagNamePreference: { - ...(['implements', 'const', 'memberof', 'readonly', 'yields'].reduce((acc, tag) => { - acc[tag] = { - message: `@${tag} currently not supported in Typescript` - }; - return acc; - }, {})), + // eslint-disable-next-line node/no-unsupported-features,node/no-unsupported-features/es-syntax + ...["implements", "const", "memberof", "readonly", "yields"].reduce( + (acc, tag) => { + acc[tag] = { + message: `@${tag} currently not supported in Typescript` + }; + return acc; + }, + {} + ), extends: "extends", return: "returns", constructor: "constructor", diff --git a/_SETUP.md b/_SETUP.md index 654dbef0843..99b88760aa1 100644 --- a/_SETUP.md +++ b/_SETUP.md @@ -67,7 +67,7 @@ yarn pretty This performs linting on: -* eslint (code-lint script) +* eslint (eslint script) * schema + dependencies (jest-lint script) * types (type-lint script) * format + generated files (special-lint script) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 9a573c30e37..a80a2f58af9 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -71,7 +71,7 @@ jobs: - script: | set -e export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH" - yarn -s run code-lint --format junit > junit.xml + yarn -s run eslint --format junit > junit.xml yarn jest-lint yarn type-lint yarn special-lint diff --git a/package.json b/package.json index 4e2df4086a9..b7c9376b097 100644 --- a/package.json +++ b/package.json @@ -119,12 +119,12 @@ "build:examples": "cd examples && node buildAll.js", "pretest": "yarn lint", "prelint": "yarn setup", - "lint": "yarn code-lint && yarn jest-lint && yarn type-lint && yarn special-lint", - "code-lint": "eslint --cache \"{setup,lib,bin,hot,buildin,benchmark,tooling,schemas}/**/*.js\" \"test/*.js\" \"test/{configCases,watchCases,statsCases,hotCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\"", + "lint": "yarn eslint && yarn jest-lint && yarn type-lint && yarn special-lint", + "eslint": "eslint . --ext '.js'", "type-lint": "tsc --pretty", "special-lint": "node tooling/inherit-types && node tooling/format-schemas && node tooling/compile-to-definitions", "special-lint-fix": "node tooling/inherit-types --write --override && node tooling/format-schemas --write && node tooling/compile-to-definitions --write", - "fix": "yarn code-lint --fix && yarn special-lint-fix", + "fix": "yarn eslint --fix && yarn special-lint-fix", "pretty": "prettier --loglevel warn --write \"*.{ts,js,json,yml,yaml}\" \"{setup,lib,bin,hot,buildin,benchmark,tooling,schemas}/**/*.{js,json}\" \"test/*.js\" \"test/{configCases,watchCases,statsCases,hotCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\"", "jest-lint": "node --max-old-space-size=4096 node_modules/jest-cli/bin/jest --testMatch \"/test/*.lint.js\" --no-verbose", "benchmark": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.benchmark.js\" --runInBand", From 7ee8ca3cbf6c1a6084a7b2274eee286b539aa9e9 Mon Sep 17 00:00:00 2001 From: shao Date: Thu, 22 Aug 2019 18:16:39 +0800 Subject: [PATCH 2/4] optimize code-lint config --- .eslintignore | 15 +++++++++++++-- .eslintrc.js | 6 +----- _SETUP.md | 2 +- azure-pipelines.yml | 2 +- package.json | 6 +++--- 5 files changed, 19 insertions(+), 12 deletions(-) diff --git a/.eslintignore b/.eslintignore index 0d996a52564..dabb31606a7 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,6 +1,17 @@ +# Ignore node_modules node_modules -test/** + +# Ignore not support files +!.*.js +.eslintrc.js *.d.ts + +# Ignore some test files +test/**/*.js +!test/*.js +!test/*Cases/**/webpack.config.js + +# Ignore some examples files examples/**/*.js !examples/*/webpack.config.js -!.*.js + diff --git a/.eslintrc.js b/.eslintrc.js index 4533d48fe19..69f411216f8 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -11,10 +11,7 @@ module.exports = { es6: true }, parserOptions: { - ecmaVersion: 2017, - ecmaFeatures: { - experimentalObjectRestSpread: true - } + ecmaVersion: 2017 }, rules: { "prettier/prettier": "error", @@ -58,7 +55,6 @@ module.exports = { jsdoc: { // supported tags https://github.com/microsoft/TypeScript-wiki/blob/master/JSDoc-support-in-JavaScript.md tagNamePreference: { - // eslint-disable-next-line node/no-unsupported-features,node/no-unsupported-features/es-syntax ...["implements", "const", "memberof", "readonly", "yields"].reduce( (acc, tag) => { acc[tag] = { diff --git a/_SETUP.md b/_SETUP.md index 99b88760aa1..654dbef0843 100644 --- a/_SETUP.md +++ b/_SETUP.md @@ -67,7 +67,7 @@ yarn pretty This performs linting on: -* eslint (eslint script) +* eslint (code-lint script) * schema + dependencies (jest-lint script) * types (type-lint script) * format + generated files (special-lint script) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index a80a2f58af9..9a573c30e37 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -71,7 +71,7 @@ jobs: - script: | set -e export PATH="$HOME/.yarn/bin:$HOME/.config/yarn/global/node_modules/.bin:$PATH" - yarn -s run eslint --format junit > junit.xml + yarn -s run code-lint --format junit > junit.xml yarn jest-lint yarn type-lint yarn special-lint diff --git a/package.json b/package.json index b7c9376b097..72cdee413e0 100644 --- a/package.json +++ b/package.json @@ -119,12 +119,12 @@ "build:examples": "cd examples && node buildAll.js", "pretest": "yarn lint", "prelint": "yarn setup", - "lint": "yarn eslint && yarn jest-lint && yarn type-lint && yarn special-lint", - "eslint": "eslint . --ext '.js'", + "lint": "yarn code-lint && yarn jest-lint && yarn type-lint && yarn special-lint", + "code-lint": "eslint . --ext '.js' --cache", "type-lint": "tsc --pretty", "special-lint": "node tooling/inherit-types && node tooling/format-schemas && node tooling/compile-to-definitions", "special-lint-fix": "node tooling/inherit-types --write --override && node tooling/format-schemas --write && node tooling/compile-to-definitions --write", - "fix": "yarn eslint --fix && yarn special-lint-fix", + "fix": "yarn code-lint --fix && yarn special-lint-fix", "pretty": "prettier --loglevel warn --write \"*.{ts,js,json,yml,yaml}\" \"{setup,lib,bin,hot,buildin,benchmark,tooling,schemas}/**/*.{js,json}\" \"test/*.js\" \"test/{configCases,watchCases,statsCases,hotCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\"", "jest-lint": "node --max-old-space-size=4096 node_modules/jest-cli/bin/jest --testMatch \"/test/*.lint.js\" --no-verbose", "benchmark": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.benchmark.js\" --runInBand", From 94d17681c42da7a668828ccc43f1c10748606bc6 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 22 Aug 2019 13:26:45 +0200 Subject: [PATCH 3/4] resolve linting issues in test/helpers --- test/helpers/PluginEnvironment.js | 41 ++++++++++--------- test/helpers/TemplatePluginEnvironment.js | 2 +- test/helpers/applyPluginWithOptions.js | 6 +-- test/helpers/createLazyTestEnv.js | 2 +- test/helpers/remove.js | 5 ++- test/helpers/supportDefaultAssignment.js | 9 ++-- .../supportsArrowFunctionExpression.js | 6 ++- test/helpers/supportsBlockScoping.js | 6 ++- test/helpers/supportsDefaultArgs.js | 2 +- test/helpers/supportsES6.js | 2 +- test/helpers/supportsForOf.js | 4 +- test/helpers/supportsIteratorDestructuring.js | 2 +- test/helpers/supportsObjectDestructuring.js | 2 +- test/helpers/supportsOptionalCatchBinding.js | 2 +- test/helpers/supportsSpread.js | 5 ++- test/helpers/supportsTemplateStrings.js | 2 +- test/helpers/supportsWebAssembly.js | 2 +- 17 files changed, 56 insertions(+), 44 deletions(-) diff --git a/test/helpers/PluginEnvironment.js b/test/helpers/PluginEnvironment.js index 1b7ad46d728..456517780a9 100644 --- a/test/helpers/PluginEnvironment.js +++ b/test/helpers/PluginEnvironment.js @@ -22,27 +22,30 @@ module.exports = function PluginEnvironment() { // In the meanwhile, `hooks` is a `Proxy` which creates fake hooks // on demand. Instead of creating a dummy object with a few `Hook` // method, a custom `Hook` class could be used. - hooks: new Proxy({}, { - get(target, hookName) { - let hook = hooks.get(hookName); - if (hook === undefined) { - const eventName = getEventName(hookName); - hook = { - tap(_, handler) { - addEvent(eventName, handler); - }, - tapAsync(_, handler) { - addEvent(eventName, handler); - }, - tapPromise(_, handler) { - addEvent(eventName, handler); - } - }; - hooks.set(hookName, hook); + hooks: new Proxy( + {}, + { + get(target, hookName) { + let hook = hooks.get(hookName); + if (hook === undefined) { + const eventName = getEventName(hookName); + hook = { + tap(_, handler) { + addEvent(eventName, handler); + }, + tapAsync(_, handler) { + addEvent(eventName, handler); + }, + tapPromise(_, handler) { + addEvent(eventName, handler); + } + }; + hooks.set(hookName, hook); + } + return hook; } - return hook; } - }) + ) }; }; diff --git a/test/helpers/TemplatePluginEnvironment.js b/test/helpers/TemplatePluginEnvironment.js index b852c0c2151..2e9c34cc382 100644 --- a/test/helpers/TemplatePluginEnvironment.js +++ b/test/helpers/TemplatePluginEnvironment.js @@ -1,4 +1,4 @@ -var PluginEnvironment = require('./PluginEnvironment'); +var PluginEnvironment = require("./PluginEnvironment"); module.exports = function TemplatePluginEnvironment() { var events = []; diff --git a/test/helpers/applyPluginWithOptions.js b/test/helpers/applyPluginWithOptions.js index 47a82cb1567..844d580af28 100644 --- a/test/helpers/applyPluginWithOptions.js +++ b/test/helpers/applyPluginWithOptions.js @@ -1,11 +1,11 @@ -var PluginEnvironment = require('./PluginEnvironment'); +var PluginEnvironment = require("./PluginEnvironment"); module.exports = function applyPluginWithOptions(Plugin) { - var plugin = new (Function.prototype.bind.apply(Plugin, arguments)); + var plugin = new (Function.prototype.bind.apply(Plugin, arguments))(); var pluginEnvironment = new PluginEnvironment(); plugin.apply(pluginEnvironment.getEnvironmentStub()); - var env = (this === global) ? {} : this; + var env = this === global ? {} : this; env.plugin = plugin; env.pluginEnvironment = pluginEnvironment; diff --git a/test/helpers/createLazyTestEnv.js b/test/helpers/createLazyTestEnv.js index 813e232bbae..9f052df9c5c 100644 --- a/test/helpers/createLazyTestEnv.js +++ b/test/helpers/createLazyTestEnv.js @@ -72,7 +72,7 @@ module.exports = (env, globalTimeout = 2000, nameSuffix = "") => { fn = createOnceFn(fn); numberOfTests++; let spec; - if(fn) { + if (fn) { spec = env.fit(title, fn, timeout); } else { spec = env.fit(title, () => {}); diff --git a/test/helpers/remove.js b/test/helpers/remove.js index 747e9302dae..efa4f64f5d8 100644 --- a/test/helpers/remove.js +++ b/test/helpers/remove.js @@ -1,3 +1,6 @@ +const fs = require("fs"); +const path = require("path"); + module.exports.remove = function remove(src) { if (!fs.existsSync(src)) return; const files = fs.readdirSync(src); @@ -10,4 +13,4 @@ module.exports.remove = function remove(src) { fs.unlinkSync(srcFile); } }); -} +}; diff --git a/test/helpers/supportDefaultAssignment.js b/test/helpers/supportDefaultAssignment.js index 598c2cef9fc..4a714a48821 100644 --- a/test/helpers/supportDefaultAssignment.js +++ b/test/helpers/supportDefaultAssignment.js @@ -1,9 +1,10 @@ module.exports = function supportDefaultAssignment() { try { - var E = eval("class E { toString() { return 'default' } }") - var f1 = eval("(function f1({a, b = E}) {return new b().toString();})") - return f1({a: "test"}) === "default" ; - } catch(e) { + // eslint-disable-next-line no-unused-vars + var E = eval("class E { toString() { return 'default' } }"); + var f1 = eval("(function f1({a, b = E}) {return new b().toString();})"); + return f1({ a: "test" }) === "default"; + } catch (e) { return false; } }; diff --git a/test/helpers/supportsArrowFunctionExpression.js b/test/helpers/supportsArrowFunctionExpression.js index a3d9932c729..e325c33606e 100644 --- a/test/helpers/supportsArrowFunctionExpression.js +++ b/test/helpers/supportsArrowFunctionExpression.js @@ -1,8 +1,10 @@ module.exports = function supportArrowFunctionExpression() { try { - eval("var foo = function(fn) {return fn.toString()}; foo(() => {return 'a'})"); + eval( + "var foo = function(fn) {return fn.toString()}; foo(() => {return 'a'})" + ); return true; - } catch(e) { + } catch (e) { return false; } }; diff --git a/test/helpers/supportsBlockScoping.js b/test/helpers/supportsBlockScoping.js index e6d0fb44883..86f7330c5f1 100644 --- a/test/helpers/supportsBlockScoping.js +++ b/test/helpers/supportsBlockScoping.js @@ -1,8 +1,10 @@ module.exports = function supportsBlockScoping() { try { - var f = eval("(function f() { const x = 1; if (true) { const x = 2; } return x; })"); + var f = eval( + "(function f() { const x = 1; if (true) { const x = 2; } return x; })" + ); return f() === 1; - } catch(e) { + } catch (e) { return false; } }; diff --git a/test/helpers/supportsDefaultArgs.js b/test/helpers/supportsDefaultArgs.js index b20a6e1b685..e74cd97ed20 100644 --- a/test/helpers/supportsDefaultArgs.js +++ b/test/helpers/supportsDefaultArgs.js @@ -2,7 +2,7 @@ module.exports = function supportsDefaultArgs() { try { var f = eval("(function f(a = 123) { return a; })"); return f() === 123; - } catch(e) { + } catch (e) { return false; } }; diff --git a/test/helpers/supportsES6.js b/test/helpers/supportsES6.js index d7631f1ab4e..15857d9f52d 100644 --- a/test/helpers/supportsES6.js +++ b/test/helpers/supportsES6.js @@ -2,7 +2,7 @@ module.exports = function supportsES6() { try { eval("class A {}"); return true; - } catch(e) { + } catch (e) { return false; } }; diff --git a/test/helpers/supportsForOf.js b/test/helpers/supportsForOf.js index 332fddffe65..3411344fafb 100644 --- a/test/helpers/supportsForOf.js +++ b/test/helpers/supportsForOf.js @@ -1,8 +1,8 @@ module.exports = function supportDefaultAssignment() { try { var f = eval("(function f() { for(var x of ['ok', 'fail']) return x; })"); - return f() === "ok" ; - } catch(e) { + return f() === "ok"; + } catch (e) { return false; } }; diff --git a/test/helpers/supportsIteratorDestructuring.js b/test/helpers/supportsIteratorDestructuring.js index 8a604f15820..8945732f396 100644 --- a/test/helpers/supportsIteratorDestructuring.js +++ b/test/helpers/supportsIteratorDestructuring.js @@ -2,7 +2,7 @@ module.exports = function supportsIteratorDestructuring() { try { var f = eval("(function f([, x, ...y]) { return x; })"); return f([1, 2]) === 2; - } catch(e) { + } catch (e) { return false; } }; diff --git a/test/helpers/supportsObjectDestructuring.js b/test/helpers/supportsObjectDestructuring.js index c3be9e86d21..f60fcd52038 100644 --- a/test/helpers/supportsObjectDestructuring.js +++ b/test/helpers/supportsObjectDestructuring.js @@ -2,7 +2,7 @@ module.exports = function supportsObjectDestructuring() { try { var f = eval("(function f({x, y}) { return x + y; })"); return f({ x: 1, y: 2 }) === 3; - } catch(e) { + } catch (e) { return false; } }; diff --git a/test/helpers/supportsOptionalCatchBinding.js b/test/helpers/supportsOptionalCatchBinding.js index 8e3edbfb254..5fdeeca45c6 100644 --- a/test/helpers/supportsOptionalCatchBinding.js +++ b/test/helpers/supportsOptionalCatchBinding.js @@ -2,7 +2,7 @@ module.exports = function supportsOptionalCatchBinding() { try { eval("try {} catch {}"); return true; - } catch(e) { + } catch (e) { return false; } }; diff --git a/test/helpers/supportsSpread.js b/test/helpers/supportsSpread.js index 3ea317b61e6..76c10b204fa 100644 --- a/test/helpers/supportsSpread.js +++ b/test/helpers/supportsSpread.js @@ -1,9 +1,10 @@ module.exports = function supportsSpread() { try { - var x = { a: true }, y; // eslint-disable-line no-unused-vars + var x = { a: true }, + y; // eslint-disable-line no-unused-vars eval("y = { ...x }"); return y !== x && y.a; - } catch(e) { + } catch (e) { return false; } }; diff --git a/test/helpers/supportsTemplateStrings.js b/test/helpers/supportsTemplateStrings.js index 7c310eab89a..abfefd0ec6a 100644 --- a/test/helpers/supportsTemplateStrings.js +++ b/test/helpers/supportsTemplateStrings.js @@ -2,7 +2,7 @@ module.exports = function supportsTemplateStrings() { try { var f = eval("(function f() { return String.raw`a\\b`; })"); return f() === "a\\b"; - } catch(e) { + } catch (e) { return false; } }; diff --git a/test/helpers/supportsWebAssembly.js b/test/helpers/supportsWebAssembly.js index 51cbdbb573a..6eaf5259b7a 100644 --- a/test/helpers/supportsWebAssembly.js +++ b/test/helpers/supportsWebAssembly.js @@ -1,7 +1,7 @@ module.exports = function supportsWebAssembly() { try { return typeof WebAssembly !== "undefined"; - } catch(e) { + } catch (e) { return false; } }; From 85421cdbbd7a97c2aba809e9b710c251ae059cc7 Mon Sep 17 00:00:00 2001 From: Tobias Koppers Date: Thu, 22 Aug 2019 13:27:15 +0200 Subject: [PATCH 4/4] improve linting performance --- .eslintignore | 9 ++++++++- package.json | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/.eslintignore b/.eslintignore index dabb31606a7..f9f03214300 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1,14 +1,21 @@ # Ignore node_modules node_modules +# Ignore some folders +benchmark +coverage + # Ignore not support files !.*.js .eslintrc.js *.d.ts # Ignore some test files -test/**/*.js +test/* +!test/*Cases +!test/helpers !test/*.js +test/*Cases/**/*.js !test/*Cases/**/webpack.config.js # Ignore some examples files diff --git a/package.json b/package.json index 72cdee413e0..734cfd773aa 100644 --- a/package.json +++ b/package.json @@ -125,7 +125,7 @@ "special-lint": "node tooling/inherit-types && node tooling/format-schemas && node tooling/compile-to-definitions", "special-lint-fix": "node tooling/inherit-types --write --override && node tooling/format-schemas --write && node tooling/compile-to-definitions --write", "fix": "yarn code-lint --fix && yarn special-lint-fix", - "pretty": "prettier --loglevel warn --write \"*.{ts,js,json,yml,yaml}\" \"{setup,lib,bin,hot,buildin,benchmark,tooling,schemas}/**/*.{js,json}\" \"test/*.js\" \"test/{configCases,watchCases,statsCases,hotCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\"", + "pretty": "prettier --loglevel warn --write \"*.{ts,js,json,yml,yaml}\" \"{setup,lib,bin,hot,buildin,benchmark,tooling,schemas}/**/*.{js,json}\" \"test/*.js\" \"test/helpers/*.js\" \"test/{configCases,watchCases,statsCases,hotCases}/**/webpack.config.js\" \"examples/**/webpack.config.js\"", "jest-lint": "node --max-old-space-size=4096 node_modules/jest-cli/bin/jest --testMatch \"/test/*.lint.js\" --no-verbose", "benchmark": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"/test/*.benchmark.js\" --runInBand", "cover": "yarn cover:all && yarn cover:report",