Skip to content

Commit

Permalink
fix(core): remove fixes if diagnostics was removed
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jun 17, 2024
1 parent 5797507 commit 0e46049
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function createLinter(ctx: ProjectContext, config: Config, withStack: boo
const ts = ctx.typescript;
const fileRules = new Map<string, Rules>();
const fileFixes = new Map<string, Map<string, {
diagnostic: ts.Diagnostic;
diagnostic: ts.DiagnosticWithLocation;
title: string;
start: number;
end: number;
Expand Down Expand Up @@ -64,7 +64,7 @@ export function createLinter(ctx: ProjectContext, config: Config, withStack: boo
const rules = getFileRules(sourceFile.fileName);
const fixes = getFileFixes(sourceFile.fileName);

let result: ts.DiagnosticWithLocation[] = [];
let diagnostics: ts.DiagnosticWithLocation[] = [];
let currentRuleId: string;

fixes.clear();
Expand All @@ -84,11 +84,23 @@ export function createLinter(ctx: ProjectContext, config: Config, withStack: boo

for (const plugin of plugins) {
if (plugin.resolveDiagnostics) {
result = plugin.resolveDiagnostics(sourceFile.fileName, result);
diagnostics = plugin.resolveDiagnostics(sourceFile.fileName, diagnostics);
}
}

return result;
const diagnosticSet = new Set(diagnostics);

for (const [ruleId, fix] of [...fixes]) {
const finalFixes = fix.filter(fix => diagnosticSet.has(fix.diagnostic));
if (finalFixes.length) {
fixes.set(ruleId, finalFixes);
}
else {
fixes.delete(ruleId);
}
}

return diagnostics;

function reportError(message: string, start: number, end: number, traceOffset: false | number = 0) {
return report(ts.DiagnosticCategory.Error, message, start, end, traceOffset);
Expand Down Expand Up @@ -126,7 +138,7 @@ export function createLinter(ctx: ProjectContext, config: Config, withStack: boo
}
}

result.push(error);
diagnostics.push(error);

return {
withDeprecated() {
Expand Down

0 comments on commit 0e46049

Please sign in to comment.