Skip to content

Commit

Permalink
refactor: remove unneeded fallback code
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelDeBoey authored and ljharb committed Nov 8, 2021
1 parent e95f4ad commit 18248f6
Showing 1 changed file with 10 additions and 26 deletions.
36 changes: 10 additions & 26 deletions src/lib/rule-finder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');

const eslint = require('eslint');
const { ESLint, Linter } = require('eslint');
const glob = require('glob');
const difference = require('./array-diff');
const getSortedRules = require('./sort-rules');
Expand All @@ -17,32 +17,16 @@ function _getConfigFile(specifiedFile) {
return require(path.join(process.cwd(), 'package.json')).main;
}

async function _getConfigs(configFile, files) {
let isPathIgnored;
let getConfigForFile;

if (eslint.ESLint) {
const esLint = new eslint.ESLint({
// Ignore any config applicable depending on the location on the filesystem
useEslintrc: false,
// Point to the particular config
overrideConfigFile: configFile
});
isPathIgnored = esLint.isPathIgnored.bind(esLint);
getConfigForFile = esLint.calculateConfigForFile.bind(esLint);
} else {
const cliEngine = new eslint.CLIEngine({
// Ignore any config applicable depending on the location on the filesystem
useEslintrc: false,
// Point to the particular config
configFile
});
isPathIgnored = cliEngine.isPathIgnored.bind(cliEngine);
getConfigForFile = cliEngine.getConfigForFile.bind(cliEngine);
}
async function _getConfigs(overrideConfigFile, files) {
const esLint = new ESLint({
// Ignore any config applicable depending on the location on the filesystem
useEslintrc: false,
// Point to the particular config
overrideConfigFile
});

const configs = files.map(async filePath => (
await isPathIgnored(filePath) ? false : getConfigForFile(filePath)
await esLint.isPathIgnored(filePath) ? false : esLint.calculateConfigForFile(filePath)
));
return new Set((await Promise.all(configs)).filter(Boolean));
}
Expand Down Expand Up @@ -84,7 +68,7 @@ function _getPluginRules(config) {
}

function _getCoreRules() {
return (eslint.Linter ? new eslint.Linter() : eslint.linter).getRules();
return new Linter().getRules();
}

function _filterRuleNames(ruleNames, rules, predicate) {
Expand Down

0 comments on commit 18248f6

Please sign in to comment.