Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/eslint-plugin/src/rules/no-unsafe-call.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.',
Expand Down Expand Up @@ -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`',
},
});
}
}
Expand Down
101 changes: 94 additions & 7 deletions packages/eslint-plugin/tests/rules/no-unsafe-call.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,55 +51,125 @@ function foo(x: any) {
x();
}
`,
errors: [{ messageId: 'unsafeCall' }],
errors: [
{
messageId: 'unsafeCall',
line: 3,
column: 3,
endColumn: 4,
data: {
type: '`any`',
},
},
],
},
{
code: `
function foo(x: any) {
x?.();
}
`,
errors: [{ messageId: 'unsafeCall' }],
errors: [
{
messageId: 'unsafeCall',
line: 3,
column: 3,
endColumn: 4,
data: {
type: '`any`',
},
},
],
},
{
code: `
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: `
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: `
function foo(x: { a: any }) {
x.a();
}
`,
errors: [{ messageId: 'unsafeCall' }],
errors: [
{
messageId: 'unsafeCall',
line: 3,
column: 3,
endColumn: 6,
data: {
type: '`any`',
},
},
],
},
{
code: `
function foo(x: { a: any }) {
x?.a();
}
`,
errors: [{ messageId: 'unsafeCall' }],
errors: [
{
messageId: 'unsafeCall',
line: 3,
column: 3,
endColumn: 7,
data: {
type: '`any`',
},
},
],
},
{
code: `
function foo(x: { a: any }) {
x.a?.();
}
`,
errors: [{ messageId: 'unsafeCall' }],
errors: [
{
messageId: 'unsafeCall',
line: 3,
column: 3,
endColumn: 6,
data: {
type: '`any`',
},
},
],
},
{
code: `
Expand Down Expand Up @@ -163,5 +233,22 @@ const methods = {
},
],
},
{
code: `
let value: NotKnown;
value();
`,
errors: [
{
messageId: 'unsafeCall',
line: 3,
column: 1,
endColumn: 6,
data: {
type: '`error` type',
},
},
],
},
],
});