[feat] support disable comment
like eslint, we can disable by:
// tssint-disable-next-line
queryClient.invalidateQueries(['useXXX']);
You can do this through the plugin API.
import { Plugin, defineConfig } from '@tsslint/config';
export default defineConfig({
plugins: [
createIngorePlugin(/\/\/ tsslint-disable-next-line\n/g),
createIngorePlugin(/\/\/ eslint-disable-next-line\n/g),
]
});
function createIngorePlugin(pattern: RegExp): Plugin {
return ({ languageService }) => ({
resolveDiagnostics(fileName, results) {
const sourceFile = languageService.getProgram()?.getSourceFile(fileName);
if (!sourceFile) {
return results;
}
const comments = [...sourceFile.text.matchAll(pattern)];
const lines = new Set(comments.map(comment => sourceFile.getLineAndCharacterOfPosition(comment.index).line));
return results.filter(error => error.source !== 'tsslint' || !lines.has(sourceFile.getLineAndCharacterOfPosition(error.start).line - 1));
},
});
}
@johnsoncodehk works fine, but I think this should be builtin feature.
This is not yet a built-in feature, as projects migrating from ESLint may still need to support eslint-disable-next-line instead of tsslint-disable-next-line/@tsslint-ignore, so this syntax needs to be available configuration.
I will keep this issue open.
@johnsoncodehk
It would be fine to also support use tslint-disable-next-line, because some useful eslint rules which used to check unused eslint disable comments will report error to it:
for anyone don't know how to config the plugins, you can use like following:
@johnsoncodehk the unused-disable-next-line check is not a good idea for eslint & tslint mixed project.
@tjx666 it can be disabled by createDisableNextLinePlugin(false).
@johnsoncodehk I see your latest implementation add 2 plugin arguments, so, I use following now(I just copy you plugin code because you had not publish the latest code yet):
plugins: [
createDisableNextLinePlugin(
true,
new RegExp(/\/\/\s*tslint-disable-next-line\b[ \t]*(?<ruleId>\S*)\b/g),
),
createShowDocsActionPlugin(),
],
plugins: [ createDisableNextLinePlugin( true, new RegExp(/\/\/\s*tslint-disable-next-line\b[ \t]*(?<ruleId>\S*)\b/g), ), createShowDocsActionPlugin(), ],
This is now available in 1.3.0.