diff --git a/.eslintrc b/.eslintrc index 4064c571d..12fb8b7a2 100644 --- a/.eslintrc +++ b/.eslintrc @@ -18,7 +18,13 @@ "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"], @@ -26,18 +32,17 @@ "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", { @@ -91,6 +96,12 @@ "no-console": "off", }, }, + { + "files": "resolvers/**", + "env": { + "es6": false, + }, + }, { "files": [ "resolvers/*/test/**/*", @@ -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, + }, + }, ], } diff --git a/resolvers/.eslintrc.yml b/resolvers/.eslintrc.yml deleted file mode 100644 index 9db33eda4..000000000 --- a/resolvers/.eslintrc.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -env: - es6: false diff --git a/src/.eslintrc.yml b/src/.eslintrc.yml deleted file mode 100644 index 340d66bf6..000000000 --- a/src/.eslintrc.yml +++ /dev/null @@ -1,3 +0,0 @@ ---- -rules: - comma-dangle: [1, "always-multiline"] diff --git a/src/rules/default.js b/src/rules/default.js index b8277b452..6b917ccae 100644 --- a/src/rules/default.js +++ b/src/rules/default.js @@ -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; diff --git a/src/rules/export.js b/src/rules/export.js index be75fa07f..e0b2c5785 100644 --- a/src/rules/export.js +++ b/src/rules/export.js @@ -90,7 +90,7 @@ module.exports = { 'ExportSpecifier': (node) => addNamed( node.exported.name, node.exported, - getParent(node.parent) + getParent(node.parent), ), 'ExportNamedDeclaration': function (node) { @@ -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}'.`, ); } }, @@ -164,7 +164,7 @@ module.exports = { } else { context.report( node, - `Multiple exports of name '${name.replace(tsTypePrefix, '')}'.` + `Multiple exports of name '${name.replace(tsTypePrefix, '')}'.`, ); } } diff --git a/src/rules/first.js b/src/rules/first.js index eb613d330..087b840cb 100644 --- a/src/rules/first.js +++ b/src/rules/first.js @@ -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; @@ -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); diff --git a/src/rules/newline-after-import.js b/src/rules/newline-after-import.js index 1b946b35a..a3e0a11e1 100644 --- a/src/rules/newline-after-import.js +++ b/src/rules/newline-after-import.js @@ -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), ), }); } diff --git a/src/rules/no-cycle.js b/src/rules/no-cycle.js index dda5a679d..cefa41f99 100644 --- a/src/rules/no-cycle.js +++ b/src/rules/no-cycle.js @@ -46,7 +46,7 @@ module.exports = { name, context.settings, resolve(name, context), - context + context, ); function checkSourceValue(sourceNode, importer) { @@ -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 diff --git a/src/rules/no-duplicates.js b/src/rules/no-duplicates.js index c887b39e7..43c2c5b20 100644 --- a/src/rules/no-duplicates.js +++ b/src/rules/no-duplicates.js @@ -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 @@ -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; @@ -115,7 +115,7 @@ function getFix(first, rest, sourceCode) { specifier.isEmpty ? needsComma : true, ]; }, - ['', !firstHasTrailingComma && !firstIsEmpty] + ['', !firstHasTrailingComma && !firstIsEmpty], ); const fixes = []; @@ -123,7 +123,7 @@ function getFix(first, rest, sourceCode) { 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'` diff --git a/src/rules/no-extraneous-dependencies.js b/src/rules/no-extraneous-dependencies.js index 25a91aef5..b54ee28bb 100644 --- a/src/rules/no-extraneous-dependencies.js +++ b/src/rules/no-extraneous-dependencies.js @@ -55,13 +55,13 @@ 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 { @@ -69,8 +69,8 @@ function getDependencies(context, packageDir) { 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, + ), ); } diff --git a/src/rules/no-namespace.js b/src/rules/no-namespace.js index fb3d76052..c615dfff5 100644 --- a/src/rules/no-namespace.js +++ b/src/rules/no-namespace.js @@ -76,7 +76,7 @@ module.exports = { const importLocalNames = generateLocalNames( importNames, importNameConflicts, - namespaceVariable.name + namespaceVariable.name, ); // Replace the ImportNamespaceSpecifier with a list of ImportSpecifiers diff --git a/src/rules/no-relative-packages.js b/src/rules/no-relative-packages.js index 714eb3f5e..17406e80e 100644 --- a/src/rules/no-relative-packages.js +++ b/src/rules/no-relative-packages.js @@ -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, diff --git a/src/rules/no-unresolved.js b/src/rules/no-unresolved.js index 549101897..b9dae97c8 100644 --- a/src/rules/no-unresolved.js +++ b/src/rules/no-unresolved.js @@ -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.`, ); } } diff --git a/src/rules/no-unused-modules.js b/src/rules/no-unused-modules.js index 068eb911c..9891d4097 100644 --- a/src/rules/no-unused-modules.js +++ b/src/rules/no-unused-modules.js @@ -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); }); @@ -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`, ); } }; diff --git a/src/rules/no-useless-path-segments.js b/src/rules/no-useless-path-segments.js index a05860802..c0156d09f 100644 --- a/src/rules/no-useless-path-segments.js +++ b/src/rules/no-useless-path-segments.js @@ -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) @@ -135,8 +135,8 @@ module.exports = { importPathSplit .slice(0, countExpectedRelativeParents) .concat(importPathSplit.slice(countImportPathRelativeParents + diff)) - .join('/') - ) + .join('/'), + ), ); } diff --git a/src/rules/no-webpack-loader-syntax.js b/src/rules/no-webpack-loader-syntax.js index 2f49ad6c6..e517207ba 100644 --- a/src/rules/no-webpack-loader-syntax.js +++ b/src/rules/no-webpack-loader-syntax.js @@ -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.', ); } } diff --git a/src/rules/order.js b/src/rules/order.js index 194a3fd53..fce979f09 100644 --- a/src/rules/order.js +++ b/src/rules/order.js @@ -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') { @@ -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, )), }); } @@ -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; @@ -631,7 +631,7 @@ module.exports = { }, ranks, getBlockImports(node.parent), - pathGroupsExcludedImportTypes + pathGroupsExcludedImportTypes, ); } }, @@ -662,7 +662,7 @@ module.exports = { }, ranks, getBlockImports(node.parent), - pathGroupsExcludedImportTypes + pathGroupsExcludedImportTypes, ); }, CallExpression: function handleRequires(node) { @@ -684,7 +684,7 @@ module.exports = { }, ranks, getBlockImports(block), - pathGroupsExcludedImportTypes + pathGroupsExcludedImportTypes, ); }, 'Program:exit': function reportAndReset() { diff --git a/utils/.eslintrc b/utils/.eslintrc deleted file mode 100644 index fa000aa72..000000000 --- a/utils/.eslintrc +++ /dev/null @@ -1,15 +0,0 @@ -{ - "parserOptions": { - "ecmaVersion": 6, - }, - "rules": { - "comma-dangle": ["error", { - "arrays": "always-multiline", - "objects": "always-multiline", - "imports": "always-multiline", - "exports": "always-multiline", - "functions": "never" - }], - "no-console": 1, - } -}