diff --git a/lib/eslint.js b/lib/eslint.js index 9903e8a..9abc496 100644 --- a/lib/eslint.js +++ b/lib/eslint.js @@ -1,40 +1,25 @@ -const CLIEngine = require("eslint").CLIEngine; const ESLint = require("eslint").ESLint; const chalk = require("chalk"); const EsplintError = require("./EsplintError"); const { merge } = require("lodash"); function creatEslintInstance(eslintConfig) { - if (ESLint) { - const eslint = new ESLint(eslintConfig); - return { - runLint: (files) => newRunLint(eslint, files), - getConfigForFile: (file) => newGetConfigForFile(eslint, file), - }; - } - - const cli = new CLIEngine(eslintConfig); + const eslint = new ESLint(eslintConfig); return { - runLint: (files) => runLint(cli, files), - getConfigForFile: (file) => getConfigForFile(cli, file), + runLint: (files) => runLint(eslint, files), + getConfigForFile: (file) => getConfigForFile(eslint, file), }; } function overrideRulesConfig(config, rules) { - if (ESLint) { - return merge({}, config.eslint, { - overrideConfig: { - rules, - }, - }); - } else { - return merge({}, config.eslint, { + return merge({}, config.eslint, { + overrideConfig: { rules, - }); - } + }, + }); } -async function newRunLint(eslint, files) { +async function runLint(eslint, files) { const results = await eslint.lintFiles(files); const errorResults = ESLint.getErrorResults(results); const hasErrors = Boolean(errorResults.length); @@ -49,29 +34,10 @@ async function newRunLint(eslint, files) { return results; } -async function runLint(eslintCli, files) { - const report = eslintCli.executeOnFiles(files); - const errorReport = CLIEngine.getErrorResults(report.results); - const hasErrors = Boolean(errorReport.length); - if (hasErrors) { - const formatter = eslintCli.getFormatter(); - throw new EsplintError( - `There were some ESLint errors. Fix them and try again.\n${chalk.reset( - formatter(errorReport) - )}` - ); - } - return report.results; -} - -function newGetConfigForFile(eslint, file) { +function getConfigForFile(eslint, file) { return eslint.calculateConfigForFile(file); } -async function getConfigForFile(cli, file) { - return cli.getConfigForFile(file); -} - function getWarningRules({ rules }) { return Object.keys(rules).filter((name) => { const ruleConfig = rules[name]; diff --git a/package.json b/package.json index 77218ac..fa226df 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ "strip-ansi": "^6.0.0" }, "peerDependencies": { - "eslint": ">=4.19.1" + "eslint": ">=7.0.0" }, "dependencies": { "chalk": "^4.0.0",