diff --git a/src/rules/no-default-export.js b/src/rules/no-default-export.js index 6e5a53748..dabbae543 100644 --- a/src/rules/no-default-export.js +++ b/src/rules/no-default-export.js @@ -27,14 +27,16 @@ module.exports = { }, ExportNamedDeclaration(node) { - node.specifiers.filter((specifier) => (specifier.exported.name || specifier.exported.value) === 'default').forEach((specifier) => { - const { loc } = context.getSourceCode().getFirstTokens(node)[1] || {}; - if (specifier.type === 'ExportDefaultSpecifier') { - context.report({ node, message: preferNamed, loc }); - } else if (specifier.type === 'ExportSpecifier') { - context.report({ node, message: noAliasDefault(specifier), loc }); - } - }); + node.specifiers + .filter((specifier) => (specifier.exported.name || specifier.exported.value) === 'default') + .forEach((specifier) => { + const { loc } = context.getSourceCode().getFirstTokens(node)[1] || {}; + if (specifier.type === 'ExportDefaultSpecifier') { + context.report({ node, message: preferNamed, loc }); + } else if (specifier.type === 'ExportSpecifier') { + context.report({ node, message: noAliasDefault(specifier), loc }); + } + }); }, }; }, diff --git a/src/rules/no-duplicates.js b/src/rules/no-duplicates.js index 2373202cb..6b4f4d559 100644 --- a/src/rules/no-duplicates.js +++ b/src/rules/no-duplicates.js @@ -1,6 +1,8 @@ import resolve from 'eslint-module-utils/resolve'; -import docsUrl from '../docsUrl'; import semver from 'semver'; +import flatMap from 'array.prototype.flatmap'; + +import docsUrl from '../docsUrl'; let typescriptPkg; try { @@ -51,7 +53,7 @@ function getFix(first, rest, sourceCode, context) { } const defaultImportNames = new Set( - [first, ...rest].map(getDefaultImportName).filter(Boolean), + flatMap([].concat(first, rest || []), (x) => getDefaultImportName(x) || []), ); // Bail if there are multiple different default import names – it's up to the @@ -62,10 +64,7 @@ function getFix(first, rest, sourceCode, context) { // Leave it to the user to handle comments. Also skip `import * as ns from // './foo'` imports, since they cannot be merged into another import. - const restWithoutComments = rest.filter((node) => !( - hasProblematicComments(node, sourceCode) - || hasNamespace(node) - )); + const restWithoutComments = rest.filter((node) => !hasProblematicComments(node, sourceCode) && !hasNamespace(node)); const specifiers = restWithoutComments .map((node) => { diff --git a/src/rules/no-restricted-paths.js b/src/rules/no-restricted-paths.js index bce9fd1a0..cd680a194 100644 --- a/src/rules/no-restricted-paths.js +++ b/src/rules/no-restricted-paths.js @@ -77,9 +77,11 @@ module.exports = { const restrictedPaths = options.zones || []; const basePath = options.basePath || process.cwd(); const currentFilename = context.getPhysicalFilename ? context.getPhysicalFilename() : context.getFilename(); - const matchingZones = restrictedPaths.filter((zone) => [].concat(zone.target) - .map((target) => path.resolve(basePath, target)) - .some((targetPath) => isMatchingTargetPath(currentFilename, targetPath))); + const matchingZones = restrictedPaths.filter( + (zone) => [].concat(zone.target) + .map((target) => path.resolve(basePath, target)) + .some((targetPath) => isMatchingTargetPath(currentFilename, targetPath)), + ); function isMatchingTargetPath(filename, targetPath) { if (isGlob(targetPath)) { @@ -231,8 +233,7 @@ module.exports = { reportInvalidExceptions(validatorsWithInvalidExceptions, node); const applicableValidatorsForImportPathExcludingExceptions = applicableValidatorsForImportPath - .filter((validator) => validator.hasValidExceptions) - .filter((validator) => !validator.isPathException(absoluteImportPath)); + .filter((validator) => validator.hasValidExceptions && !validator.isPathException(absoluteImportPath)); reportImportsInRestrictedZone(applicableValidatorsForImportPathExcludingExceptions, node, importPath, zone.message); }); } diff --git a/src/rules/no-unused-modules.js b/src/rules/no-unused-modules.js index c8a20f8c0..ecba3a19c 100644 --- a/src/rules/no-unused-modules.js +++ b/src/rules/no-unused-modules.js @@ -177,7 +177,7 @@ const resolveFiles = (src, ignoreExports, context) => { // prepare list of source files, don't consider files from node_modules return new Set( - srcFileList.filter(({ filename }) => !isNodeModule(filename)).map(({ filename }) => filename), + flatMap(srcFileList, ({ filename }) => isNodeModule(filename) ? [] : filename), ); }; @@ -359,9 +359,7 @@ const fileIsInPkg = (file) => { }; const checkPkgFieldObject = (pkgField) => { - const pkgFieldFiles = values(pkgField) - .filter((value) => typeof value !== 'boolean') - .map((value) => join(basePath, value)); + const pkgFieldFiles = flatMap(values(pkgField), (value) => typeof value === 'boolean' ? [] : join(basePath, value)); if (includes(pkgFieldFiles, file)) { return true; diff --git a/tests/src/package.js b/tests/src/package.js index dd55e2740..08138084c 100644 --- a/tests/src/package.js +++ b/tests/src/package.js @@ -27,8 +27,7 @@ describe('package', function () { expect(err).not.to.exist; files.filter(isJSFile).forEach(function (f) { - expect(module.rules).to.have - .property(path.basename(f, '.js')); + expect(module.rules).to.have.property(path.basename(f, '.js')); }); done(); diff --git a/tests/src/rules/order.js b/tests/src/rules/order.js index db6aec4fc..2a44aa06a 100644 --- a/tests/src/rules/order.js +++ b/tests/src/rules/order.js @@ -2736,7 +2736,7 @@ ruleTester.run('order', rule, { }], }), ], - ].filter((t) => !!t), + ].filter(Boolean), }); context('TypeScript', function () {