Skip to content

Commit ca1ae72

Browse files
refactor: remove dup of code from linter.js (#202)
* refactor: remove dup of code from linter.js * refactor: removing unnecessary function --------- Co-authored-by: Ricardo Gobbo de Souza <[email protected]>
1 parent 204e3b8 commit ca1ae72

File tree

2 files changed

+15
-27
lines changed

2 files changed

+15
-27
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ or
3636
pnpm add -D eslint-webpack-plugin
3737
```
3838

39-
> **Note**:
39+
> **Note**:
4040
>
4141
> You also need to install `eslint >= 8` from npm, if you haven't already:
4242

src/linter.js

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { dirname, isAbsolute, join } = require('path');
22

33
const ESLintError = require('./ESLintError');
44
const { getESLint } = require('./getESLint');
5+
const { arrify } = require('./utils');
56

67
/** @typedef {import('eslint').ESLint} ESLint */
78
/** @typedef {import('eslint').ESLint.Formatter} Formatter */
@@ -59,7 +60,7 @@ function linter(key, options, compilation) {
5960
* @param {string | string[]} files
6061
*/
6162
function lint(files) {
62-
for (const file of asList(files)) {
63+
for (const file of arrify(files)) {
6364
delete crossRunResultStorage[file];
6465
}
6566
rawResults.push(
@@ -192,10 +193,7 @@ function parseResults(options, results) {
192193
);
193194

194195
if (messages.length > 0) {
195-
errors.push({
196-
...file,
197-
messages,
198-
});
196+
errors.push({ ...file, messages });
199197
}
200198
}
201199

@@ -205,10 +203,7 @@ function parseResults(options, results) {
205203
);
206204

207205
if (messages.length > 0) {
208-
warnings.push({
209-
...file,
210-
messages,
211-
});
206+
warnings.push({ ...file, messages });
212207
}
213208
}
214209
});
@@ -267,20 +262,21 @@ async function removeIgnoredWarnings(eslint, results) {
267262
// fatal is false for ignored file warnings.
268263
// ruleId is unset for internal ESLint errors.
269264
// line is unset for warnings not involving file contents.
265+
const { messages, warningCount, errorCount, filePath } = result;
266+
const [firstMessage] = messages;
267+
const hasWarning = warningCount === 1 && errorCount === 0;
270268
const ignored =
271-
result.messages.length === 0 ||
272-
(result.warningCount === 1 &&
273-
result.errorCount === 0 &&
274-
!result.messages[0].fatal &&
275-
!result.messages[0].ruleId &&
276-
!result.messages[0].line &&
277-
(await eslint.isPathIgnored(result.filePath)));
278-
269+
messages.length === 0 ||
270+
(hasWarning &&
271+
!firstMessage.fatal &&
272+
!firstMessage.ruleId &&
273+
!firstMessage.line &&
274+
(await eslint.isPathIgnored(filePath)));
279275
return ignored ? false : result;
280276
});
281277

282278
// @ts-ignore
283-
return (await Promise.all(filterPromises)).filter((result) => !!result);
279+
return (await Promise.all(filterPromises)).filter(Boolean);
284280
}
285281

286282
/**
@@ -308,12 +304,4 @@ function getResultStorage({ compiler }) {
308304
return storage;
309305
}
310306

311-
/**
312-
* @param {string | string[]} x
313-
*/
314-
function asList(x) {
315-
/* istanbul ignore next */
316-
return Array.isArray(x) ? x : [x];
317-
}
318-
319307
module.exports = linter;

0 commit comments

Comments
 (0)