Skip to content

Commit

Permalink
Remove some needless imports (#560)
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmywarting committed Jun 19, 2021
1 parent 6adf459 commit 3e7b77c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
26 changes: 12 additions & 14 deletions index.js
Expand Up @@ -3,17 +3,14 @@ const path = require('path');
const {ESLint} = require('eslint');
const globby = require('globby');
const isEqual = require('lodash/isEqual');
const uniq = require('lodash/uniq');
const pick = require('lodash/pick');
const omit = require('lodash/omit');
const micromatch = require('micromatch');
const arrify = require('arrify');
const pReduce = require('p-reduce');
const pMap = require('p-map');
const {cosmiconfig, defaultLoaders} = require('cosmiconfig');
const defineLazyProperty = require('define-lazy-prop');
const pFilter = require('p-filter');
const {CONFIG_FILES, MODULE_NAME, DEFAULT_IGNORES, LINT_METHOD_OPTIONS} = require('./lib/constants');
const {CONFIG_FILES, MODULE_NAME, DEFAULT_IGNORES} = require('./lib/constants');
const {
normalizeOptions,
getIgnores,
Expand Down Expand Up @@ -104,9 +101,9 @@ const globFiles = async (patterns, {ignores, extensions, cwd}) => (

const getConfig = async options => {
const {options: foundOptions, prettierOptions} = mergeWithFileConfig(normalizeOptions(options));
options = buildConfig(foundOptions, prettierOptions);
const engine = new ESLint(omit(options, LINT_METHOD_OPTIONS));
return engine.calculateConfigForFile(options.filePath);
const {filePath, warnIgnored, ...eslintOptions} = buildConfig(foundOptions, prettierOptions);
const engine = new ESLint(eslintOptions);
return engine.calculateConfigForFile(filePath);
};

const lintText = async (string, inputOptions = {}) => {
Expand All @@ -117,15 +114,16 @@ const lintText = async (string, inputOptions = {}) => {
throw new Error('The `ignores` option requires the `filePath` option to be defined.');
}

const engine = new ESLint(omit(options, LINT_METHOD_OPTIONS));
const {filePath, warnIgnored, ...eslintOptions} = options;
const engine = new ESLint(eslintOptions);

if (options.filePath) {
const filename = path.relative(options.cwd, options.filePath);
if (filePath) {
const filename = path.relative(options.cwd, filePath);

if (
micromatch.isMatch(filename, options.baseConfig.ignorePatterns) ||
globby.gitignore.sync({cwd: options.cwd, ignore: options.baseConfig.ignorePatterns})(options.filePath) ||
await engine.isPathIgnored(options.filePath)
globby.gitignore.sync({cwd: options.cwd, ignore: options.baseConfig.ignorePatterns})(filePath) ||
await engine.isPathIgnored(filePath)
) {
return {
errorCount: 0,
Expand All @@ -140,7 +138,7 @@ const lintText = async (string, inputOptions = {}) => {
}
}

const report = await engine.lintText(string, pick(options, LINT_METHOD_OPTIONS));
const report = await engine.lintText(string, {filePath, warnIgnored});

return processReport(report, {isQuiet: inputOptions.quiet});
};
Expand All @@ -164,7 +162,7 @@ const lintFiles = async (patterns, inputOptions = {}) => {
[]) :
await globFiles(patterns, mergeOptions(inputOptions));

return mergeReports(await pMap(await mergeWithFileConfigs(uniq(paths), inputOptions, configFiles), async ({files, options, prettierOptions}) => runEslint(files, buildConfig(options, prettierOptions), {isQuiet: options.quiet})));
return mergeReports(await pMap(await mergeWithFileConfigs([...new Set(paths)], inputOptions, configFiles), async ({files, options, prettierOptions}) => runEslint(files, buildConfig(options, prettierOptions), {isQuiet: options.quiet})));
};

const getFormatter = async name => {
Expand Down
5 changes: 1 addition & 4 deletions lib/constants.js
Expand Up @@ -137,8 +137,6 @@ const TSCONFIG_DEFFAULTS = {

const CACHE_DIR_NAME = 'xo-linter';

const LINT_METHOD_OPTIONS = ['filePath', 'warnIgnored'];

module.exports = {
DEFAULT_IGNORES,
DEFAULT_EXTENSION,
Expand All @@ -149,6 +147,5 @@ module.exports = {
CONFIG_FILES,
MERGE_OPTIONS_CONCAT,
TSCONFIG_DEFFAULTS,
CACHE_DIR_NAME,
LINT_METHOD_OPTIONS
CACHE_DIR_NAME
};

0 comments on commit 3e7b77c

Please sign in to comment.