Skip to content

Commit

Permalink
refactor(cli): optimize code fix check
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jun 11, 2024
1 parent 6e1f443 commit 3438761
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ import glob = require('glob');
}
}
if (diagnostics.length) {
hasFix ||= linter.getCodeFixes(fileName, 0, Number.MAX_VALUE, diagnostics).length >= 1;
hasFix ||= linter.hasCodeFixes(fileName);
hasError ||= diagnostics.some(diagnostic => diagnostic.category === ts.DiagnosticCategory.Error);
}
}
Expand Down
12 changes: 12 additions & 0 deletions packages/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ export function createLinter(ctx: ProjectContext, config: Config, withStack: boo
};
}
},
hasCodeFixes(fileName: string) {

const fixesMap = getFileFixes(fileName);

for (const [_ruleId, fixes] of fixesMap) {
if (fixes.length) {
return true;
}
}

return false;
},
getCodeFixes(fileName: string, start: number, end: number, diagnostics?: ts.Diagnostic[]) {

const fixesMap = getFileFixes(fileName);
Expand Down

0 comments on commit 3438761

Please sign in to comment.