Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove result storage cache #78

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 1 addition & 35 deletions src/linter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ import getESLint from './getESLint';
/** @typedef {(files: string|string[]) => void} Linter */
/** @typedef {{[files: string]: LintResult}} LintResultMap */

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

/**
* @param {string|undefined} key
* @param {Options} options
Expand All @@ -39,8 +36,6 @@ export default function linter(key, options, compilation) {
/** @type {Promise<LintResult[]>[]} */
const rawResults = [];

const crossRunResultStorage = getResultStorage(compilation);

try {
({ eslint, lintFiles, cleanup } = getESLint(key, options));
} catch (e) {
Expand All @@ -56,9 +51,6 @@ export default function linter(key, options, compilation) {
* @param {string | string[]} files
*/
function lint(files) {
for (const file of asList(files)) {
delete crossRunResultStorage[file];
}
rawResults.push(
lintFiles(files).catch((e) => {
compilation.errors.push(e);
Expand All @@ -69,20 +61,14 @@ export default 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, rawResults.length))
);

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 Expand Up @@ -289,23 +275,3 @@ async function flatten(results) {
const flat = (acc, list) => [...acc, ...list];
return (await Promise.all(results)).reduce(flat, []);
}

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

/**
* @param {string | string[]} x
*/
function asList(x) {
/* istanbul ignore next */
return Array.isArray(x) ? x : [x];
}
6 changes: 1 addition & 5 deletions test/watch.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,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(message).toEqual(expect.stringMatching('\\(2 errors,'));
expect(stats.hasErrors()).toBe(false);
done();
}
});
Expand Down