Skip to content

Commit 8c155ba

Browse files
committed
[eslint] tighten up rules
1 parent 9799567 commit 8c155ba

File tree

106 files changed

+1405
-1370
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+1405
-1370
lines changed

.eslintrc

+91-4
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,66 @@
1212
"env": {
1313
"node": true,
1414
"es6": true,
15+
"es2017": true,
1516
},
1617
"parserOptions": {
1718
"sourceType": "module",
1819
"ecmaVersion": 2020,
1920
},
2021
"rules": {
22+
"arrow-body-style": [2, "as-needed"],
23+
"arrow-parens": [2, "always"],
24+
"arrow-spacing": [2, { "before": true, "after": true }],
25+
"block-spacing": [2, "always"],
26+
"brace-style": [2, "1tbs", { "allowSingleLine": true }],
2127
"comma-dangle": ["error", {
2228
"arrays": "always-multiline",
2329
"objects": "always-multiline",
2430
"imports": "always-multiline",
2531
"exports": "always-multiline",
2632
"functions": "always-multiline",
2733
}],
34+
"comma-spacing": [2, { "before": false, "after": true }],
2835
"comma-style": [2, "last"],
29-
"curly": [2, "multi-line"],
36+
"computed-property-spacing": [2, "never"],
37+
"curly": [2, "all"],
38+
"default-case": [2, { "commentPattern": "(?:)" }],
39+
"default-case-last": [2],
40+
"default-param-last": [2],
41+
"dot-location": [2, "property"],
42+
"dot-notation": [2, { "allowKeywords": true, "allowPattern": "throws" }],
3043
"eol-last": [2, "always"],
3144
"eqeqeq": [2, "allow-null"],
32-
"func-call-spacing": 2,
33-
"indent": [2, 2],
45+
"for-direction": [2],
46+
"function-call-argument-newline": [2, "consistent"],
47+
"func-call-spacing": [2, "never"],
48+
"implicit-arrow-linebreak": [2, "beside"],
49+
"indent": [2, 2, {
50+
"SwitchCase": 1,
51+
"VariableDeclarator": 1,
52+
"outerIIFEBody": 1,
53+
"FunctionDeclaration": {
54+
"parameters": 1,
55+
"body": 1
56+
},
57+
"FunctionExpression": {
58+
"parameters": 1,
59+
"body": 1
60+
},
61+
"CallExpression": {
62+
"arguments": 1
63+
},
64+
"ArrayExpression": 1,
65+
"ObjectExpression": 1,
66+
"ImportDeclaration": 1,
67+
"flatTernaryExpressions": false,
68+
}],
69+
"jsx-quotes": [2, "prefer-double"],
70+
"key-spacing": [2, {
71+
"beforeColon": false,
72+
"afterColon": true,
73+
"mode": "strict",
74+
}],
3475
"keyword-spacing": ["error", {
3576
"before": true,
3677
"after": true,
@@ -40,27 +81,68 @@
4081
"case": { "after": true }
4182
}
4283
}],
84+
"linebreak-style": [2, "unix"],
85+
"lines-around-directive": [2, {
86+
"before": "always",
87+
"after": "always",
88+
}],
4389
"max-len": 0,
90+
"new-parens": 2,
91+
"no-array-constructor": 2,
92+
"no-compare-neg-zero": 2,
4493
"no-cond-assign": [2, "always"],
94+
"no-extra-parens": 2,
95+
"no-multiple-empty-lines": [2, { "max": 1, "maxEOF": 1, "maxBOF": 0 }],
4596
"no-return-assign": [2, "always"],
97+
"no-trailing-spaces": 2,
4698
"no-var": 2,
4799
"object-curly-spacing": [2, "always"],
48100
"object-shorthand": ["error", "always", {
49101
"ignoreConstructors": false,
50-
"avoidQuotes": true,
102+
"avoidQuotes": false,
103+
"avoidExplicitReturnArrows": true,
51104
}],
52105
"one-var": [2, "never"],
106+
"operator-linebreak": [2, "none", {
107+
"overrides": {
108+
"?": "before",
109+
":": "before",
110+
"&&": "before",
111+
"||": "before",
112+
},
113+
}],
53114
"prefer-const": 2,
115+
"prefer-object-spread": 2,
116+
"prefer-rest-params": 2,
117+
"prefer-template": 2,
118+
"quote-props": [2, "as-needed", { "keywords": false }],
54119
"quotes": [2, "single", {
55120
"allowTemplateLiterals": true,
56121
"avoidEscape": true,
57122
}],
123+
"rest-spread-spacing": [2, "never"],
58124
"semi": [2, "always"],
125+
"semi-spacing": [2, { "before": false, "after": true }],
126+
"semi-style": [2, "last"],
127+
"space-before-blocks": [2, { "functions": "always", "keywords": "always", "classes": "always" }],
59128
"space-before-function-paren": ["error", {
60129
"anonymous": "always",
61130
"named": "never",
62131
"asyncArrow": "always",
63132
}],
133+
"space-in-parens": [2, "never"],
134+
"space-infix-ops": [2],
135+
"space-unary-ops": [2, { "words": true, "nonwords": false }],
136+
"switch-colon-spacing": [2, { "after": true, "before": false }],
137+
"template-curly-spacing": [2, "never"],
138+
"template-tag-spacing": [2, "never"],
139+
"unicode-bom": [2, "never"],
140+
"use-isnan": [2, { "enforceForSwitchCase": true }],
141+
"valid-typeof": [2],
142+
"wrap-iife": [2, "outside", { "functionPrototypeMethods": true }],
143+
"wrap-regex": [2],
144+
"yield-star-spacing": [2, { "before": false, "after": true }],
145+
"yoda": [2, "never", { "exceptRange": true, "onlyEquality": false }],
64146

65147
"eslint-plugin/consistent-output": [
66148
"error",
@@ -116,6 +198,9 @@
116198
"files": "resolvers/webpack/**",
117199
"rules": {
118200
"no-console": 1,
201+
"prefer-template": 0,
202+
"prefer-object-spread": 0,
203+
"prefer-rest-params": 0,
119204
},
120205
"env": {
121206
"es6": true,
@@ -143,6 +228,8 @@
143228
"exports": "always-multiline",
144229
"functions": "never"
145230
}],
231+
"prefer-object-spread": "off",
232+
"prefer-template": "off",
146233
"no-console": 1,
147234
},
148235
},

config/typescript.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ module.exports = {
1616
'@typescript-eslint/parser': ['.ts', '.tsx'],
1717
},
1818
'import/resolver': {
19-
'node': {
20-
'extensions': allExtensions,
19+
node: {
20+
extensions: allExtensions,
2121
},
2222
},
2323
},

memo-parser/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const parserOptions = {
1717
};
1818

1919
exports.parse = function parse(content, options) {
20-
options = Object.assign({}, options, parserOptions);
20+
options = { ...options, ...parserOptions };
2121

2222
if (!options.filePath) {
2323
throw new Error('no file path provided!');
@@ -30,7 +30,7 @@ exports.parse = function parse(content, options) {
3030
const key = keyHash.digest('hex');
3131

3232
let ast = cache.get(key);
33-
if (ast != null) return ast;
33+
if (ast != null) { return ast; }
3434

3535
const realParser = moduleRequire(options.parser);
3636

resolvers/node/index.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,14 @@ exports.resolve = function (source, file, config) {
2929
};
3030

3131
function opts(file, config, packageFilter) {
32-
return Object.assign({
33-
// more closely matches Node (#333)
32+
return { // more closely matches Node (#333)
3433
// plus 'mjs' for native modules! (#939)
3534
extensions: ['.mjs', '.js', '.json', '.node'],
36-
},
37-
config,
38-
{
35+
...config,
3936
// path.resolve will handle paths relative to CWD
4037
basedir: path.dirname(path.resolve(file)),
4138
packageFilter,
42-
});
39+
};
4340
}
4441

4542
function identity(x) { return x; }

resolvers/node/test/packageMains.js

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const resolver = require('../');
88

99
const file = path.join(__dirname, 'package-mains', 'dummy.js');
1010

11-
1211
describe('packageMains', function () {
1312
it('captures module', function () {
1413
expect(resolver.resolve('./module', file)).property('path')

resolvers/node/test/paths.js

-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ describe('paths', function () {
1111
});
1212
});
1313

14-
1514
describe('core', function () {
1615
it('returns found, but null path, for core Node modules', function () {
1716
const resolved = node.resolve('fs', './test/file.js');
@@ -20,7 +19,6 @@ describe('core', function () {
2019
});
2120
});
2221

23-
2422
describe('default options', function () {
2523

2624
it('finds .json files', function () {

resolvers/webpack/index.js

+9-11
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ exports.resolve = function (source, file, settings) {
7575
if (!configPath || !path.isAbsolute(configPath)) {
7676
// if not, find ancestral package.json and use its directory as base for the path
7777
packageDir = findRoot(path.resolve(file));
78-
if (!packageDir) throw new Error('package not found above ' + file);
78+
if (!packageDir) { throw new Error('package not found above ' + file); }
7979
}
8080

8181
configPath = findConfigPath(configPath, packageDir);
@@ -108,7 +108,7 @@ exports.resolve = function (source, file, settings) {
108108
}
109109

110110
if (Array.isArray(webpackConfig)) {
111-
webpackConfig = webpackConfig.map(cfg => {
111+
webpackConfig = webpackConfig.map((cfg) => {
112112
if (typeof cfg === 'function') {
113113
return cfg(env, argv);
114114
}
@@ -284,16 +284,15 @@ function createWebpack1ResolveSync(webpackRequire, resolveConfig, plugins) {
284284
new ResultSymlinkPlugin(),
285285
);
286286

287-
288287
const resolvePlugins = [];
289288

290289
// support webpack.ResolverPlugin
291290
if (plugins) {
292291
plugins.forEach(function (plugin) {
293292
if (
294-
plugin.constructor &&
295-
plugin.constructor.name === 'ResolverPlugin' &&
296-
Array.isArray(plugin.plugins)
293+
plugin.constructor
294+
&& plugin.constructor.name === 'ResolverPlugin'
295+
&& Array.isArray(plugin.plugins)
297296
) {
298297
resolvePlugins.push.apply(resolvePlugins, plugin.plugins);
299298
}
@@ -324,10 +323,10 @@ function makeRootPlugin(ModulesInRootPlugin, name, root) {
324323
/* eslint-enable */
325324

326325
function findExternal(source, externals, context, resolveSync) {
327-
if (!externals) return false;
326+
if (!externals) { return false; }
328327

329328
// string match
330-
if (typeof externals === 'string') return (source === externals);
329+
if (typeof externals === 'string') { return source === externals; }
331330

332331
// array: recurse
333332
if (Array.isArray(externals)) {
@@ -384,8 +383,8 @@ function findExternal(source, externals, context, resolveSync) {
384383

385384
// else, vanilla object
386385
for (const key in externals) {
387-
if (!has(externals, key)) continue;
388-
if (source === key) return true;
386+
if (!has(externals, key)) { continue; }
387+
if (source === key) { return true; }
389388
}
390389
return false;
391390
}
@@ -396,7 +395,6 @@ function findConfigPath(configPath, packageDir) {
396395
});
397396
let extension;
398397

399-
400398
if (configPath) {
401399
// extensions is not reused below, so safe to mutate it here.
402400
extensions.reverse();

resolvers/webpack/test/config-extensions/webpack.config.babel.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'path';
33
export default {
44
resolve: {
55
alias: {
6-
'foo': path.join(__dirname, 'some', 'goofy', 'path', 'foo.js'),
6+
foo: path.join(__dirname, 'some', 'goofy', 'path', 'foo.js'),
77
},
88
modules: [
99
path.join(__dirname, 'src'),
@@ -17,7 +17,7 @@ export default {
1717
},
1818

1919
externals: [
20-
{ 'jquery': 'jQuery' },
20+
{ jquery: 'jQuery' },
2121
'bootstrap',
2222
],
2323
};

resolvers/webpack/test/extensions.js

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const path = require('path');
66

77
const resolve = require('../index').resolve;
88

9-
109
const file = path.join(__dirname, 'files', 'dummy.js');
1110
const extensions = path.join(__dirname, 'custom-extensions', 'dummy.js');
1211

resolvers/webpack/test/fallback.js

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const path = require('path');
66

77
const resolve = require('../index').resolve;
88

9-
109
const file = path.join(__dirname, 'files', 'src', 'dummy.js');
1110

1211
describe('fallback', function () {

resolvers/webpack/test/loaders.js

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const path = require('path');
66

77
const resolve = require('../index').resolve;
88

9-
109
const file = path.join(__dirname, 'files', 'dummy.js');
1110

1211
describe('inline loader syntax', function () {

resolvers/webpack/test/packageMains.js

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const resolver = require('../');
88

99
const file = path.join(__dirname, 'package-mains', 'dummy.js');
1010

11-
1211
describe('packageMains', function () {
1312

1413
it('captures module', function () {

resolvers/webpack/test/root.js

-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ const path = require('path');
66

77
const resolve = require('../index').resolve;
88

9-
109
const file = path.join(__dirname, 'files', 'src', 'dummy.js');
1110
const webpackDir = path.join(__dirname, 'different-package-location');
1211

scripts/testAll.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@ const spawnOptions = {
1010
spawnSync(
1111
npmPath,
1212
['test'],
13-
Object.assign({ cwd: __dirname }, spawnOptions));
13+
{ cwd: __dirname, ...spawnOptions });
1414

1515
for (const resolverDir of resolverDirectories) {
1616
spawnSync(
1717
npmPath,
1818
['test'],
19-
Object.assign({ cwd: resolverDir }, spawnOptions));
19+
{ cwd: resolverDir, ...spawnOptions });
2020
}

0 commit comments

Comments
 (0)