From 777a51324ad7a6669e83b6bdf0d609278350e7c3 Mon Sep 17 00:00:00 2001 From: Vincent Girard Date: Fri, 7 Jun 2024 11:33:59 -0400 Subject: [PATCH 1/6] fix(eslint-plugin): [no-unsafe-call] differentiate a types-error any from a true any --- packages/eslint-plugin/src/rules/no-unsafe-call.ts | 8 +++++++- packages/eslint-plugin/tests/rules/no-unsafe-call.test.ts | 7 +++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/no-unsafe-call.ts b/packages/eslint-plugin/src/rules/no-unsafe-call.ts index b4ec6379f2e1..8a24536d39c4 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-call.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-call.ts @@ -20,7 +20,7 @@ export default createRule<[], MessageIds>({ meta: { type: 'problem', docs: { - description: 'Disallow calling a value with type `any`', + description: 'Disallow calling a value with type {{type}}', recommended: 'recommended', requiresTypeChecking: true, }, @@ -64,9 +64,15 @@ export default createRule<[], MessageIds>({ messageId = 'unsafeCallThis'; } } + + const isErrorType = tsutils.isIntrinsicErrorType(type); + context.report({ node: reportingNode, messageId: messageId, + data: { + type: isErrorType ? '`error`' : '`any`', + }, }); } } diff --git a/packages/eslint-plugin/tests/rules/no-unsafe-call.test.ts b/packages/eslint-plugin/tests/rules/no-unsafe-call.test.ts index bb844011fd7b..720846e16984 100644 --- a/packages/eslint-plugin/tests/rules/no-unsafe-call.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unsafe-call.test.ts @@ -163,5 +163,12 @@ const methods = { }, ], }, + { + code: ` +let value: NotKnown; +value(); + `, + errors: [{ messageId: 'unsafeCall' }], + }, ], }); From da5cb6ee7cdd6d5f562eb112919fbf87667f6990 Mon Sep 17 00:00:00 2001 From: Vincent Girard Date: Fri, 7 Jun 2024 11:54:20 -0400 Subject: [PATCH 2/6] Fixed docs tests --- packages/eslint-plugin/docs/rules/no-unsafe-call.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx b/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx index 3e56c1e0f092..118f1ba15537 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx +++ b/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx @@ -1,5 +1,5 @@ --- -description: 'Disallow calling a value with type `any`.' +description: 'Disallow calling a value with type {{type}}.' --- import Tabs from '@theme/Tabs'; From 8fdd8f205b129859a07240be8dbeb41ab416f42a Mon Sep 17 00:00:00 2001 From: Vincent Girard Date: Sat, 8 Jun 2024 15:54:01 -0400 Subject: [PATCH 3/6] Fixed error message and tests --- .../docs/rules/no-unsafe-call.mdx | 2 +- .../eslint-plugin/src/rules/no-unsafe-call.ts | 2 +- .../tests/rules/no-unsafe-call.test.ts | 96 +++++++++++++++++-- 3 files changed, 90 insertions(+), 10 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx b/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx index 118f1ba15537..569cd0fe3546 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx +++ b/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx @@ -1,5 +1,5 @@ --- -description: 'Disallow calling a value with type {{type}}.' +description: 'Disallow calling a value with type an {{type}} value.' --- import Tabs from '@theme/Tabs'; diff --git a/packages/eslint-plugin/src/rules/no-unsafe-call.ts b/packages/eslint-plugin/src/rules/no-unsafe-call.ts index 8a24536d39c4..a391b82312ad 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-call.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-call.ts @@ -20,7 +20,7 @@ export default createRule<[], MessageIds>({ meta: { type: 'problem', docs: { - description: 'Disallow calling a value with type {{type}}', + description: 'Disallow calling a value with type an {{type}} value', recommended: 'recommended', requiresTypeChecking: true, }, diff --git a/packages/eslint-plugin/tests/rules/no-unsafe-call.test.ts b/packages/eslint-plugin/tests/rules/no-unsafe-call.test.ts index 720846e16984..fe62b0595fb1 100644 --- a/packages/eslint-plugin/tests/rules/no-unsafe-call.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unsafe-call.test.ts @@ -51,7 +51,17 @@ function foo(x: any) { x(); } `, - errors: [{ messageId: 'unsafeCall' }], + errors: [ + { + messageId: 'unsafeCall', + line: 3, + column: 3, + endColumn: 4, + data: { + type: '`any`', + }, + }, + ], }, { code: ` @@ -59,7 +69,17 @@ function foo(x: any) { x?.(); } `, - errors: [{ messageId: 'unsafeCall' }], + errors: [ + { + messageId: 'unsafeCall', + line: 3, + column: 3, + endColumn: 4, + data: { + type: '`any`', + }, + }, + ], }, { code: ` @@ -67,7 +87,17 @@ function foo(x: any) { x.a.b.c.d.e.f.g(); } `, - errors: [{ messageId: 'unsafeCall' }], + errors: [ + { + messageId: 'unsafeCall', + line: 3, + column: 3, + endColumn: 18, + data: { + type: '`any`', + }, + }, + ], }, { code: ` @@ -75,7 +105,17 @@ function foo(x: any) { x.a.b.c.d.e.f.g?.(); } `, - errors: [{ messageId: 'unsafeCall' }], + errors: [ + { + messageId: 'unsafeCall', + line: 3, + column: 3, + endColumn: 18, + data: { + type: '`any`', + }, + }, + ], }, { code: ` @@ -83,7 +123,17 @@ function foo(x: { a: any }) { x.a(); } `, - errors: [{ messageId: 'unsafeCall' }], + errors: [ + { + messageId: 'unsafeCall', + line: 3, + column: 3, + endColumn: 6, + data: { + type: '`any`', + }, + }, + ], }, { code: ` @@ -91,7 +141,17 @@ function foo(x: { a: any }) { x?.a(); } `, - errors: [{ messageId: 'unsafeCall' }], + errors: [ + { + messageId: 'unsafeCall', + line: 3, + column: 3, + endColumn: 7, + data: { + type: '`any`', + }, + }, + ], }, { code: ` @@ -99,7 +159,17 @@ function foo(x: { a: any }) { x.a?.(); } `, - errors: [{ messageId: 'unsafeCall' }], + errors: [ + { + messageId: 'unsafeCall', + line: 3, + column: 3, + endColumn: 6, + data: { + type: '`any`', + }, + }, + ], }, { code: ` @@ -168,7 +238,17 @@ const methods = { let value: NotKnown; value(); `, - errors: [{ messageId: 'unsafeCall' }], + errors: [ + { + messageId: 'unsafeCall', + line: 3, + column: 1, + endColumn: 6, + data: { + type: '`error` type', + }, + }, + ], }, ], }); From 2c870ab4f67034090f8f990028779c793b01a177 Mon Sep 17 00:00:00 2001 From: Vincent Girard Date: Sun, 9 Jun 2024 11:29:42 -0400 Subject: [PATCH 4/6] Fixed error message --- packages/eslint-plugin/src/rules/no-unsafe-call.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/eslint-plugin/src/rules/no-unsafe-call.ts b/packages/eslint-plugin/src/rules/no-unsafe-call.ts index a391b82312ad..d8ac595163fe 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-call.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-call.ts @@ -71,7 +71,7 @@ export default createRule<[], MessageIds>({ node: reportingNode, messageId: messageId, data: { - type: isErrorType ? '`error`' : '`any`', + type: isErrorType ? '`error` type' : '`any`', }, }); } From c1390fffd3d1cc6774ebcf942248a696b6e0883c Mon Sep 17 00:00:00 2001 From: Vincent Girard Date: Mon, 17 Jun 2024 09:39:03 -0400 Subject: [PATCH 5/6] Fixed description and message --- packages/eslint-plugin/docs/rules/no-unsafe-call.mdx | 2 +- packages/eslint-plugin/src/rules/no-unsafe-call.ts | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx b/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx index 569cd0fe3546..44874eea174b 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx +++ b/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx @@ -1,5 +1,5 @@ --- -description: 'Disallow calling a value with type an {{type}} value.' +description: 'Disallow calling a value with type an `any` value.' --- import Tabs from '@theme/Tabs'; diff --git a/packages/eslint-plugin/src/rules/no-unsafe-call.ts b/packages/eslint-plugin/src/rules/no-unsafe-call.ts index d8ac595163fe..5de0ad757c13 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-call.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-call.ts @@ -20,12 +20,12 @@ export default createRule<[], MessageIds>({ meta: { type: 'problem', docs: { - description: 'Disallow calling a value with type an {{type}} value', + description: 'Disallow calling a value with type an `any` value', recommended: 'recommended', requiresTypeChecking: true, }, messages: { - unsafeCall: 'Unsafe call of an `any` typed value.', + unsafeCall: 'Unsafe call of an {{type}} typed value.', unsafeCallThis: [ 'Unsafe call of an `any` typed value. `this` is typed as `any`.', 'You can try to fix this by turning on the `noImplicitThis` compiler option, or adding a `this` parameter to the function.', From 2735d4d3e66da762c37e402d4a43ac09b1e7067b Mon Sep 17 00:00:00 2001 From: Vincent Girard Date: Sat, 29 Jun 2024 11:54:05 -0400 Subject: [PATCH 6/6] Applied suggestions --- packages/eslint-plugin/docs/rules/no-unsafe-call.mdx | 2 +- packages/eslint-plugin/src/rules/no-unsafe-call.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx b/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx index 44874eea174b..3e56c1e0f092 100644 --- a/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx +++ b/packages/eslint-plugin/docs/rules/no-unsafe-call.mdx @@ -1,5 +1,5 @@ --- -description: 'Disallow calling a value with type an `any` value.' +description: 'Disallow calling a value with type `any`.' --- import Tabs from '@theme/Tabs'; diff --git a/packages/eslint-plugin/src/rules/no-unsafe-call.ts b/packages/eslint-plugin/src/rules/no-unsafe-call.ts index 5de0ad757c13..f496f02d9155 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-call.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-call.ts @@ -20,7 +20,7 @@ export default createRule<[], MessageIds>({ meta: { type: 'problem', docs: { - description: 'Disallow calling a value with type an `any` value', + description: 'Disallow calling a value with type `any`', recommended: 'recommended', requiresTypeChecking: true, },