diff --git a/packages/eslint-plugin/src/rules/no-unsafe-return.ts b/packages/eslint-plugin/src/rules/no-unsafe-return.ts index ef308450bd80..ae959627c09d 100644 --- a/packages/eslint-plugin/src/rules/no-unsafe-return.ts +++ b/packages/eslint-plugin/src/rules/no-unsafe-return.ts @@ -28,7 +28,7 @@ export default createRule({ requiresTypeChecking: true, }, messages: { - unsafeReturn: 'Unsafe return of an `{{type}}` typed value.', + unsafeReturn: 'Unsafe return of an {{type}} typed value.', unsafeReturnThis: [ 'Unsafe return of an `{{type}}` 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.', @@ -137,6 +137,7 @@ export default createRule({ } let messageId: 'unsafeReturn' | 'unsafeReturnThis' = 'unsafeReturn'; + const isErrorType = tsutils.isIntrinsicErrorType(returnNodeType); if (!isNoImplicitThis) { // `return this` @@ -156,7 +157,11 @@ export default createRule({ node: reportingNode, messageId, data: { - type: anyType === AnyType.Any ? 'any' : 'any[]', + type: isErrorType + ? 'error' + : anyType === AnyType.Any + ? '`any`' + : '`any[]`', }, }); } diff --git a/packages/eslint-plugin/tests/rules/no-unsafe-return.test.ts b/packages/eslint-plugin/tests/rules/no-unsafe-return.test.ts index 36c6103bbc20..dc5e1df369d6 100644 --- a/packages/eslint-plugin/tests/rules/no-unsafe-return.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unsafe-return.test.ts @@ -139,7 +139,7 @@ function foo() { { messageId: 'unsafeReturn', data: { - type: 'any', + type: '`any`', }, }, ], @@ -154,7 +154,7 @@ function foo() { { messageId: 'unsafeReturn', data: { - type: 'any', + type: '`any`', }, }, ], @@ -169,7 +169,7 @@ const foo = () => { { messageId: 'unsafeReturn', data: { - type: 'any', + type: '`any`', }, }, ], @@ -180,7 +180,7 @@ const foo = () => { { messageId: 'unsafeReturn', data: { - type: 'any', + type: '`any`', }, }, ], @@ -195,7 +195,7 @@ function foo() { { messageId: 'unsafeReturn', data: { - type: 'any[]', + type: '`any[]`', }, }, ], @@ -210,7 +210,7 @@ function foo() { { messageId: 'unsafeReturn', data: { - type: 'any[]', + type: '`any[]`', }, }, ], @@ -225,7 +225,7 @@ function foo() { { messageId: 'unsafeReturn', data: { - type: 'any[]', + type: '`any[]`', }, }, ], @@ -240,7 +240,7 @@ function foo() { { messageId: 'unsafeReturn', data: { - type: 'any[]', + type: '`any[]`', }, }, ], @@ -255,7 +255,7 @@ const foo = () => { { messageId: 'unsafeReturn', data: { - type: 'any[]', + type: '`any[]`', }, }, ], @@ -266,7 +266,7 @@ const foo = () => { { messageId: 'unsafeReturn', data: { - type: 'any[]', + type: '`any[]`', }, }, ], @@ -407,12 +407,18 @@ function bar() { line: 3, column: 3, endColumn: 15, + data: { + type: '`any`', + }, }, { messageId: 'unsafeReturnThis', line: 7, column: 16, endColumn: 20, + data: { + type: '`any`', + }, }, ], }, @@ -427,6 +433,29 @@ foo(() => 'foo' as any); line: 3, column: 11, endColumn: 23, + data: { + type: '`any`', + }, + }, + ], + }, + { + code: ` +let value: NotKnown; + +function example() { + return value; +} + `, + errors: [ + { + messageId: 'unsafeReturn', + line: 5, + column: 3, + endColumn: 16, + data: { + type: 'error', + }, }, ], },