diff --git a/test/lint/lint.js b/test/lint/lint.js index 1dca29d261..c7ba7a4d0f 100755 --- a/test/lint/lint.js +++ b/test/lint/lint.js @@ -1,62 +1,61 @@ #!/usr/bin/env node 'use strict'; -const {CLIEngine} = require('eslint'); +const {ESLint} = require('eslint'); const unicorn = require('../..'); const {recommended} = unicorn.configs; const files = [process.argv[2] || '.']; const fix = process.argv.includes('--fix'); -const ruleIds = Object.keys(unicorn.rules); -const unicornRules = new Map(Object.entries(unicorn.rules)); -const cli = new CLIEngine({ +const eslint = new ESLint({ baseConfig: recommended, useEslintrc: false, + plugins: { + unicorn + }, fix, - ignorePattern: [ - ] + overrideConfig: { + ignorePatterns: [ + 'coverage', + 'test/integration/fixtures' + ] + } }); -cli.addPlugin('eslint-plugin-unicorn', unicorn); - -// Make sure rules are loaded from codebase -const loadedRules = cli.getRules(); -if (!ruleIds.every(ruleId => unicornRules.get(ruleId) === loadedRules.get(`unicorn/${ruleId}`))) { - console.error('`eslint-plugin-unicorn` rules are not loaded from codebase.'); - process.exit(1); -} +(async function () { + const results = await eslint.lintFiles(files); -const report = cli.executeOnFiles(files); + if (fix) { + await ESLint.outputFixes(results); + } -const { - errorCount, - warningCount, - fixableErrorCount, - fixableWarningCount -} = report; + const errorCount = results.reduce((total, {errorCount}) => total + errorCount, 0); + const warningCount = results.reduce((total, {warningCount}) => total + warningCount, 0); + const fixableErrorCount = results.reduce((total, {fixableErrorCount}) => total + fixableErrorCount, 0); + const fixableWarningCount = results.reduce((total, {fixableWarningCount}) => total + fixableWarningCount, 0); -const hasFixable = fixableErrorCount || fixableWarningCount; + const hasFixable = fixableErrorCount || fixableWarningCount; -if (fix) { - CLIEngine.outputFixes(report); -} + if (errorCount || warningCount) { + const {format} = await eslint.loadFormatter(); + console.log(format(results)); -if (errorCount || warningCount) { - const formatter = cli.getFormatter(); - console.log(formatter(report.results)); + console.log(); + console.log(`You need to fix the failed test${errorCount + warningCount > 1 ? 's' : ''} above and run \`npm run lint \` to check again.`); - console.log(); - console.log(`You need to fix the failed test${errorCount + warningCount > 1 ? 's' : ''} above and run \`npm run lint \` to check again.`); + if (hasFixable) { + console.log(); + console.log('You may also want run `npm run lint --fix` to fix fixable problems.'); + } - if (hasFixable) { console.log(); - console.log('You may also want run `npm run lint --fix` to fix fixable problems.'); + console.log('* If you\'re making a new rule, you can fix this later. *'); + } else { + console.log('All tests have passed.'); } - console.log(); - console.log('* If you\'re making a new rule, you can fix this later. *'); -} else { - console.log('All tests have passed.'); -} - -process.exit(errorCount); + process.exit(errorCount); +})().catch(error => { + process.exitCode = 1; + console.error(error); +});