diff --git a/rules/no-unnecessary-await.js b/rules/no-unnecessary-await.js index cf06620366..94e6789e34 100644 --- a/rules/no-unnecessary-await.js +++ b/rules/no-unnecessary-await.js @@ -25,10 +25,14 @@ function notPromise(node) { case 'Literal': case 'TemplateLiteral': case 'UnaryExpression': - case 'UpdateExpression': + case 'UpdateExpression': { return true; - case 'SequenceExpression': + } + + case 'SequenceExpression': { return notPromise(node.expressions[node.expressions.length - 1]); + } + // No default } diff --git a/test/run-rules-on-codebase/lint.mjs b/test/run-rules-on-codebase/lint.mjs index 974363ef66..250db662d3 100644 --- a/test/run-rules-on-codebase/lint.mjs +++ b/test/run-rules-on-codebase/lint.mjs @@ -1,9 +1,13 @@ #!/usr/bin/env node import process from 'node:process'; import {parseArgs} from 'node:util'; -import {ESLint} from 'eslint'; -import unicorn from '../../index.js'; -import allConfig from '../../configs/all.js'; +// eslint-disable-next-line n/file-extension-in-import -- https://github.com/eslint-community/eslint-plugin-n/issues/50 +import eslintExperimentalApis from 'eslint/use-at-your-own-risk'; +import chalk from 'chalk'; +import {outdent} from 'outdent'; +import eslintPluginUnicorn from '../../index.js'; + +const {FlatESLint} = eslintExperimentalApis; const { values: { @@ -19,20 +23,24 @@ const { allowPositionals: true, }); -const eslint = new ESLint({ - baseConfig: allConfig, - useEslintrc: false, - extensions: ['.js', '.mjs'], - plugins: { - unicorn, +const configs = [ + // TODO: Use `eslintPluginUnicorn.configs.all` instead when we change preset to flat config + { + plugins: { + unicorn: eslintPluginUnicorn, + }, + rules: eslintPluginUnicorn.configs.all.rules, }, - fix, - overrideConfig: { - ignorePatterns: [ + { + ignores: [ 'coverage', 'test/integration/fixtures', 'test/integration/fixtures-local', + // Ignore this file self temporarily, disabling `n/file-extension-in-import` comment cause error + 'test/run-rules-on-codebase/lint.mjs', ], + }, + { rules: { // https://github.com/sindresorhus/eslint-plugin-unicorn/issues/1109#issuecomment-782689255 'unicorn/consistent-destructuring': 'off', @@ -46,27 +54,31 @@ const eslint = new ESLint({ 'unicorn/prefer-string-replace-all': 'off', 'unicorn/prefer-at': 'off', }, - overrides: [ - { - files: [ - '**/*.js', - ], - rules: { - 'unicorn/prefer-module': 'off', - }, - }, + }, + { + files: [ + '**/*.js', ], + rules: { + 'unicorn/prefer-module': 'off', + }, }, -}); +]; const sum = (collection, fieldName) => collection.reduce((total, {[fieldName]: value}) => total + value, 0); async function run() { - const results = await eslint.lintFiles(patterns); + const eslint = new FlatESLint({ + overrideConfigFile: true, + overrideConfig: configs, + fix, + }); + + const results = await eslint.lintFiles(patterns.length === 0 ? ['.'] : patterns); if (fix) { - await ESLint.outputFixes(results); + await FlatESLint.outputFixes(results); } const errorCount = sum(results, 'errorCount'); @@ -75,22 +87,34 @@ async function run() { const fixableWarningCount = sum(results, 'fixableWarningCount'); const hasFixable = fixableErrorCount || fixableWarningCount; + const summary = outdent` + ${results.length} files linted: + - error: ${chalk.gray(errorCount)} + - warning: ${chalk.gray(warningCount)} + - fixable error: ${chalk.gray(fixableErrorCount)} + - fixable warning: ${chalk.gray(fixableWarningCount)} + `; if (errorCount || warningCount) { + console.log('*! If you\'re making a new rule, you can ignore this before review. !*'); + + console.log(); + console.log(summary); + const {format} = await eslint.loadFormatter(); + console.log(); console.log(format(results)); console.log(); - console.log(`You need to fix the failed test${errorCount + warningCount > 1 ? 's' : ''} above and run \`npm run run-rules-on-codebase \` to check again.`); + console.log(`You need to fix the failed test${errorCount + warningCount > 1 ? 's' : ''} above and run \`npm run run-rules-on-codebase -- \` to check again.`); if (hasFixable) { console.log(); - console.log('You may also want run `npm run run-rules-on-codebase --fix` to fix fixable problems.'); + console.log('You may also want run `npm run run-rules-on-codebase -- --fix` to fix fixable problems.'); } - - console.log(); - console.log('* If you\'re making a new rule, you can fix this later. *'); } else { + console.log(summary); + console.log(); console.log('All tests have passed.'); }