Skip to content

Commit cdcc76a

Browse files
committedNov 9, 2021
[eslint] consolidate configs
1 parent 332d3c8 commit cdcc76a

18 files changed

+71
-65
lines changed
 

‎.eslintrc

+37-10
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,31 @@
1818
"ecmaVersion": 2020,
1919
},
2020
"rules": {
21-
"comma-dangle": [2, "always-multiline"],
21+
"comma-dangle": ["error", {
22+
"arrays": "always-multiline",
23+
"objects": "always-multiline",
24+
"imports": "always-multiline",
25+
"exports": "always-multiline",
26+
"functions": "always-multiline",
27+
}],
2228
"comma-style": [2, "last"],
2329
"curly": [2, "multi-line"],
2430
"eol-last": [2, "always"],
2531
"eqeqeq": [2, "allow-null"],
2632
"func-call-spacing": 2,
2733
"indent": [2, 2],
2834
"keyword-spacing": ["error", {
29-
before: true,
30-
after: true,
31-
overrides: {
32-
return: { after: true },
33-
throw: { after: true },
34-
case: { after: true }
35+
"before": true,
36+
"after": true,
37+
"overrides": {
38+
"return": { "after": true },
39+
"throw": { "after": true },
40+
"case": { "after": true }
3541
}
3642
}],
37-
"max-len": [1, 99, 2],
43+
"max-len": 0,
3844
"no-cond-assign": [2, "always"],
3945
"no-return-assign": [2, "always"],
40-
"no-shadow": 1,
4146
"no-var": 2,
4247
"object-curly-spacing": [2, "always"],
4348
"object-shorthand": ["error", "always", {
@@ -91,6 +96,12 @@
9196
"no-console": "off",
9297
},
9398
},
99+
{
100+
"files": "resolvers/**",
101+
"env": {
102+
"es6": false,
103+
},
104+
},
94105
{
95106
"files": [
96107
"resolvers/*/test/**/*",
@@ -99,6 +110,22 @@
99110
"mocha": true,
100111
"es6": false
101112
},
102-
}
113+
},
114+
{
115+
"files": "utils/**",
116+
"parserOptions": {
117+
"ecmaVersion": 6,
118+
},
119+
"rules": {
120+
"comma-dangle": ["error", {
121+
"arrays": "always-multiline",
122+
"objects": "always-multiline",
123+
"imports": "always-multiline",
124+
"exports": "always-multiline",
125+
"functions": "never"
126+
}],
127+
"no-console": 1,
128+
},
129+
},
103130
],
104131
}

‎resolvers/.eslintrc.yml

-3
This file was deleted.

‎src/.eslintrc.yml

-3
This file was deleted.

‎src/rules/default.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = {
1515
function checkDefault(specifierType, node) {
1616

1717
const defaultSpecifier = node.specifiers.find(
18-
specifier => specifier.type === specifierType
18+
specifier => specifier.type === specifierType,
1919
);
2020

2121
if (!defaultSpecifier) return;

‎src/rules/export.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ module.exports = {
9090
'ExportSpecifier': (node) => addNamed(
9191
node.exported.name,
9292
node.exported,
93-
getParent(node.parent)
93+
getParent(node.parent),
9494
),
9595

9696
'ExportNamedDeclaration': function (node) {
@@ -146,7 +146,7 @@ module.exports = {
146146
if (!any) {
147147
context.report(
148148
node.source,
149-
`No named exports found in module '${node.source.value}'.`
149+
`No named exports found in module '${node.source.value}'.`,
150150
);
151151
}
152152
},
@@ -164,7 +164,7 @@ module.exports = {
164164
} else {
165165
context.report(
166166
node,
167-
`Multiple exports of name '${name.replace(tsTypePrefix, '')}'.`
167+
`Multiple exports of name '${name.replace(tsTypePrefix, '')}'.`,
168168
);
169169
}
170170
}

‎src/rules/first.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ module.exports = {
105105
const range = [0, removeFixers[removeFixers.length - 1].range[1]];
106106
let insertSourceCode = sortNodes.map(function (_errorInfo) {
107107
const nodeSourceCode = String.prototype.slice.apply(
108-
originSourceCode, _errorInfo.range
108+
originSourceCode, _errorInfo.range,
109109
);
110110
if (/\S/.test(nodeSourceCode[0])) {
111111
return '\n' + nodeSourceCode;
@@ -124,7 +124,7 @@ module.exports = {
124124
const fixers = [insertFixer].concat(removeFixers);
125125
fixers.forEach(function (computedFixer, i) {
126126
replaceSourceCode += (originSourceCode.slice(
127-
fixers[i - 1] ? fixers[i - 1].range[1] : 0, computedFixer.range[0]
127+
fixers[i - 1] ? fixers[i - 1].range[1] : 0, computedFixer.range[0],
128128
) + computedFixer.text);
129129
});
130130
return fixer.replaceTextRange(range, replaceSourceCode);

‎src/rules/newline-after-import.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ module.exports = {
107107
after ${type} statement not followed by another ${type}.`,
108108
fix: fixer => fixer.insertTextAfter(
109109
node,
110-
'\n'.repeat(EXPECTED_LINE_DIFFERENCE - lineDifference)
110+
'\n'.repeat(EXPECTED_LINE_DIFFERENCE - lineDifference),
111111
),
112112
});
113113
}

‎src/rules/no-cycle.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ module.exports = {
4646
name,
4747
context.settings,
4848
resolve(name, context),
49-
context
49+
context,
5050
);
5151

5252
function checkSourceValue(sourceNode, importer) {
@@ -88,7 +88,7 @@ module.exports = {
8888
const toTraverse = [...declarations].filter(({ source, isOnlyImportingTypes }) =>
8989
!ignoreModule(source.value) &&
9090
// Ignore only type imports
91-
!isOnlyImportingTypes
91+
!isOnlyImportingTypes,
9292
);
9393
/*
9494
Only report as a cycle if there are any import declarations that are considered by

‎src/rules/no-duplicates.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function getFix(first, rest, sourceCode) {
4545
}
4646

4747
const defaultImportNames = new Set(
48-
[first, ...rest].map(getDefaultImportName).filter(Boolean)
48+
[first, ...rest].map(getDefaultImportName).filter(Boolean),
4949
);
5050

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

8989
const shouldAddDefault = getDefaultImportName(first) == null && defaultImportNames.size === 1;
@@ -115,15 +115,15 @@ function getFix(first, rest, sourceCode) {
115115
specifier.isEmpty ? needsComma : true,
116116
];
117117
},
118-
['', !firstHasTrailingComma && !firstIsEmpty]
118+
['', !firstHasTrailingComma && !firstIsEmpty],
119119
);
120120

121121
const fixes = [];
122122

123123
if (shouldAddDefault && openBrace == null && shouldAddSpecifiers) {
124124
// `import './foo'` → `import def, {...} from './foo'`
125125
fixes.push(
126-
fixer.insertTextAfter(firstToken, ` ${defaultImportName}, {${specifiersText}} from`)
126+
fixer.insertTextAfter(firstToken, ` ${defaultImportName}, {${specifiersText}} from`),
127127
);
128128
} else if (shouldAddDefault && openBrace == null && !shouldAddSpecifiers) {
129129
// `import './foo'` → `import def from './foo'`

‎src/rules/no-extraneous-dependencies.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ function getDependencies(context, packageDir) {
5555
const packageJsonPath = path.join(dir, 'package.json');
5656
if (!depFieldCache.has(packageJsonPath)) {
5757
const depFields = extractDepFields(
58-
JSON.parse(fs.readFileSync(packageJsonPath, 'utf8'))
58+
JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')),
5959
);
6060
depFieldCache.set(packageJsonPath, depFields);
6161
}
6262
const _packageContent = depFieldCache.get(packageJsonPath);
6363
Object.keys(packageContent).forEach(depsKey =>
64-
Object.assign(packageContent[depsKey], _packageContent[depsKey])
64+
Object.assign(packageContent[depsKey], _packageContent[depsKey]),
6565
);
6666
});
6767
} else {
6868
// use closest package.json
6969
Object.assign(
7070
packageContent,
7171
extractDepFields(
72-
readPkgUp({ cwd: context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(), normalize: false }).pkg
73-
)
72+
readPkgUp({ cwd: context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(), normalize: false }).pkg,
73+
),
7474
);
7575
}
7676

‎src/rules/no-namespace.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module.exports = {
7676
const importLocalNames = generateLocalNames(
7777
importNames,
7878
importNameConflicts,
79-
namespaceVariable.name
79+
namespaceVariable.name,
8080
);
8181

8282
// Replace the ImportNamespaceSpecifier with a list of ImportSpecifiers

‎src/rules/no-relative-packages.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ function checkImportForRelativePackage(context, importPath, node) {
3737
const properImport = path.join(
3838
importPkg.pkg.name,
3939
path.dirname(properPath),
40-
importBaseName === path.basename(importRoot) ? '' : importBaseName
40+
importBaseName === path.basename(importRoot) ? '' : importBaseName,
4141
);
4242
context.report({
4343
node,

‎src/rules/no-unresolved.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ module.exports = {
4040
if (resolvedPath === undefined) {
4141
context.report(
4242
source,
43-
`Unable to resolve path to module '${source.value}'.`
43+
`Unable to resolve path to module '${source.value}'.`,
4444
);
4545
} else if (caseSensitive || caseSensitiveStrict) {
4646
const cacheSettings = ModuleCache.getSettings(context.settings);
4747
if (!fileExistsWithCaseSync(resolvedPath, cacheSettings, caseSensitiveStrict)) {
4848
context.report(
4949
source,
50-
`Casing of ${source.value} does not match the underlying filesystem.`
50+
`Casing of ${source.value} does not match the underlying filesystem.`,
5151
);
5252
}
5353
}

‎src/rules/no-unused-modules.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ const prepareImportsAndExports = (srcFiles, context) => {
248248
}
249249
const localImport = imports.get(key) || new Set();
250250
value.declarations.forEach(({ importedSpecifiers }) =>
251-
importedSpecifiers.forEach(specifier => localImport.add(specifier))
251+
importedSpecifiers.forEach(specifier => localImport.add(specifier)),
252252
);
253253
imports.set(key, localImport);
254254
});
@@ -564,13 +564,13 @@ module.exports = {
564564
if (exportStatement.whereUsed.size < 1) {
565565
context.report(
566566
node,
567-
`exported declaration '${value}' not used within other modules`
567+
`exported declaration '${value}' not used within other modules`,
568568
);
569569
}
570570
} else {
571571
context.report(
572572
node,
573-
`exported declaration '${value}' not used within other modules`
573+
`exported declaration '${value}' not used within other modules`,
574574
);
575575
}
576576
};

‎src/rules/no-useless-path-segments.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ module.exports = {
8888

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

9494
// Check if path contains unnecessary index (including a configured extension)
@@ -135,8 +135,8 @@ module.exports = {
135135
importPathSplit
136136
.slice(0, countExpectedRelativeParents)
137137
.concat(importPathSplit.slice(countImportPathRelativeParents + diff))
138-
.join('/')
139-
)
138+
.join('/'),
139+
),
140140
);
141141
}
142142

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import docsUrl from '../docsUrl';
44
function reportIfNonStandard(context, node, name) {
55
if (name && name.indexOf('!') !== -1) {
66
context.report(node, `Unexpected '!' in '${name}'. ` +
7-
'Do not use import syntax to configure webpack loaders.'
7+
'Do not use import syntax to configure webpack loaders.',
88
);
99
}
1010
}

‎src/rules/order.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ function fixOutOfOrder(context, firstNode, secondNode, order) {
200200
fix: canFix && (fixer =>
201201
fixer.replaceTextRange(
202202
[firstRootStart, secondRootEnd],
203-
newCode + sourceCode.text.substring(firstRootStart, secondRootStart)
203+
newCode + sourceCode.text.substring(firstRootStart, secondRootStart),
204204
)),
205205
});
206206
} else if (order === 'after') {
@@ -210,7 +210,7 @@ function fixOutOfOrder(context, firstNode, secondNode, order) {
210210
fix: canFix && (fixer =>
211211
fixer.replaceTextRange(
212212
[secondRootStart, firstRootEnd],
213-
sourceCode.text.substring(secondRootEnd, firstRootEnd) + newCode
213+
sourceCode.text.substring(secondRootEnd, firstRootEnd) + newCode,
214214
)),
215215
});
216216
}
@@ -463,7 +463,7 @@ function makeNewlinesBetweenReport(context, imported, newlinesBetweenImports) {
463463
const getNumberOfEmptyLinesBetween = (currentImport, previousImport) => {
464464
const linesBetweenImports = context.getSourceCode().lines.slice(
465465
previousImport.node.loc.end.line,
466-
currentImport.node.loc.start.line - 1
466+
currentImport.node.loc.start.line - 1,
467467
);
468468

469469
return linesBetweenImports.filter((line) => !line.trim().length).length;
@@ -631,7 +631,7 @@ module.exports = {
631631
},
632632
ranks,
633633
getBlockImports(node.parent),
634-
pathGroupsExcludedImportTypes
634+
pathGroupsExcludedImportTypes,
635635
);
636636
}
637637
},
@@ -662,7 +662,7 @@ module.exports = {
662662
},
663663
ranks,
664664
getBlockImports(node.parent),
665-
pathGroupsExcludedImportTypes
665+
pathGroupsExcludedImportTypes,
666666
);
667667
},
668668
CallExpression: function handleRequires(node) {
@@ -684,7 +684,7 @@ module.exports = {
684684
},
685685
ranks,
686686
getBlockImports(block),
687-
pathGroupsExcludedImportTypes
687+
pathGroupsExcludedImportTypes,
688688
);
689689
},
690690
'Program:exit': function reportAndReset() {

‎utils/.eslintrc

-15
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.