Skip to content

Commit eb63c3f

Browse files
fix(heft-lint-plugin): allow ESLint linter output to be cached (#5107)
Signed-off-by: Aramis Sennyey <[email protected]> Co-authored-by: Aramis Sennyey <[email protected]>
1 parent e989f87 commit eb63c3f

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@rushstack/heft-lint-plugin",
5+
"comment": "Fix an issue where the cache is only populated for incremental TypeScript builds.",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@rushstack/heft-lint-plugin"
10+
}

heft-plugins/heft-lint-plugin/src/Eslint.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,14 @@ export class Eslint extends LinterBase<TEslint.ESLint.LintResult> {
176176
return lintResult.fixableErrorCount + lintResult.fixableWarningCount > 0;
177177
}));
178178

179-
return lintResults;
179+
const trimmedLintResults: TEslint.ESLint.LintResult[] = [];
180+
for (const lintResult of lintResults) {
181+
if (lintResult.messages.length > 0 || lintResult.warningCount > 0 || lintResult.errorCount > 0) {
182+
trimmedLintResults.push(lintResult);
183+
}
184+
}
185+
186+
return trimmedLintResults;
180187
}
181188

182189
protected async lintingFinishedAsync(lintResults: TEslint.ESLint.LintResult[]): Promise<void> {

heft-plugins/heft-lint-plugin/src/LinterBase.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,15 @@ export abstract class LinterBase<TLintResult> {
138138
continue;
139139
}
140140

141-
// Compute the version from the source file content
142-
const version: string = sourceFile.version || '';
141+
// TypeScript only computes the version during an incremental build.
142+
let version: string = sourceFile.version;
143+
if (!version) {
144+
// Compute the version from the source file content
145+
const sourceCodeHash: Hash = createHash('sha1');
146+
sourceCodeHash.update(sourceFile.text);
147+
version = sourceCodeHash.digest('base64');
148+
}
149+
143150
const cachedVersion: string = cachedNoFailureFileVersions.get(relative) || '';
144151
if (
145152
cachedVersion === '' ||

0 commit comments

Comments
 (0)