Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] support disable comment #12

Open
tjx666 opened this issue Jun 15, 2024 · 3 comments
Open

[feat] support disable comment #12

tjx666 opened this issue Jun 15, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@tjx666
Copy link

tjx666 commented Jun 15, 2024

like eslint, we can disable by:

// tssint-disable-next-line
queryClient.invalidateQueries(['useXXX']);
@johnsoncodehk johnsoncodehk added the enhancement New feature or request label Jun 15, 2024
@johnsoncodehk
Copy link
Owner

johnsoncodehk commented Jun 15, 2024

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 added a commit that referenced this issue Jun 15, 2024
@tjx666
Copy link
Author

tjx666 commented Jun 15, 2024

@johnsoncodehk works fine, but I think this should be builtin feature.

johnsoncodehk added a commit that referenced this issue Jun 15, 2024
@johnsoncodehk
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants