Skip to content

Commit

Permalink
Merge branch 'main' into key-spacing
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaKGoldberg committed Jan 24, 2023
2 parents 23036de + 09d57ce commit e483407
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/eslint-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"@typescript-eslint/type-utils": "5.49.0",
"@typescript-eslint/utils": "5.49.0",
"debug": "^4.3.4",
"grapheme-splitter": "^1.0.4",
"ignore": "^5.2.0",
"grapheme-splitter": "^1.0.4",
"natural-compare-lite": "^1.4.0",
Expand All @@ -62,6 +63,7 @@
"@types/natural-compare-lite": "^1.4.0",
"@types/prettier": "*",
"chalk": "^5.0.1",
"grapheme-splitter": "^1.0.4",
"cross-fetch": "^3.1.5",
"json-schema": "*",
"markdown-table": "^3.0.2",
Expand Down
19 changes: 18 additions & 1 deletion packages/eslint-plugin/src/rules/ban-ts-comment.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
import { AST_TOKEN_TYPES } from '@typescript-eslint/utils';
import GraphemeSplitter from 'grapheme-splitter';

import * as util from '../util';

let splitter: GraphemeSplitter;
function isASCII(value: string): boolean {
return /^[\u0020-\u007f]*$/u.test(value);
}
function getStringLength(value: string): number {
if (isASCII(value)) {
return value.length;
}

splitter ??= new GraphemeSplitter();

return splitter.countGraphemes(value);
}

type DirectiveConfig =
| boolean
| 'allow-with-description'
Expand Down Expand Up @@ -147,7 +162,9 @@ export default util.createRule<[Options], MessageIds>({
minimumDescriptionLength = defaultMinimumDescriptionLength,
} = options;
const format = descriptionFormats.get(fullDirective);
if (description.trim().length < minimumDescriptionLength) {
if (
getStringLength(description.trim()) < minimumDescriptionLength
) {
context.report({
data: { directive, minimumDescriptionLength },
node: comment,
Expand Down
96 changes: 96 additions & 0 deletions packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ ruleTester.run('ts-expect-error', rule, {
},
],
},
{
code: noFormat`// @ts-expect-error 👨‍👩‍👧‍👦👨‍👩‍👧‍👦👨‍👩‍👧‍👦`,
options: [
{
'ts-expect-error': 'allow-with-description',
},
],
},
],
invalid: [
{
Expand Down Expand Up @@ -228,6 +236,22 @@ if (false) {
},
],
},
{
code: noFormat`// @ts-expect-error 👨‍👩‍👧‍👦`,
options: [
{
'ts-expect-error': 'allow-with-description',
},
],
errors: [
{
data: { directive: 'expect-error', minimumDescriptionLength: 3 },
messageId: 'tsDirectiveCommentRequiresDescription',
line: 1,
column: 1,
},
],
},
],
});

Expand Down Expand Up @@ -266,6 +290,14 @@ ruleTester.run('ts-ignore', rule, {
},
],
},
{
code: noFormat`// @ts-ignore 👨‍👩‍👧‍👦👨‍👩‍👧‍👦👨‍👩‍👧‍👦`,
options: [
{
'ts-ignore': 'allow-with-description',
},
],
},
],
invalid: [
{
Expand Down Expand Up @@ -460,6 +492,22 @@ if (false) {
},
],
},
{
code: noFormat`// @ts-ignore 👨‍👩‍👧‍👦`,
options: [
{
'ts-ignore': 'allow-with-description',
},
],
errors: [
{
data: { directive: 'ignore', minimumDescriptionLength: 3 },
messageId: 'tsDirectiveCommentRequiresDescription',
line: 1,
column: 1,
},
],
},
],
});

Expand Down Expand Up @@ -498,6 +546,14 @@ ruleTester.run('ts-nocheck', rule, {
},
],
},
{
code: noFormat`// @ts-nocheck 👨‍👩‍👧‍👦👨‍👩‍👧‍👦👨‍👩‍👧‍👦`,
options: [
{
'ts-nocheck': 'allow-with-description',
},
],
},
],
invalid: [
{
Expand Down Expand Up @@ -668,6 +724,22 @@ if (false) {
},
],
},
{
code: noFormat`// @ts-nocheck 👨‍👩‍👧‍👦`,
options: [
{
'ts-nocheck': 'allow-with-description',
},
],
errors: [
{
data: { directive: 'nocheck', minimumDescriptionLength: 3 },
messageId: 'tsDirectiveCommentRequiresDescription',
line: 1,
column: 1,
},
],
},
],
});

Expand Down Expand Up @@ -700,6 +772,14 @@ ruleTester.run('ts-check', rule, {
},
],
},
{
code: noFormat`// @ts-check 👨‍👩‍👧‍👦👨‍👩‍👧‍👦👨‍👩‍👧‍👦`,
options: [
{
'ts-check': 'allow-with-description',
},
],
},
],
invalid: [
{
Expand Down Expand Up @@ -863,5 +943,21 @@ if (false) {
},
],
},
{
code: noFormat`// @ts-check 👨‍👩‍👧‍👦`,
options: [
{
'ts-check': 'allow-with-description',
},
],
errors: [
{
data: { directive: 'check', minimumDescriptionLength: 3 },
messageId: 'tsDirectiveCommentRequiresDescription',
line: 1,
column: 1,
},
],
},
],
});

0 comments on commit e483407

Please sign in to comment.