Skip to content

Commit

Permalink
[eslint] enable object-shorthand, space-before-function-paren
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 28, 2021
1 parent 49ada27 commit 1359e24
Show file tree
Hide file tree
Showing 53 changed files with 209 additions and 199 deletions.
10 changes: 10 additions & 0 deletions .eslintrc
Expand Up @@ -31,13 +31,23 @@
"no-shadow": 1,
"no-var": 2,
"object-curly-spacing": [2, "always"],
"object-shorthand": ["error", "always", {
"ignoreConstructors": false,
"avoidQuotes": true,
}],
"one-var": [2, "never"],
"prefer-const": 2,
"quotes": [2, "single", {
"allowTemplateLiterals": true,
"avoidEscape": true,
}],
"semi": [2, "always"],
"space-before-function-paren": ["error", {
"anonymous": "always",
"named": "never",
"asyncArrow": "always",
}],

"eslint-plugin/consistent-output": [
"error",
"always",
Expand Down
8 changes: 4 additions & 4 deletions resolvers/webpack/index.js
Expand Up @@ -163,7 +163,7 @@ exports.resolve = function (source, file, settings) {
const MAX_CACHE = 10;
const _cache = [];
function getResolveSync(configPath, webpackConfig, cwd) {
const cacheKey = { configPath: configPath, webpackConfig: webpackConfig };
const cacheKey = { configPath, webpackConfig };
let cached = find(_cache, function (entry) { return isEqual(entry.key, cacheKey); });
if (!cached) {
cached = {
Expand Down Expand Up @@ -265,7 +265,7 @@ function createWebpack1ResolveSync(webpackRequire, resolveConfig, plugins) {
resolver.apply(
resolveConfig.packageAlias
? new DirectoryDescriptionFileFieldAliasPlugin('package.json', resolveConfig.packageAlias)
: function() {},
: function () {},
new ModuleAliasPlugin(resolveConfig.alias || {}),
makeRootPlugin(ModulesInRootPlugin, 'module', resolveConfig.root),
new ModulesInDirectoriesPlugin(
Expand Down Expand Up @@ -302,7 +302,7 @@ function createWebpack1ResolveSync(webpackRequire, resolveConfig, plugins) {

resolver.apply.apply(resolver, resolvePlugins);

return function() {
return function () {
return resolver.resolveSync.apply(resolver, arguments);
};
}
Expand Down Expand Up @@ -391,7 +391,7 @@ function findExternal(source, externals, context, resolveSync) {
}

function findConfigPath(configPath, packageDir) {
const extensions = Object.keys(interpret.extensions).sort(function(a, b) {
const extensions = Object.keys(interpret.extensions).sort(function (a, b) {
return a === '.js' ? -1 : b === '.js' ? 1 : a.length - b.length;
});
let extension;
Expand Down
10 changes: 5 additions & 5 deletions resolvers/webpack/test/config.js
Expand Up @@ -101,7 +101,7 @@ describe('config', function () {
.and.equal(path.join(__dirname, 'files', 'some', 'goofy', 'path', 'foo.js'));
});

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

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

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

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

it('prevents async config using', function() {
it('prevents async config using', function () {
const settings = {
config: require(path.join(__dirname, './files/webpack.config.async.js')),
};
Expand Down
2 changes: 1 addition & 1 deletion src/rules/default.js
Expand Up @@ -10,7 +10,7 @@ module.exports = {
schema: [],
},

create: function (context) {
create(context) {

function checkDefault(specifierType, node) {

Expand Down
2 changes: 1 addition & 1 deletion src/rules/dynamic-import-chunkname.js
Expand Up @@ -24,7 +24,7 @@ module.exports = {
}],
},

create: function (context) {
create(context) {
const config = context.options[0];
const { importFunctions = [] } = config || {};
const { webpackChunknameFormat = '[0-9a-zA-Z-_/.]+' } = config || {};
Expand Down
2 changes: 1 addition & 1 deletion src/rules/export.js
Expand Up @@ -54,7 +54,7 @@ module.exports = {
schema: [],
},

create: function (context) {
create(context) {
const namespace = new Map([[rootProgram, new Map()]]);

function addNamed(name, node, parent, isType) {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/exports-last.js
Expand Up @@ -15,9 +15,9 @@ module.exports = {
schema: [],
},

create: function (context) {
create(context) {
return {
Program: function ({ body }) {
Program({ body }) {
const lastNonExportStatementIndex = body.reduce(function findLastIndex(acc, item, index) {
if (isNonExportStatement(item)) {
return index;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/extensions.js
Expand Up @@ -103,7 +103,7 @@ module.exports = {
},
},

create: function (context) {
create(context) {

const props = buildProperties(context);

Expand Down
4 changes: 2 additions & 2 deletions src/rules/first.js
Expand Up @@ -21,8 +21,8 @@ module.exports = {
],
},

create: function (context) {
function isPossibleDirective (node) {
create(context) {
function isPossibleDirective(node) {
return node.type === 'ExpressionStatement' &&
node.expression.type === 'Literal' &&
typeof node.expression.value === 'string';
Expand Down
2 changes: 1 addition & 1 deletion src/rules/named.js
Expand Up @@ -21,7 +21,7 @@ module.exports = {
],
},

create: function (context) {
create(context) {
const options = context.options[0] || {};

function checkSpecifiers(key, type, node) {
Expand Down
4 changes: 2 additions & 2 deletions src/rules/newline-after-import.js
Expand Up @@ -72,7 +72,7 @@ module.exports = {
},
],
},
create: function (context) {
create(context) {
let level = 0;
const requireCalls = [];

Expand Down Expand Up @@ -138,7 +138,7 @@ after ${type} statement not followed by another ${type}.`,
return {
ImportDeclaration: checkImport,
TSImportEqualsDeclaration: checkImport,
CallExpression: function(node) {
CallExpression(node) {
if (isStaticRequire(node) && level === 0) {
requireCalls.push(node);
}
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-absolute-path.js
Expand Up @@ -11,7 +11,7 @@ module.exports = {
schema: [ makeOptionsSchema() ],
},

create: function (context) {
create(context) {
function reportIfAbsolute(source) {
if (typeof source.value === 'string' && isAbsolute(source.value)) {
context.report(source, 'Do not import modules using an absolute path');
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-amd.js
Expand Up @@ -18,7 +18,7 @@ module.exports = {
schema: [],
},

create: function (context) {
create(context) {
return {
'CallExpression': function (node) {
if (context.getScope().type !== 'module') return;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-anonymous-default-export.js
Expand Up @@ -86,7 +86,7 @@ module.exports = {
],
},

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

return {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-commonjs.js
Expand Up @@ -88,7 +88,7 @@ module.exports = {
},
},

create: function (context) {
create(context) {
const options = normalizeLegacyOptions(context.options);

return {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-cycle.js
Expand Up @@ -36,7 +36,7 @@ module.exports = {
})],
},

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

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-deprecated.js
Expand Up @@ -21,7 +21,7 @@ module.exports = {
schema: [],
},

create: function (context) {
create(context) {
const deprecated = new Map();
const namespaces = new Map();

Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-duplicates.js
Expand Up @@ -261,7 +261,7 @@ module.exports = {
],
},

create: function (context) {
create(context) {
// Prepare the resolver from options.
const considerQueryStringOption = context.options[0] &&
context.options[0]['considerQueryString'];
Expand Down Expand Up @@ -300,7 +300,7 @@ module.exports = {
}
},

'Program:exit'() {
'Program:exit': function () {
checkImports(imported, context);
checkImports(nsImported, context);
checkImports(defaultTypesImported, context);
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-dynamic-require.js
Expand Up @@ -38,7 +38,7 @@ module.exports = {
],
},

create: function (context) {
create(context) {
const options = context.options[0] || {};

return {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-extraneous-dependencies.js
Expand Up @@ -252,7 +252,7 @@ module.exports = {
],
},

create: function (context) {
create(context) {
const options = context.options[0] || {};
const filename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename();
const deps = getDependencies(context, options.packageDir) || extractDepFields({});
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-mutable-exports.js
Expand Up @@ -9,7 +9,7 @@ module.exports = {
schema: [],
},

create: function (context) {
create(context) {
function checkDeclaration(node) {
const { kind } = node;
if (kind === 'var' || kind === 'let') {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-named-as-default-member.js
Expand Up @@ -21,7 +21,7 @@ module.exports = {
schema: [],
},

create: function(context) {
create(context) {

const fileImports = new Map();
const allPropertyLookups = new Map();
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-named-as-default.js
Expand Up @@ -11,7 +11,7 @@ module.exports = {
schema: [],
},

create: function (context) {
create(context) {
function checkDefault(nameKey, defaultSpecifier) {
// #566: default is a valid specifier
if (defaultSpecifier[nameKey].name === 'default') return;
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-named-default.js
Expand Up @@ -9,7 +9,7 @@ module.exports = {
schema: [],
},

create: function (context) {
create(context) {
return {
'ImportDeclaration': function (node) {
node.specifiers.forEach(function (im) {
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-namespace.js
Expand Up @@ -32,7 +32,7 @@ module.exports = {
}],
},

create: function (context) {
create(context) {
const firstOption = context.options[0] || {};
const ignoreGlobs = firstOption.ignore;

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-nodejs-modules.js
Expand Up @@ -31,7 +31,7 @@ module.exports = {
],
},

create: function (context) {
create(context) {
const options = context.options[0] || {};
const allowed = options.allow || [];

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-self-import.js
Expand Up @@ -30,7 +30,7 @@ module.exports = {

schema: [],
},
create: function (context) {
create(context) {
return moduleVisitor((source, node) => {
isImportingSelf(context, node, source.value);
}, { commonjs: true });
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-unresolved.js
Expand Up @@ -22,7 +22,7 @@ module.exports = {
],
},

create: function (context) {
create(context) {
function checkSourceValue(source) {
const shouldCheckCase = !CASE_SENSITIVE_FS
&& (!context.options[0] || context.options[0].caseSensitive !== false);
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-unused-modules.js
Expand Up @@ -32,7 +32,7 @@ try {
// https://github.com/eslint/eslint/blob/v5.2.0/lib/util/glob-util.js#L174-L269
listFilesToProcess = function (src, extensions) {
return originalListFilesToProcess(src, {
extensions: extensions,
extensions,
});
};
} catch (e) {
Expand All @@ -54,7 +54,7 @@ try {
if (FileEnumerator) {
listFilesToProcess = function (src, extensions) {
const e = new FileEnumerator({
extensions: extensions,
extensions,
});

return Array.from(e.iterateFiles(src), ({ filePath, ignored }) => ({
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-webpack-loader-syntax.js
Expand Up @@ -18,7 +18,7 @@ module.exports = {
schema: [],
},

create: function (context) {
create(context) {
return moduleVisitor((source, node) => {
reportIfNonStandard(context, node, source.value);
}, { commonjs: true });
Expand Down

0 comments on commit 1359e24

Please sign in to comment.