Skip to content

Commit

Permalink
Merge pull request #9613 from shaodahong/optimize-eslint
Browse files Browse the repository at this point in the history
optimize eslint script
  • Loading branch information
sokra committed Aug 22, 2019
2 parents 9b02c19 + 85421cd commit 9dc49cf
Show file tree
Hide file tree
Showing 20 changed files with 91 additions and 52 deletions.
24 changes: 24 additions & 0 deletions .eslintignore
@@ -0,0 +1,24 @@
# Ignore node_modules
node_modules

# Ignore some folders
benchmark
coverage

# Ignore not support files
!.*.js
.eslintrc.js
*.d.ts

# Ignore some test files
test/*
!test/*Cases
!test/helpers
!test/*.js
test/*Cases/**/*.js
!test/*Cases/**/webpack.config.js

# Ignore some examples files
examples/**/*.js
!examples/*/webpack.config.js

15 changes: 9 additions & 6 deletions .eslintrc.js
Expand Up @@ -55,12 +55,15 @@ 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;
}, {})),
...["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",
Expand Down
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -120,12 +120,12 @@
"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\"",
"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 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 \"<rootDir>/test/*.lint.js\" --no-verbose",
"benchmark": "node --max-old-space-size=4096 --trace-deprecation node_modules/jest-cli/bin/jest --testMatch \"<rootDir>/test/*.benchmark.js\" --runInBand",
"cover": "yarn cover:all && yarn cover:report",
Expand Down
41 changes: 22 additions & 19 deletions test/helpers/PluginEnvironment.js
Expand Up @@ -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;
}
})
)
};
};

Expand Down
2 changes: 1 addition & 1 deletion test/helpers/TemplatePluginEnvironment.js
@@ -1,4 +1,4 @@
var PluginEnvironment = require('./PluginEnvironment');
var PluginEnvironment = require("./PluginEnvironment");

module.exports = function TemplatePluginEnvironment() {
var events = [];
Expand Down
6 changes: 3 additions & 3 deletions 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;

Expand Down
2 changes: 1 addition & 1 deletion test/helpers/createLazyTestEnv.js
Expand Up @@ -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, () => {});
Expand Down
5 changes: 4 additions & 1 deletion 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);
Expand All @@ -10,4 +13,4 @@ module.exports.remove = function remove(src) {
fs.unlinkSync(srcFile);
}
});
}
};
9 changes: 5 additions & 4 deletions 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;
}
};
6 changes: 4 additions & 2 deletions 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;
}
};
6 changes: 4 additions & 2 deletions 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;
}
};
2 changes: 1 addition & 1 deletion test/helpers/supportsDefaultArgs.js
Expand Up @@ -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;
}
};
2 changes: 1 addition & 1 deletion test/helpers/supportsES6.js
Expand Up @@ -2,7 +2,7 @@ module.exports = function supportsES6() {
try {
eval("class A {}");
return true;
} catch(e) {
} catch (e) {
return false;
}
};
4 changes: 2 additions & 2 deletions 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;
}
};
2 changes: 1 addition & 1 deletion test/helpers/supportsIteratorDestructuring.js
Expand Up @@ -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;
}
};
2 changes: 1 addition & 1 deletion test/helpers/supportsObjectDestructuring.js
Expand Up @@ -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;
}
};
2 changes: 1 addition & 1 deletion test/helpers/supportsOptionalCatchBinding.js
Expand Up @@ -2,7 +2,7 @@ module.exports = function supportsOptionalCatchBinding() {
try {
eval("try {} catch {}");
return true;
} catch(e) {
} catch (e) {
return false;
}
};
5 changes: 3 additions & 2 deletions 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;
}
};
2 changes: 1 addition & 1 deletion test/helpers/supportsTemplateStrings.js
Expand Up @@ -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;
}
};
2 changes: 1 addition & 1 deletion test/helpers/supportsWebAssembly.js
@@ -1,7 +1,7 @@
module.exports = function supportsWebAssembly() {
try {
return typeof WebAssembly !== "undefined";
} catch(e) {
} catch (e) {
return false;
}
};

0 comments on commit 9dc49cf

Please sign in to comment.