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

[heft-lint-plugin] fix: eslint doesn't cache output correctly #5107

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion heft-plugins/heft-lint-plugin/src/Eslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,14 @@ export class Eslint extends LinterBase<TEslint.ESLint.LintResult> {
return lintResult.fixableErrorCount + lintResult.fixableWarningCount > 0;
}));

return lintResults;
const transformedLintResults: TEslint.ESLint.LintResult[] = [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change seems unrelated to the caching issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, thought I added more context for this one - we were checking if the array was empty and using that to determine if we should write to cache, but the return result from ESLint is always an array of size = 1. https://github.com/eslint/eslint/blob/main/lib/cli-engine/cli-engine.js#L921-L950. We need to filter that array first for any warnings/errors (uncacheable things) and only then can we cache ESLint results.

for (const lintResult of lintResults) {
if (lintResult.messages.length > 0 || lintResult.warningCount > 0 || lintResult.errorCount > 0) {
transformedLintResults.push(lintResult);
}
}

return transformedLintResults;
}

protected async lintingFinishedAsync(lintResults: TEslint.ESLint.LintResult[]): Promise<void> {
Expand Down
4 changes: 3 additions & 1 deletion heft-plugins/heft-lint-plugin/src/LinterBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,9 @@ export abstract class LinterBase<TLintResult> {
}

// Compute the version from the source file content
const version: string = sourceFile.version || '';
const sourceCodeHash: Hash = createHash('sha1');
sourceCodeHash.update(sourceFile.text);
const version: string = sourceCodeHash.digest('base64');
const cachedVersion: string = cachedNoFailureFileVersions.get(relative) || '';
if (
cachedVersion === '' ||
Expand Down
Loading