Skip to content

Commit 3e7b77c

Browse files
authored
Remove some needless imports (#560)
1 parent 6adf459 commit 3e7b77c

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

Diff for: index.js

+12-14
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@ const path = require('path');
33
const {ESLint} = require('eslint');
44
const globby = require('globby');
55
const isEqual = require('lodash/isEqual');
6-
const uniq = require('lodash/uniq');
7-
const pick = require('lodash/pick');
8-
const omit = require('lodash/omit');
96
const micromatch = require('micromatch');
107
const arrify = require('arrify');
118
const pReduce = require('p-reduce');
129
const pMap = require('p-map');
1310
const {cosmiconfig, defaultLoaders} = require('cosmiconfig');
1411
const defineLazyProperty = require('define-lazy-prop');
1512
const pFilter = require('p-filter');
16-
const {CONFIG_FILES, MODULE_NAME, DEFAULT_IGNORES, LINT_METHOD_OPTIONS} = require('./lib/constants');
13+
const {CONFIG_FILES, MODULE_NAME, DEFAULT_IGNORES} = require('./lib/constants');
1714
const {
1815
normalizeOptions,
1916
getIgnores,
@@ -104,9 +101,9 @@ const globFiles = async (patterns, {ignores, extensions, cwd}) => (
104101

105102
const getConfig = async options => {
106103
const {options: foundOptions, prettierOptions} = mergeWithFileConfig(normalizeOptions(options));
107-
options = buildConfig(foundOptions, prettierOptions);
108-
const engine = new ESLint(omit(options, LINT_METHOD_OPTIONS));
109-
return engine.calculateConfigForFile(options.filePath);
104+
const {filePath, warnIgnored, ...eslintOptions} = buildConfig(foundOptions, prettierOptions);
105+
const engine = new ESLint(eslintOptions);
106+
return engine.calculateConfigForFile(filePath);
110107
};
111108

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

120-
const engine = new ESLint(omit(options, LINT_METHOD_OPTIONS));
117+
const {filePath, warnIgnored, ...eslintOptions} = options;
118+
const engine = new ESLint(eslintOptions);
121119

122-
if (options.filePath) {
123-
const filename = path.relative(options.cwd, options.filePath);
120+
if (filePath) {
121+
const filename = path.relative(options.cwd, filePath);
124122

125123
if (
126124
micromatch.isMatch(filename, options.baseConfig.ignorePatterns) ||
127-
globby.gitignore.sync({cwd: options.cwd, ignore: options.baseConfig.ignorePatterns})(options.filePath) ||
128-
await engine.isPathIgnored(options.filePath)
125+
globby.gitignore.sync({cwd: options.cwd, ignore: options.baseConfig.ignorePatterns})(filePath) ||
126+
await engine.isPathIgnored(filePath)
129127
) {
130128
return {
131129
errorCount: 0,
@@ -140,7 +138,7 @@ const lintText = async (string, inputOptions = {}) => {
140138
}
141139
}
142140

143-
const report = await engine.lintText(string, pick(options, LINT_METHOD_OPTIONS));
141+
const report = await engine.lintText(string, {filePath, warnIgnored});
144142

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

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

170168
const getFormatter = async name => {

Diff for: lib/constants.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,6 @@ const TSCONFIG_DEFFAULTS = {
137137

138138
const CACHE_DIR_NAME = 'xo-linter';
139139

140-
const LINT_METHOD_OPTIONS = ['filePath', 'warnIgnored'];
141-
142140
module.exports = {
143141
DEFAULT_IGNORES,
144142
DEFAULT_EXTENSION,
@@ -149,6 +147,5 @@ module.exports = {
149147
CONFIG_FILES,
150148
MERGE_OPTIONS_CONCAT,
151149
TSCONFIG_DEFFAULTS,
152-
CACHE_DIR_NAME,
153-
LINT_METHOD_OPTIONS
150+
CACHE_DIR_NAME
154151
};

0 commit comments

Comments
 (0)