-
-
Notifications
You must be signed in to change notification settings - Fork 291
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,21 +2,16 @@ import process from 'node:process'; | |
import path from 'node:path'; | ||
import {ESLint} from 'eslint'; | ||
import {globby, isGitIgnoredSync} from 'globby'; | ||
import {isEqual} from 'lodash-es'; | ||
import {omit, isEqual} from 'lodash-es'; | ||
import micromatch from 'micromatch'; | ||
import arrify from 'arrify'; | ||
import pReduce from 'p-reduce'; | ||
import pMap from 'p-map'; | ||
import {cosmiconfig, defaultLoaders} from 'cosmiconfig'; | ||
import defineLazyProperty from 'define-lazy-prop'; | ||
import pFilter from 'p-filter'; | ||
import slash from 'slash'; | ||
import {CONFIG_FILES, MODULE_NAME, DEFAULT_IGNORES} from './lib/constants.js'; | ||
import { | ||
normalizeOptions, | ||
getIgnores, | ||
mergeWithFileConfig, | ||
mergeWithFileConfigs, | ||
buildConfig, | ||
mergeOptions, | ||
} from './lib/options-manager.js'; | ||
|
@@ -87,10 +82,19 @@ const processReport = (report, {isQuiet = false} = {}) => { | |
return result; | ||
}; | ||
|
||
const runEslint = async (paths, options, processorOptions) => { | ||
const engine = new ESLint(options); | ||
const runEslint = async (filePath, options, processorOptions) => { | ||
const engine = new ESLint(omit(options, ['filePath', 'warnIgnored'])); | ||
const filename = path.relative(options.cwd, filePath); | ||
|
||
const report = await engine.lintFiles(await pFilter(paths, async path => !(await engine.isPathIgnored(path)))); | ||
if ( | ||
micromatch.isMatch(filename, options.baseConfig.ignorePatterns) | ||
|| isGitIgnoredSync({cwd: options.cwd, ignore: options.baseConfig.ignorePatterns})(filePath) | ||
|| await engine.isPathIgnored(filePath) | ||
) { | ||
return; | ||
} | ||
|
||
const report = await engine.lintFiles([filePath]); | ||
return processReport(report, processorOptions); | ||
}; | ||
|
||
|
@@ -145,25 +149,24 @@ const lintText = async (string, inputOptions = {}) => { | |
}; | ||
|
||
const lintFiles = async (patterns, inputOptions = {}) => { | ||
inputOptions = normalizeOptions(inputOptions); | ||
inputOptions.cwd = path.resolve(inputOptions.cwd || process.cwd()); | ||
const configExplorer = cosmiconfig(MODULE_NAME, {searchPlaces: CONFIG_FILES, loaders: {noExt: defaultLoaders['.json']}, stopDir: inputOptions.cwd}); | ||
|
||
const configFiles = (await Promise.all( | ||
(await globby( | ||
CONFIG_FILES.map(configFile => `**/${configFile}`), | ||
{ignore: DEFAULT_IGNORES, gitignore: true, absolute: true, cwd: inputOptions.cwd}, | ||
)).map(configFile => configExplorer.load(configFile)), | ||
)).filter(Boolean); | ||
|
||
const paths = configFiles.length > 0 | ||
? await pReduce( | ||
configFiles, | ||
async (paths, {filepath, config}) => | ||
[...paths, ...(await globFiles(patterns, {...mergeOptions(inputOptions, config), cwd: path.dirname(filepath)}))], | ||
[]) | ||
: await globFiles(patterns, mergeOptions(inputOptions)); | ||
|
||
return mergeReports(await pMap(await mergeWithFileConfigs([...new Set(paths)], inputOptions, configFiles), async ({files, options, prettierOptions}) => runEslint(files, buildConfig(options, prettierOptions), {isQuiet: options.quiet}))); | ||
|
||
const files = await globFiles(patterns, mergeOptions(inputOptions)); | ||
|
||
const reports = await pMap( | ||
files, | ||
async filePath => { | ||
const {options: foundOptions, prettierOptions} = mergeWithFileConfig({ | ||
...inputOptions, | ||
filePath, | ||
}); | ||
const options = buildConfig(foundOptions, prettierOptions); | ||
return runEslint(filePath, options, {isQuiet: inputOptions.quiet}); | ||
}, | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
sindresorhus
Member
|
||
); | ||
|
||
return mergeReports(reports.filter(Boolean)); | ||
}; | ||
|
||
const getFormatter = async name => { | ||
|
@fisker - Responding to #599 (comment)
The memory issue I seem to have run into is quite troublesome, but the amount of code you've deleted suggests to me this change is definitely worth preserving...
At a high level, without really understanding this code, it seems we've somehow made this tradeoff:
I am digging into the code some