Skip to content

Commit

Permalink
[eslint] consolidate configs
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 9, 2021
1 parent 332d3c8 commit cdcc76a
Show file tree
Hide file tree
Showing 18 changed files with 71 additions and 65 deletions.
47 changes: 37 additions & 10 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,31 @@
"ecmaVersion": 2020,
},
"rules": {
"comma-dangle": [2, "always-multiline"],
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "always-multiline",
}],
"comma-style": [2, "last"],
"curly": [2, "multi-line"],
"eol-last": [2, "always"],
"eqeqeq": [2, "allow-null"],
"func-call-spacing": 2,
"indent": [2, 2],
"keyword-spacing": ["error", {
before: true,
after: true,
overrides: {
return: { after: true },
throw: { after: true },
case: { after: true }
"before": true,
"after": true,
"overrides": {
"return": { "after": true },
"throw": { "after": true },
"case": { "after": true }
}
}],
"max-len": [1, 99, 2],
"max-len": 0,
"no-cond-assign": [2, "always"],
"no-return-assign": [2, "always"],
"no-shadow": 1,
"no-var": 2,
"object-curly-spacing": [2, "always"],
"object-shorthand": ["error", "always", {
Expand Down Expand Up @@ -91,6 +96,12 @@
"no-console": "off",
},
},
{
"files": "resolvers/**",
"env": {
"es6": false,
},
},
{
"files": [
"resolvers/*/test/**/*",
Expand All @@ -99,6 +110,22 @@
"mocha": true,
"es6": false
},
}
},
{
"files": "utils/**",
"parserOptions": {
"ecmaVersion": 6,
},
"rules": {
"comma-dangle": ["error", {
"arrays": "always-multiline",
"objects": "always-multiline",
"imports": "always-multiline",
"exports": "always-multiline",
"functions": "never"
}],
"no-console": 1,
},
},
],
}
3 changes: 0 additions & 3 deletions resolvers/.eslintrc.yml

This file was deleted.

3 changes: 0 additions & 3 deletions src/.eslintrc.yml

This file was deleted.

2 changes: 1 addition & 1 deletion src/rules/default.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = {
function checkDefault(specifierType, node) {

const defaultSpecifier = node.specifiers.find(
specifier => specifier.type === specifierType
specifier => specifier.type === specifierType,
);

if (!defaultSpecifier) return;
Expand Down
6 changes: 3 additions & 3 deletions src/rules/export.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ module.exports = {
'ExportSpecifier': (node) => addNamed(
node.exported.name,
node.exported,
getParent(node.parent)
getParent(node.parent),
),

'ExportNamedDeclaration': function (node) {
Expand Down Expand Up @@ -146,7 +146,7 @@ module.exports = {
if (!any) {
context.report(
node.source,
`No named exports found in module '${node.source.value}'.`
`No named exports found in module '${node.source.value}'.`,
);
}
},
Expand All @@ -164,7 +164,7 @@ module.exports = {
} else {
context.report(
node,
`Multiple exports of name '${name.replace(tsTypePrefix, '')}'.`
`Multiple exports of name '${name.replace(tsTypePrefix, '')}'.`,
);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/rules/first.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ module.exports = {
const range = [0, removeFixers[removeFixers.length - 1].range[1]];
let insertSourceCode = sortNodes.map(function (_errorInfo) {
const nodeSourceCode = String.prototype.slice.apply(
originSourceCode, _errorInfo.range
originSourceCode, _errorInfo.range,
);
if (/\S/.test(nodeSourceCode[0])) {
return '\n' + nodeSourceCode;
Expand All @@ -124,7 +124,7 @@ module.exports = {
const fixers = [insertFixer].concat(removeFixers);
fixers.forEach(function (computedFixer, i) {
replaceSourceCode += (originSourceCode.slice(
fixers[i - 1] ? fixers[i - 1].range[1] : 0, computedFixer.range[0]
fixers[i - 1] ? fixers[i - 1].range[1] : 0, computedFixer.range[0],
) + computedFixer.text);
});
return fixer.replaceTextRange(range, replaceSourceCode);
Expand Down
2 changes: 1 addition & 1 deletion src/rules/newline-after-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ module.exports = {
after ${type} statement not followed by another ${type}.`,
fix: fixer => fixer.insertTextAfter(
node,
'\n'.repeat(EXPECTED_LINE_DIFFERENCE - lineDifference)
'\n'.repeat(EXPECTED_LINE_DIFFERENCE - lineDifference),
),
});
}
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-cycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ module.exports = {
name,
context.settings,
resolve(name, context),
context
context,
);

function checkSourceValue(sourceNode, importer) {
Expand Down Expand Up @@ -88,7 +88,7 @@ module.exports = {
const toTraverse = [...declarations].filter(({ source, isOnlyImportingTypes }) =>
!ignoreModule(source.value) &&
// Ignore only type imports
!isOnlyImportingTypes
!isOnlyImportingTypes,
);
/*
Only report as a cycle if there are any import declarations that are considered by
Expand Down
8 changes: 4 additions & 4 deletions src/rules/no-duplicates.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function getFix(first, rest, sourceCode) {
}

const defaultImportNames = new Set(
[first, ...rest].map(getDefaultImportName).filter(Boolean)
[first, ...rest].map(getDefaultImportName).filter(Boolean),
);

// Bail if there are multiple different default import names – it's up to the
Expand Down Expand Up @@ -83,7 +83,7 @@ function getFix(first, rest, sourceCode) {
const unnecessaryImports = restWithoutComments.filter(node =>
!hasSpecifiers(node) &&
!hasNamespace(node) &&
!specifiers.some(specifier => specifier.importNode === node)
!specifiers.some(specifier => specifier.importNode === node),
);

const shouldAddDefault = getDefaultImportName(first) == null && defaultImportNames.size === 1;
Expand Down Expand Up @@ -115,15 +115,15 @@ function getFix(first, rest, sourceCode) {
specifier.isEmpty ? needsComma : true,
];
},
['', !firstHasTrailingComma && !firstIsEmpty]
['', !firstHasTrailingComma && !firstIsEmpty],
);

const fixes = [];

if (shouldAddDefault && openBrace == null && shouldAddSpecifiers) {
// `import './foo'` → `import def, {...} from './foo'`
fixes.push(
fixer.insertTextAfter(firstToken, ` ${defaultImportName}, {${specifiersText}} from`)
fixer.insertTextAfter(firstToken, ` ${defaultImportName}, {${specifiersText}} from`),
);
} else if (shouldAddDefault && openBrace == null && !shouldAddSpecifiers) {
// `import './foo'` → `import def from './foo'`
Expand Down
8 changes: 4 additions & 4 deletions src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,22 +55,22 @@ function getDependencies(context, packageDir) {
const packageJsonPath = path.join(dir, 'package.json');
if (!depFieldCache.has(packageJsonPath)) {
const depFields = extractDepFields(
JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')),
);
depFieldCache.set(packageJsonPath, depFields);
}
const _packageContent = depFieldCache.get(packageJsonPath);
Object.keys(packageContent).forEach(depsKey =>
Object.assign(packageContent[depsKey], _packageContent[depsKey])
Object.assign(packageContent[depsKey], _packageContent[depsKey]),
);
});
} else {
// use closest package.json
Object.assign(
packageContent,
extractDepFields(
readPkgUp({ cwd: context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(), normalize: false }).pkg
)
readPkgUp({ cwd: context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(), normalize: false }).pkg,
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-namespace.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ module.exports = {
const importLocalNames = generateLocalNames(
importNames,
importNameConflicts,
namespaceVariable.name
namespaceVariable.name,
);

// Replace the ImportNamespaceSpecifier with a list of ImportSpecifiers
Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-relative-packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ function checkImportForRelativePackage(context, importPath, node) {
const properImport = path.join(
importPkg.pkg.name,
path.dirname(properPath),
importBaseName === path.basename(importRoot) ? '' : importBaseName
importBaseName === path.basename(importRoot) ? '' : importBaseName,
);
context.report({
node,
Expand Down
4 changes: 2 additions & 2 deletions src/rules/no-unresolved.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ module.exports = {
if (resolvedPath === undefined) {
context.report(
source,
`Unable to resolve path to module '${source.value}'.`
`Unable to resolve path to module '${source.value}'.`,
);
} else if (caseSensitive || caseSensitiveStrict) {
const cacheSettings = ModuleCache.getSettings(context.settings);
if (!fileExistsWithCaseSync(resolvedPath, cacheSettings, caseSensitiveStrict)) {
context.report(
source,
`Casing of ${source.value} does not match the underlying filesystem.`
`Casing of ${source.value} does not match the underlying filesystem.`,
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/rules/no-unused-modules.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ const prepareImportsAndExports = (srcFiles, context) => {
}
const localImport = imports.get(key) || new Set();
value.declarations.forEach(({ importedSpecifiers }) =>
importedSpecifiers.forEach(specifier => localImport.add(specifier))
importedSpecifiers.forEach(specifier => localImport.add(specifier)),
);
imports.set(key, localImport);
});
Expand Down Expand Up @@ -564,13 +564,13 @@ module.exports = {
if (exportStatement.whereUsed.size < 1) {
context.report(
node,
`exported declaration '${value}' not used within other modules`
`exported declaration '${value}' not used within other modules`,
);
}
} else {
context.report(
node,
`exported declaration '${value}' not used within other modules`
`exported declaration '${value}' not used within other modules`,
);
}
};
Expand Down
6 changes: 3 additions & 3 deletions src/rules/no-useless-path-segments.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ module.exports = {

const fileExtensions = getFileExtensions(context.settings);
const regexUnnecessaryIndex = new RegExp(
`.*\\/index(\\${Array.from(fileExtensions).join('|\\')})?$`
`.*\\/index(\\${Array.from(fileExtensions).join('|\\')})?$`,
);

// Check if path contains unnecessary index (including a configured extension)
Expand Down Expand Up @@ -135,8 +135,8 @@ module.exports = {
importPathSplit
.slice(0, countExpectedRelativeParents)
.concat(importPathSplit.slice(countImportPathRelativeParents + diff))
.join('/')
)
.join('/'),
),
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/rules/no-webpack-loader-syntax.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import docsUrl from '../docsUrl';
function reportIfNonStandard(context, node, name) {
if (name && name.indexOf('!') !== -1) {
context.report(node, `Unexpected '!' in '${name}'. ` +
'Do not use import syntax to configure webpack loaders.'
'Do not use import syntax to configure webpack loaders.',
);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ function fixOutOfOrder(context, firstNode, secondNode, order) {
fix: canFix && (fixer =>
fixer.replaceTextRange(
[firstRootStart, secondRootEnd],
newCode + sourceCode.text.substring(firstRootStart, secondRootStart)
newCode + sourceCode.text.substring(firstRootStart, secondRootStart),
)),
});
} else if (order === 'after') {
Expand All @@ -210,7 +210,7 @@ function fixOutOfOrder(context, firstNode, secondNode, order) {
fix: canFix && (fixer =>
fixer.replaceTextRange(
[secondRootStart, firstRootEnd],
sourceCode.text.substring(secondRootEnd, firstRootEnd) + newCode
sourceCode.text.substring(secondRootEnd, firstRootEnd) + newCode,
)),
});
}
Expand Down Expand Up @@ -463,7 +463,7 @@ function makeNewlinesBetweenReport(context, imported, newlinesBetweenImports) {
const getNumberOfEmptyLinesBetween = (currentImport, previousImport) => {
const linesBetweenImports = context.getSourceCode().lines.slice(
previousImport.node.loc.end.line,
currentImport.node.loc.start.line - 1
currentImport.node.loc.start.line - 1,
);

return linesBetweenImports.filter((line) => !line.trim().length).length;
Expand Down Expand Up @@ -631,7 +631,7 @@ module.exports = {
},
ranks,
getBlockImports(node.parent),
pathGroupsExcludedImportTypes
pathGroupsExcludedImportTypes,
);
}
},
Expand Down Expand Up @@ -662,7 +662,7 @@ module.exports = {
},
ranks,
getBlockImports(node.parent),
pathGroupsExcludedImportTypes
pathGroupsExcludedImportTypes,
);
},
CallExpression: function handleRequires(node) {
Expand All @@ -684,7 +684,7 @@ module.exports = {
},
ranks,
getBlockImports(block),
pathGroupsExcludedImportTypes
pathGroupsExcludedImportTypes,
);
},
'Program:exit': function reportAndReset() {
Expand Down
15 changes: 0 additions & 15 deletions utils/.eslintrc

This file was deleted.

0 comments on commit cdcc76a

Please sign in to comment.