Content-Length: 7981 | pFad | http://github.com/typescript-eslint/typescript-eslint/pull/10046.patch
thub.com
From 4c320d2519e38124a4c92b5f1810f8cc405f1602 Mon Sep 17 00:00:00 2001
From: Ronen Amiel
Date: Mon, 23 Sep 2024 21:43:59 +0300
Subject: [PATCH 1/6] fix ban-ts-comment for reporting false positives when
@ts-nocheck is not at the beginning of the file
---
.../eslint-plugin/src/rules/ban-ts-comment.ts | 21 ++++++++++++++++++-
1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/packages/eslint-plugin/src/rules/ban-ts-comment.ts b/packages/eslint-plugin/src/rules/ban-ts-comment.ts
index 44970393cfc7..d3382cc7715d 100644
--- a/packages/eslint-plugin/src/rules/ban-ts-comment.ts
+++ b/packages/eslint-plugin/src/rules/ban-ts-comment.ts
@@ -181,8 +181,19 @@ export default createRule<[Options], MessageIds>({
);
}
+ function isPositionEarlierThan(
+ a: TSESTree.Position,
+ b: TSESTree.Position,
+ ): boolean {
+ return a.line <= b.line || a.column < b.column;
+ }
+
return {
- Program(): void {
+ Program(node): void {
+ const firstStatement = node.body[0] as
+ | TSESTree.ProgramStatement
+ | undefined;
+
const comments = context.sourceCode.getAllComments();
comments.forEach(comment => {
@@ -192,6 +203,14 @@ export default createRule<[Options], MessageIds>({
}
const { directive, description } = match;
+ if (
+ directive === 'nocheck' &&
+ firstStatement &&
+ isPositionEarlierThan(firstStatement.loc.start, comment.loc.start)
+ ) {
+ return;
+ }
+
const fullDirective = `ts-${directive}` as keyof Options;
const option = options[fullDirective];
From c4c2cdc790cde429eb6c71079653b6be2f2f6a43 Mon Sep 17 00:00:00 2001
From: Ronen Amiel
Date: Mon, 23 Sep 2024 22:47:37 +0300
Subject: [PATCH 2/6] adjust and add tests
---
.../tests/rules/ban-ts-comment.test.ts | 24 +++++++------------
1 file changed, 8 insertions(+), 16 deletions(-)
diff --git a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts
index d89b560277ed..0e2bf499190a 100644
--- a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts
+++ b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts
@@ -29,6 +29,14 @@ ruleTester.run('ts-expect-error', rule, {
`
/* @ts-expect-error
* not on the last line */
+ `,
+ `
+const a = 1;
+
+// @ts-nocheck - should not be reported
+
+// TS error is not actually suppressed
+const b: string = a;
`,
{
code: '// @ts-expect-error',
@@ -1028,22 +1036,6 @@ ruleTester.run('ts-nocheck', rule, {
},
],
},
- {
- code: `
-if (false) {
- // @ts-nocheck: Unreachable code error
- console.log('hello');
-}
- `,
- errors: [
- {
- data: { directive: 'nocheck' },
- messageId: 'tsDirectiveComment',
- line: 3,
- column: 3,
- },
- ],
- },
{
code: '// @ts-nocheck',
options: [{ 'ts-nocheck': 'allow-with-description' }],
From b769122c5e412b220b6ae97b77e31ed78281e677 Mon Sep 17 00:00:00 2001
From: Ronen Amiel
Date: Mon, 23 Sep 2024 23:12:27 +0300
Subject: [PATCH 3/6] use .at() instead if indexed access
---
packages/eslint-plugin/src/rules/ban-ts-comment.ts | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/packages/eslint-plugin/src/rules/ban-ts-comment.ts b/packages/eslint-plugin/src/rules/ban-ts-comment.ts
index d3382cc7715d..82f2aa48782c 100644
--- a/packages/eslint-plugin/src/rules/ban-ts-comment.ts
+++ b/packages/eslint-plugin/src/rules/ban-ts-comment.ts
@@ -190,9 +190,7 @@ export default createRule<[Options], MessageIds>({
return {
Program(node): void {
- const firstStatement = node.body[0] as
- | TSESTree.ProgramStatement
- | undefined;
+ const firstStatement = node.body.at(0);
const comments = context.sourceCode.getAllComments();
From 44e593889794ce09b4b48a7b36ae86e82a3e4f97 Mon Sep 17 00:00:00 2001
From: Ronen Amiel
Date: Wed, 25 Sep 2024 10:47:36 +0300
Subject: [PATCH 4/6] oops
---
packages/eslint-plugin/src/rules/ban-ts-comment.ts | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/packages/eslint-plugin/src/rules/ban-ts-comment.ts b/packages/eslint-plugin/src/rules/ban-ts-comment.ts
index 82f2aa48782c..19001dcbd97a 100644
--- a/packages/eslint-plugin/src/rules/ban-ts-comment.ts
+++ b/packages/eslint-plugin/src/rules/ban-ts-comment.ts
@@ -181,13 +181,6 @@ export default createRule<[Options], MessageIds>({
);
}
- function isPositionEarlierThan(
- a: TSESTree.Position,
- b: TSESTree.Position,
- ): boolean {
- return a.line <= b.line || a.column < b.column;
- }
-
return {
Program(node): void {
const firstStatement = node.body.at(0);
@@ -204,7 +197,7 @@ export default createRule<[Options], MessageIds>({
if (
directive === 'nocheck' &&
firstStatement &&
- isPositionEarlierThan(firstStatement.loc.start, comment.loc.start)
+ firstStatement.loc.start.line <= comment.loc.start.line
) {
return;
}
From d0794c65227c5651ed96d4f5c07530961b690a2d Mon Sep 17 00:00:00 2001
From: Ronen Amiel
Date: Sun, 29 Sep 2024 18:26:36 +0300
Subject: [PATCH 5/6] tests edge case
---
.../tests/rules/ban-ts-comment.test.ts | 32 ++++++++++++++-----
1 file changed, 24 insertions(+), 8 deletions(-)
diff --git a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts
index 0e2bf499190a..5187eec51dc5 100644
--- a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts
+++ b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts
@@ -29,14 +29,6 @@ ruleTester.run('ts-expect-error', rule, {
`
/* @ts-expect-error
* not on the last line */
- `,
- `
-const a = 1;
-
-// @ts-nocheck - should not be reported
-
-// TS error is not actually suppressed
-const b: string = a;
`,
{
code: '// @ts-expect-error',
@@ -1000,6 +992,14 @@ ruleTester.run('ts-nocheck', rule, {
`,
'/** @ts-nocheck */',
'/* @ts-nocheck */',
+ `
+const a = 1;
+
+// @ts-nocheck - should not be reported
+
+// TS error is not actually suppressed
+const b: string = a;
+ `,
],
invalid: [
{
@@ -1119,6 +1119,22 @@ ruleTester.run('ts-nocheck', rule, {
},
],
},
+ {
+ // comment's colum > first statement's column
+ // eslint-disable-next-line @typescript-eslint/internal/plugin-test-formatting
+ code: `
+ // @ts-nocheck
+const a: true = false;
+ `,
+ errors: [
+ {
+ data: { directive: 'nocheck', minimumDescriptionLength: 3 },
+ messageId: 'tsDirectiveComment',
+ line: 2,
+ column: 2,
+ },
+ ],
+ },
],
});
From d07c3ee5bb3bf718e374c400b32aad7ef253fc12 Mon Sep 17 00:00:00 2001
From: Ronen Amiel
Date: Sun, 29 Sep 2024 18:32:56 +0300
Subject: [PATCH 6/6] typo
---
packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts
index 5187eec51dc5..bfc2a4565700 100644
--- a/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts
+++ b/packages/eslint-plugin/tests/rules/ban-ts-comment.test.ts
@@ -1120,7 +1120,7 @@ const b: string = a;
],
},
{
- // comment's colum > first statement's column
+ // comment's column > first statement's column
// eslint-disable-next-line @typescript-eslint/internal/plugin-test-formatting
code: `
// @ts-nocheck
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/typescript-eslint/typescript-eslint/pull/10046.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy