Skip to content

Commit

Permalink
feat(config): add support for custom code fixes in ignore plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Dec 10, 2024
1 parent f0754b4 commit 3addf08
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions packages/config/lib/plugins/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,29 @@ export function create(cmd: string, reportsUnusedComments: boolean): Plugin {
}
return results;
},
resolveCodeFixes(sourceFile, diagnostic, codeFixes) {
if (diagnostic.source !== 'tsslint' || diagnostic.start === undefined) {
return codeFixes;
}
const line = sourceFile.getLineAndCharacterOfPosition(diagnostic.start).line;
codeFixes.push({
fixName: cmd,
description: `Ignore with ${cmd}`,
changes: [
{
fileName: sourceFile.fileName,
textChanges: [{
newText: `// ${cmd} ${diagnostic.code}\n`,
span: {
start: sourceFile.getPositionOfLineAndCharacter(line, 0),
length: 0,
},
}],
},
],
});
return codeFixes;
},
};
};
}
2 changes: 1 addition & 1 deletion packages/typescript-plugin/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function decorateLanguageService(
};
info.languageService.getCombinedCodeFix = (scope, fixId, formatOptions, preferences) => {
if (fixId === 'tsslint' && linter) {
const fixes = linter.getCodeFixes(scope.fileName, 0, Number.MAX_VALUE);
const fixes = linter.getCodeFixes(scope.fileName, 0, Number.MAX_VALUE).filter(fix => fix.fixId === 'tsslint');
const changes = core.combineCodeFixes(scope.fileName, fixes);
return {
changes: [{
Expand Down

0 comments on commit 3addf08

Please sign in to comment.