diff --git a/packages/eslint-plugin/src/rules/no-unsafe-call.ts b/packages/eslint-plugin/src/rules/no-unsafe-call.ts index b4ec6379f2e1..f496f02d9155 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-call.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-call.ts @@ -25,7 +25,7 @@ export default createRule<[], MessageIds>({ 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.', @@ -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` type' : '`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..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: ` @@ -163,5 +233,22 @@ const methods = { }, ], }, + { + code: ` +let value: NotKnown; +value(); + `, + errors: [ + { + messageId: 'unsafeCall', + line: 3, + column: 1, + endColumn: 6, + data: { + type: '`error` type', + }, + }, + ], + }, ], });