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(eslint-plugin): [ban-ts-comments] add "allow-with-description" option #2099

Merged
3 changes: 2 additions & 1 deletion packages/eslint-plugin/src/rules/ban-ts-comment.ts
Expand Up @@ -119,7 +119,8 @@ export default util.createRule<[Options], MessageIds>({
}

if (option === 'allow-with-description') {
if (description.length === 0) {
const threshold = 3;
if (description.trim().length < threshold) {
context.report({
data: { directive },
node: comment,
Expand Down
25 changes: 25 additions & 0 deletions packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts
Expand Up @@ -187,6 +187,31 @@ if (false) {
},
],
},
{
// eslint-disable-next-line @typescript-eslint/internal/plugin-test-formatting
code: '// @ts-ignore ',
dimitropoulos marked this conversation as resolved.
Show resolved Hide resolved
options: [{ 'ts-ignore': 'allow-with-description' }],
errors: [
{
data: { directive: 'ignore' },
messageId: 'tsDirectiveCommentRequiresDescription',
line: 1,
column: 1,
},
],
},
{
code: '// @ts-ignore .',
options: [{ 'ts-ignore': 'allow-with-description' }],
errors: [
{
data: { directive: 'ignore' },
messageId: 'tsDirectiveCommentRequiresDescription',
line: 1,
column: 1,
},
],
},
],
});

Expand Down