Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 1 addition & 28 deletions src/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { dirname, isAbsolute, join } = require("node:path");

const ESLintError = require("./ESLintError");
const { getESLint } = require("./getESLint");
const { arrify } = require("./utils");

/** @typedef {import("eslint").ESLint} ESLint */
/** @typedef {import("eslint").ESLint.Formatter} Formatter */
Expand All @@ -17,21 +16,6 @@ const { arrify } = require("./utils");
/** @typedef {(files: string | string[]) => void} Linter */
/** @typedef {{ [files: string]: LintResult }} LintResultMap */

/** @type {WeakMap<Compiler, LintResultMap>} */
const resultStorage = new WeakMap();

/**
* @param {Compilation} compilation compilation
* @returns {LintResultMap} lint result map
*/
function getResultStorage({ compiler }) {
let storage = resultStorage.get(compiler);
if (!storage) {
resultStorage.set(compiler, (storage = {}));
}
return storage;
}

/**
* @param {Promise<LintResult[]>[]} results results
* @returns {Promise<LintResult[]>} flatted results
Expand Down Expand Up @@ -196,8 +180,6 @@ async function linter(key, options, compilation) {
/** @type {Promise<LintResult[]>[]} */
const rawResults = [];

const crossRunResultStorage = getResultStorage(compilation);

try {
({ eslint, lintFiles, cleanup, threads } = await getESLint(key, options));
} catch (err) {
Expand All @@ -208,9 +190,6 @@ async function linter(key, options, compilation) {
* @param {string | string[]} files files
*/
function lint(files) {
for (const file of arrify(files)) {
delete crossRunResultStorage[file];
}
rawResults.push(
lintFiles(files).catch((err) => {
compilation.errors.push(new ESLintError(err.message));
Expand All @@ -224,20 +203,14 @@ async function linter(key, options, compilation) {
*/
async function report() {
// Filter out ignored files.
let results = await removeIgnoredWarnings(
const results = await removeIgnoredWarnings(
eslint,
// Get the current results, resetting the rawResults to empty
await flatten(rawResults.splice(0)),
);

await cleanup();

for (const result of results) {
crossRunResultStorage[result.filePath] = result;
}

results = Object.values(crossRunResultStorage);

// do not analyze if there are no results or eslint config
if (!results || results.length < 1) {
return {};
Expand Down
6 changes: 2 additions & 4 deletions test/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ describe("watch", () => {
function finish(err, stats) {
expect(err).toBeNull();
expect(stats.hasWarnings()).toBe(false);
const { errors } = stats.compilation;
const [{ message }] = errors;
expect(stats.hasErrors()).toBe(true);
expect(message).toEqual(expect.stringMatching("prefer-const"));
expect(stats.hasErrors()).toBe(false);
done();
}

Expand All @@ -62,6 +59,7 @@ describe("watch", () => {
expect(message).toEqual(expect.stringMatching("no-unused-vars"));
// `prefer-const` fails here
expect(message).toEqual(expect.stringMatching("prefer-const"));
expect(message).toEqual(expect.stringMatching("\\(4 errors,"));

next = finish;

Expand Down