Skip to content

Commit 1359e24

Browse files
committed
[eslint] enable object-shorthand, space-before-function-paren
1 parent 49ada27 commit 1359e24

Some content is hidden

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

53 files changed

+209
-199
lines changed

.eslintrc

+10
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,23 @@
3131
"no-shadow": 1,
3232
"no-var": 2,
3333
"object-curly-spacing": [2, "always"],
34+
"object-shorthand": ["error", "always", {
35+
"ignoreConstructors": false,
36+
"avoidQuotes": true,
37+
}],
3438
"one-var": [2, "never"],
3539
"prefer-const": 2,
3640
"quotes": [2, "single", {
3741
"allowTemplateLiterals": true,
3842
"avoidEscape": true,
3943
}],
4044
"semi": [2, "always"],
45+
"space-before-function-paren": ["error", {
46+
"anonymous": "always",
47+
"named": "never",
48+
"asyncArrow": "always",
49+
}],
50+
4151
"eslint-plugin/consistent-output": [
4252
"error",
4353
"always",

resolvers/webpack/index.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ exports.resolve = function (source, file, settings) {
163163
const MAX_CACHE = 10;
164164
const _cache = [];
165165
function getResolveSync(configPath, webpackConfig, cwd) {
166-
const cacheKey = { configPath: configPath, webpackConfig: webpackConfig };
166+
const cacheKey = { configPath, webpackConfig };
167167
let cached = find(_cache, function (entry) { return isEqual(entry.key, cacheKey); });
168168
if (!cached) {
169169
cached = {
@@ -265,7 +265,7 @@ function createWebpack1ResolveSync(webpackRequire, resolveConfig, plugins) {
265265
resolver.apply(
266266
resolveConfig.packageAlias
267267
? new DirectoryDescriptionFileFieldAliasPlugin('package.json', resolveConfig.packageAlias)
268-
: function() {},
268+
: function () {},
269269
new ModuleAliasPlugin(resolveConfig.alias || {}),
270270
makeRootPlugin(ModulesInRootPlugin, 'module', resolveConfig.root),
271271
new ModulesInDirectoriesPlugin(
@@ -302,7 +302,7 @@ function createWebpack1ResolveSync(webpackRequire, resolveConfig, plugins) {
302302

303303
resolver.apply.apply(resolver, resolvePlugins);
304304

305-
return function() {
305+
return function () {
306306
return resolver.resolveSync.apply(resolver, arguments);
307307
};
308308
}
@@ -391,7 +391,7 @@ function findExternal(source, externals, context, resolveSync) {
391391
}
392392

393393
function findConfigPath(configPath, packageDir) {
394-
const extensions = Object.keys(interpret.extensions).sort(function(a, b) {
394+
const extensions = Object.keys(interpret.extensions).sort(function (a, b) {
395395
return a === '.js' ? -1 : b === '.js' ? 1 : a.length - b.length;
396396
});
397397
let extension;

resolvers/webpack/test/config.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('config', function () {
101101
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'foo.js'));
102102
});
103103

104-
it('finds the config at option env when config is a function', function() {
104+
it('finds the config at option env when config is a function', function () {
105105
const settings = {
106106
config: require(path.join(__dirname, './files/webpack.function.config.js')),
107107
env: {
@@ -113,7 +113,7 @@ describe('config', function () {
113113
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'bar.js'));
114114
});
115115

116-
it('finds the config at option env when config is an array of functions', function() {
116+
it('finds the config at option env when config is an array of functions', function () {
117117
const settings = {
118118
config: require(path.join(__dirname, './files/webpack.function.config.multiple.js')),
119119
env: {
@@ -125,7 +125,7 @@ describe('config', function () {
125125
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'bar.js'));
126126
});
127127

128-
it('passes argv to config when it is a function', function() {
128+
it('passes argv to config when it is a function', function () {
129129
const settings = {
130130
config: require(path.join(__dirname, './files/webpack.function.config.js')),
131131
argv: {
@@ -137,7 +137,7 @@ describe('config', function () {
137137
.and.equal(path.join(__dirname, 'files', 'some', 'bar', 'bar.js'));
138138
});
139139

140-
it('passes a default empty argv object to config when it is a function', function() {
140+
it('passes a default empty argv object to config when it is a function', function () {
141141
const settings = {
142142
config: require(path.join(__dirname, './files/webpack.function.config.js')),
143143
argv: undefined,
@@ -146,7 +146,7 @@ describe('config', function () {
146146
expect(function () { resolve('baz', file, settings); }).to.not.throw(Error);
147147
});
148148

149-
it('prevents async config using', function() {
149+
it('prevents async config using', function () {
150150
const settings = {
151151
config: require(path.join(__dirname, './files/webpack.config.async.js')),
152152
};

src/rules/default.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module.exports = {
1010
schema: [],
1111
},
1212

13-
create: function (context) {
13+
create(context) {
1414

1515
function checkDefault(specifierType, node) {
1616

src/rules/dynamic-import-chunkname.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ module.exports = {
2424
}],
2525
},
2626

27-
create: function (context) {
27+
create(context) {
2828
const config = context.options[0];
2929
const { importFunctions = [] } = config || {};
3030
const { webpackChunknameFormat = '[0-9a-zA-Z-_/.]+' } = config || {};

src/rules/export.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ module.exports = {
5454
schema: [],
5555
},
5656

57-
create: function (context) {
57+
create(context) {
5858
const namespace = new Map([[rootProgram, new Map()]]);
5959

6060
function addNamed(name, node, parent, isType) {

src/rules/exports-last.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ module.exports = {
1515
schema: [],
1616
},
1717

18-
create: function (context) {
18+
create(context) {
1919
return {
20-
Program: function ({ body }) {
20+
Program({ body }) {
2121
const lastNonExportStatementIndex = body.reduce(function findLastIndex(acc, item, index) {
2222
if (isNonExportStatement(item)) {
2323
return index;

src/rules/extensions.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ module.exports = {
103103
},
104104
},
105105

106-
create: function (context) {
106+
create(context) {
107107

108108
const props = buildProperties(context);
109109

src/rules/first.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ module.exports = {
2121
],
2222
},
2323

24-
create: function (context) {
25-
function isPossibleDirective (node) {
24+
create(context) {
25+
function isPossibleDirective(node) {
2626
return node.type === 'ExpressionStatement' &&
2727
node.expression.type === 'Literal' &&
2828
typeof node.expression.value === 'string';

src/rules/named.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
],
2222
},
2323

24-
create: function (context) {
24+
create(context) {
2525
const options = context.options[0] || {};
2626

2727
function checkSpecifiers(key, type, node) {

src/rules/newline-after-import.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ module.exports = {
7272
},
7373
],
7474
},
75-
create: function (context) {
75+
create(context) {
7676
let level = 0;
7777
const requireCalls = [];
7878

@@ -138,7 +138,7 @@ after ${type} statement not followed by another ${type}.`,
138138
return {
139139
ImportDeclaration: checkImport,
140140
TSImportEqualsDeclaration: checkImport,
141-
CallExpression: function(node) {
141+
CallExpression(node) {
142142
if (isStaticRequire(node) && level === 0) {
143143
requireCalls.push(node);
144144
}

src/rules/no-absolute-path.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
schema: [ makeOptionsSchema() ],
1212
},
1313

14-
create: function (context) {
14+
create(context) {
1515
function reportIfAbsolute(source) {
1616
if (typeof source.value === 'string' && isAbsolute(source.value)) {
1717
context.report(source, 'Do not import modules using an absolute path');

src/rules/no-amd.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
schema: [],
1919
},
2020

21-
create: function (context) {
21+
create(context) {
2222
return {
2323
'CallExpression': function (node) {
2424
if (context.getScope().type !== 'module') return;

src/rules/no-anonymous-default-export.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ module.exports = {
8686
],
8787
},
8888

89-
create: function (context) {
89+
create(context) {
9090
const options = Object.assign({}, defaults, context.options[0]);
9191

9292
return {

src/rules/no-commonjs.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ module.exports = {
8888
},
8989
},
9090

91-
create: function (context) {
91+
create(context) {
9292
const options = normalizeLegacyOptions(context.options);
9393

9494
return {

src/rules/no-cycle.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ module.exports = {
3636
})],
3737
},
3838

39-
create: function (context) {
39+
create(context) {
4040
const myPath = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
4141
if (myPath === '<text>') return {}; // can't cycle-check a non-file
4242

src/rules/no-deprecated.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
schema: [],
2222
},
2323

24-
create: function (context) {
24+
create(context) {
2525
const deprecated = new Map();
2626
const namespaces = new Map();
2727

src/rules/no-duplicates.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ module.exports = {
261261
],
262262
},
263263

264-
create: function (context) {
264+
create(context) {
265265
// Prepare the resolver from options.
266266
const considerQueryStringOption = context.options[0] &&
267267
context.options[0]['considerQueryString'];
@@ -300,7 +300,7 @@ module.exports = {
300300
}
301301
},
302302

303-
'Program:exit'() {
303+
'Program:exit': function () {
304304
checkImports(imported, context);
305305
checkImports(nsImported, context);
306306
checkImports(defaultTypesImported, context);

src/rules/no-dynamic-require.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module.exports = {
3838
],
3939
},
4040

41-
create: function (context) {
41+
create(context) {
4242
const options = context.options[0] || {};
4343

4444
return {

src/rules/no-extraneous-dependencies.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ module.exports = {
252252
],
253253
},
254254

255-
create: function (context) {
255+
create(context) {
256256
const options = context.options[0] || {};
257257
const filename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
258258
const deps = getDependencies(context, options.packageDir) || extractDepFields({});

src/rules/no-mutable-exports.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
schema: [],
1010
},
1111

12-
create: function (context) {
12+
create(context) {
1313
function checkDeclaration(node) {
1414
const { kind } = node;
1515
if (kind === 'var' || kind === 'let') {

src/rules/no-named-as-default-member.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = {
2121
schema: [],
2222
},
2323

24-
create: function(context) {
24+
create(context) {
2525

2626
const fileImports = new Map();
2727
const allPropertyLookups = new Map();

src/rules/no-named-as-default.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module.exports = {
1111
schema: [],
1212
},
1313

14-
create: function (context) {
14+
create(context) {
1515
function checkDefault(nameKey, defaultSpecifier) {
1616
// #566: default is a valid specifier
1717
if (defaultSpecifier[nameKey].name === 'default') return;

src/rules/no-named-default.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module.exports = {
99
schema: [],
1010
},
1111

12-
create: function (context) {
12+
create(context) {
1313
return {
1414
'ImportDeclaration': function (node) {
1515
node.specifiers.forEach(function (im) {

src/rules/no-namespace.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ module.exports = {
3232
}],
3333
},
3434

35-
create: function (context) {
35+
create(context) {
3636
const firstOption = context.options[0] || {};
3737
const ignoreGlobs = firstOption.ignore;
3838

src/rules/no-nodejs-modules.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ module.exports = {
3131
],
3232
},
3333

34-
create: function (context) {
34+
create(context) {
3535
const options = context.options[0] || {};
3636
const allowed = options.allow || [];
3737

src/rules/no-self-import.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ module.exports = {
3030

3131
schema: [],
3232
},
33-
create: function (context) {
33+
create(context) {
3434
return moduleVisitor((source, node) => {
3535
isImportingSelf(context, node, source.value);
3636
}, { commonjs: true });

src/rules/no-unresolved.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module.exports = {
2222
],
2323
},
2424

25-
create: function (context) {
25+
create(context) {
2626
function checkSourceValue(source) {
2727
const shouldCheckCase = !CASE_SENSITIVE_FS
2828
&& (!context.options[0] || context.options[0].caseSensitive !== false);

src/rules/no-unused-modules.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ try {
3232
// https://github.com/eslint/eslint/blob/v5.2.0/lib/util/glob-util.js#L174-L269
3333
listFilesToProcess = function (src, extensions) {
3434
return originalListFilesToProcess(src, {
35-
extensions: extensions,
35+
extensions,
3636
});
3737
};
3838
} catch (e) {
@@ -54,7 +54,7 @@ try {
5454
if (FileEnumerator) {
5555
listFilesToProcess = function (src, extensions) {
5656
const e = new FileEnumerator({
57-
extensions: extensions,
57+
extensions,
5858
});
5959

6060
return Array.from(e.iterateFiles(src), ({ filePath, ignored }) => ({

src/rules/no-webpack-loader-syntax.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = {
1818
schema: [],
1919
},
2020

21-
create: function (context) {
21+
create(context) {
2222
return moduleVisitor((source, node) => {
2323
reportIfNonStandard(context, node, source.value);
2424
}, { commonjs: true });

0 commit comments

Comments
 (0)