Skip to content
This repository was archived by the owner on Aug 7, 2023. It is now read-only.

Commit 110e920

Browse files
fix: don't try to instantiate ESLint if it doesn't exist (old versions)
1 parent 49592e5 commit 110e920

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

lib/worker.js

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@ function buildCommonConstructorOptions (config, cwd) {
108108
}
109109

110110
function clearESLintCache () {
111-
log(`Clearing cache!`);
112111
for (let key of PATHS_CACHE) {
113112
PATHS_CACHE.delete(key);
114113
}
@@ -160,30 +159,33 @@ function getESLint (filePath, config, { legacyPackagePresent, projectPath }) {
160159
let resolveDir = findCwd(filePath, projectPath);
161160

162161
if (!useCache || !PATHS_CACHE.has(resolveDir)) {
163-
PATHS_CACHE.set(resolveDir, resolveESLint(resolveDir));
162+
PATHS_CACHE.set(resolveDir, resolveESLint(filePath));
164163
}
165164
let eslintPath = PATHS_CACHE.get(resolveDir);
166165

167166
if (!useCache || !ESLINT_CACHE.has(resolveDir)) {
168167
log(`Creating new ESLint instance with cwd: ${resolveDir}`);
169168
const eslintRootPath = eslintPath.replace(/eslint([/\\]).*?$/, 'eslint$1');
170169
const packageMeta = require(Path.join(eslintRootPath, 'package.json'));
171-
172170
const { ESLint } = createRequire(eslintPath)('eslint');
173-
let commonOptions = buildCommonConstructorOptions(config, projectPath || resolveDir);
171+
let bundle = {
172+
cwd: resolveDir,
173+
isBuiltIn: eslintPath === resolveBuiltInESLint(),
174+
eslintPath: eslintRootPath,
175+
eslintVersion: packageMeta.version
176+
};
174177

175-
const eslintLint = new ESLint({ ...commonOptions, fix: false });
176-
const eslintFix = new ESLint({ ...commonOptions });
178+
// Older versions of ESLint won't have this API.
179+
if (ESLint) {
180+
let commonOptions = buildCommonConstructorOptions(config, projectPath || resolveDir);
177181

178-
ESLINT_CACHE.set(resolveDir, {
179-
ESLint,
180-
eslintLint,
181-
eslintFix,
182-
eslintPath: eslintRootPath,
183-
eslintVersion: packageMeta.version,
184-
isBuiltIn: eslintPath === resolveBuiltInESLint(),
185-
cwd: resolveDir
186-
});
182+
const eslintLint = new ESLint({ ...commonOptions, fix: false });
183+
const eslintFix = new ESLint({ ...commonOptions });
184+
185+
Object.assign(bundle, { ESLint, eslintLint, eslintFix });
186+
}
187+
188+
ESLINT_CACHE.set(resolveDir, bundle);
187189
}
188190

189191
let cached = ESLINT_CACHE.get(resolveDir);
@@ -250,8 +252,8 @@ function formatResults (files, rules, config, { isModified, key, isFixJob, lintM
250252
}
251253

252254
let idTag = '';
253-
if (showRuleIdInMessage && message.ruleId) {
254-
idTag = ` (${message.ruleId})`;
255+
if (showRuleIdInMessage) {
256+
idTag = message.fatal ? ` (Fatal)` : ` (${message.ruleId})`;
255257
}
256258

257259
let rule = rules[message.ruleId];
@@ -280,7 +282,7 @@ function formatResults (files, rules, config, { isModified, key, isFixJob, lintM
280282
severity: SEVERITIES[message.severity] || 'error',
281283
location: {
282284
file: filePath,
283-
position,
285+
position
284286
},
285287
fix: message.fix,
286288
excerpt: `${message.message}${idTag}`,

0 commit comments

Comments
 (0)