From 492130792389f0bd09e897102a6df3cd59cdbd68 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Sat, 9 Nov 2024 22:37:03 +0200 Subject: [PATCH 1/9] initial implementation --- .../src/util/explicitReturnTypeUtils.ts | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts b/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts index fd843b83a0e9..299fdf38fd54 100644 --- a/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts +++ b/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts @@ -176,15 +176,12 @@ function doesImmediatelyReturnFunctionExpression({ /** * Checks if a function belongs to: * ``` - * () => ({ action: 'xxx' } as const) + * ({ action: 'xxx' } as const) * ``` */ -function returnsConstAssertionDirectly( - node: TSESTree.ArrowFunctionExpression, -): boolean { - const { body } = node; - if (isTypeAssertion(body)) { - const { typeAnnotation } = body; +function isConstAssertion(node: TSESTree.Node): boolean { + if (isTypeAssertion(node)) { + const { typeAnnotation } = node; if (typeAnnotation.type === AST_NODE_TYPES.TSTypeReference) { const { typeName } = typeAnnotation; if ( @@ -256,11 +253,20 @@ function isValidFunctionExpressionReturnType( } // https://github.com/typescript-eslint/typescript-eslint/issues/653 - return ( - options.allowDirectConstAssertionInArrowFunctions === true && - node.type === AST_NODE_TYPES.ArrowFunctionExpression && - returnsConstAssertionDirectly(node) - ); + if ( + !options.allowDirectConstAssertionInArrowFunctions || + node.type !== AST_NODE_TYPES.ArrowFunctionExpression + ) { + return false; + } + + const { body } = node; + + if (body.type === AST_NODE_TYPES.TSSatisfiesExpression) { + return isConstAssertion(body.expression); + } + + return isConstAssertion(body); } /** From 60755527167dc7b889ad26dc4652994374a43c79 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Sat, 9 Nov 2024 23:00:25 +0200 Subject: [PATCH 2/9] add tests --- .../explicit-function-return-type.test.ts | 102 +++++++++++++++ .../explicit-module-boundary-types.test.ts | 120 ++++++++++++++++++ 2 files changed, 222 insertions(+) diff --git a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts index 52eafebb8e04..f3bd32997ed1 100644 --- a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts @@ -443,6 +443,24 @@ const func = (value: number) => x as const; }, { code: ` +interface R { + type: string; + value: number; +} + +const func = (value: number) => ({ type: 'X', value }) as const satisfies R; +const func = (value: number) => ({ type: 'X', value }) as const satisfies R; +const func = (value: number) => x as const satisfies R; +const func = (value: number) => x as const satisfies R; + `, + options: [ + { + allowDirectConstAssertionInArrowFunctions: true, + }, + ], + }, + { + code: ` new Promise(resolve => {}); new Foo(1, () => {}); `, @@ -1714,6 +1732,66 @@ const func = (value: number) => ({ type: 'X', value }) as Action; }, { code: ` +interface R { + type: string; + value: number; +} + +const func = (value: number) => ({ type: 'X', value }) satisfies R; +const func = (value: number) => ({ type: 'X', value }) satisfies any; + `, + errors: [ + { + column: 30, + endColumn: 32, + endLine: 7, + line: 7, + messageId: 'missingReturnType', + }, + { + column: 30, + endColumn: 32, + endLine: 8, + line: 8, + messageId: 'missingReturnType', + }, + ], + options: [ + { + allowDirectConstAssertionInArrowFunctions: true, + }, + ], + }, + { + code: ` +const func = (value: number) => ({ type: 'X', value }) as any satisfies any; +const func = (value: number) => + ({ type: 'X', value }) as Action satisfies Action; + `, + errors: [ + { + column: 30, + endColumn: 32, + endLine: 2, + line: 2, + messageId: 'missingReturnType', + }, + { + column: 30, + endColumn: 32, + endLine: 3, + line: 3, + messageId: 'missingReturnType', + }, + ], + options: [ + { + allowDirectConstAssertionInArrowFunctions: true, + }, + ], + }, + { + code: ` const func = (value: number) => ({ type: 'X', value }) as const; `, errors: [ @@ -1731,6 +1809,30 @@ const func = (value: number) => ({ type: 'X', value }) as const; }, ], }, + { + code: ` +interface R { + type: string; + value: number; +} + +const func = (value: number) => ({ type: 'X', value }) as const satisfies R; + `, + errors: [ + { + column: 30, + endColumn: 32, + endLine: 7, + line: 7, + messageId: 'missingReturnType', + }, + ], + options: [ + { + allowDirectConstAssertionInArrowFunctions: false, + }, + ], + }, { code: 'const log = (message: string) => void console.log(message);', errors: [ diff --git a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts index d68e21b70b69..23db0e9d6885 100644 --- a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts @@ -367,6 +367,26 @@ export const func4 = (value: number) => x as const; }, { code: ` +interface R { + type: string; + value: number; +} + +export const func1 = (value: number) => + ({ type: 'X', value }) as const satisfies R; +export const func2 = (value: number) => + ({ type: 'X', value }) as const satisfies R; +export const func3 = (value: number) => x as const satisfies R; +export const func4 = (value: number) => x as const satisfies R; + `, + options: [ + { + allowDirectConstAssertionInArrowFunctions: true, + }, + ], + }, + { + code: ` export const func1 = (value: string) => value; export const func2 = (value: number) => ({ type: 'X', value }); `, @@ -1185,6 +1205,68 @@ export const func2 = (value: number) => ({ type: 'X', value }) as Action; }, { code: ` +interface R { + type: string; + value: number; +} + +export const func1 = (value: number) => ({ type: 'X', value }) satisfies R; +export const func2 = (value: number) => ({ type: 'X', value }) as any; + `, + errors: [ + { + column: 38, + endColumn: 40, + endLine: 7, + line: 7, + messageId: 'missingReturnType', + }, + { + column: 38, + endColumn: 40, + endLine: 8, + line: 8, + messageId: 'missingReturnType', + }, + ], + options: [ + { + allowDirectConstAssertionInArrowFunctions: true, + }, + ], + }, + { + code: ` +export const func1 = (value: number) => + ({ type: 'X', value }) as any satisfies any; + +export const func2 = (value: number) => + ({ type: 'X', value }) as Action satisfies Action; + `, + errors: [ + { + column: 38, + endColumn: 40, + endLine: 2, + line: 2, + messageId: 'missingReturnType', + }, + { + column: 38, + endColumn: 40, + endLine: 5, + line: 5, + messageId: 'missingReturnType', + }, + ], + options: [ + { + allowDirectConstAssertionInArrowFunctions: true, + }, + ], + }, + { + code: ` export const func = (value: number) => ({ type: 'X', value }) as const; `, errors: [ @@ -1204,6 +1286,31 @@ export const func = (value: number) => ({ type: 'X', value }) as const; }, { code: ` +interface R { + type: string; + value: number; +} + +export const func = (value: number) => + ({ type: 'X', value }) as const satisfies R; + `, + errors: [ + { + column: 37, + endColumn: 39, + endLine: 7, + line: 7, + messageId: 'missingReturnType', + }, + ], + options: [ + { + allowDirectConstAssertionInArrowFunctions: false, + }, + ], + }, + { + code: ` export class Test { constructor() {} get prop() { @@ -1364,6 +1471,19 @@ export function foo(outer) { ], options: [{ allowDirectConstAssertionInArrowFunctions: true }], }, + { + code: 'export const baz = arg => arg as const satisfies unknown;', + errors: [ + { + data: { + name: 'arg', + }, + line: 1, + messageId: 'missingArgType', + }, + ], + options: [{ allowDirectConstAssertionInArrowFunctions: true }], + }, { code: ` const foo = arg => arg; From 78caf051fd2c1aa2043c5ac625775a50445e89c4 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Sun, 10 Nov 2024 22:41:26 +0200 Subject: [PATCH 3/9] Update packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Josh Goldberg ✨ --- .../eslint-plugin/src/util/explicitReturnTypeUtils.ts | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts b/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts index 299fdf38fd54..38a0578951bd 100644 --- a/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts +++ b/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts @@ -262,11 +262,9 @@ function isValidFunctionExpressionReturnType( const { body } = node; - if (body.type === AST_NODE_TYPES.TSSatisfiesExpression) { - return isConstAssertion(body.expression); - } - - return isConstAssertion(body); + return isConstAssertion( + body.type === AST_NODE_TYPES.TSSatisfiesExpression ? body.expression : body, + ); } /** From 492be7dacabd50ab0d5ae3347160f3391663de93 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Sun, 10 Nov 2024 22:41:55 +0200 Subject: [PATCH 4/9] simplify tests, one test per case --- .../explicit-function-return-type.test.ts | 87 ++++---------- .../explicit-module-boundary-types.test.ts | 109 ++++-------------- 2 files changed, 46 insertions(+), 150 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts index f3bd32997ed1..9e4d08ea6f72 100644 --- a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts @@ -449,9 +449,26 @@ interface R { } const func = (value: number) => ({ type: 'X', value }) as const satisfies R; -const func = (value: number) => ({ type: 'X', value }) as const satisfies R; -const func = (value: number) => x as const satisfies R; -const func = (value: number) => x as const satisfies R; + `, + options: [ + { + allowDirectConstAssertionInArrowFunctions: true, + }, + ], + }, + { + code: ` +const func = (value: number) => x as const satisfies number; + `, + options: [ + { + allowDirectConstAssertionInArrowFunctions: true, + }, + ], + }, + { + code: ` +const func = (value: number) => x as const satisfies string; `, options: [ { @@ -1732,66 +1749,6 @@ const func = (value: number) => ({ type: 'X', value }) as Action; }, { code: ` -interface R { - type: string; - value: number; -} - -const func = (value: number) => ({ type: 'X', value }) satisfies R; -const func = (value: number) => ({ type: 'X', value }) satisfies any; - `, - errors: [ - { - column: 30, - endColumn: 32, - endLine: 7, - line: 7, - messageId: 'missingReturnType', - }, - { - column: 30, - endColumn: 32, - endLine: 8, - line: 8, - messageId: 'missingReturnType', - }, - ], - options: [ - { - allowDirectConstAssertionInArrowFunctions: true, - }, - ], - }, - { - code: ` -const func = (value: number) => ({ type: 'X', value }) as any satisfies any; -const func = (value: number) => - ({ type: 'X', value }) as Action satisfies Action; - `, - errors: [ - { - column: 30, - endColumn: 32, - endLine: 2, - line: 2, - messageId: 'missingReturnType', - }, - { - column: 30, - endColumn: 32, - endLine: 3, - line: 3, - messageId: 'missingReturnType', - }, - ], - options: [ - { - allowDirectConstAssertionInArrowFunctions: true, - }, - ], - }, - { - code: ` const func = (value: number) => ({ type: 'X', value }) as const; `, errors: [ @@ -1822,8 +1779,8 @@ const func = (value: number) => ({ type: 'X', value }) as const satisfies R; { column: 30, endColumn: 32, - endLine: 7, - line: 7, + endLine: 2, + line: 2, messageId: 'missingReturnType', }, ], diff --git a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts index 23db0e9d6885..748c7ddad5c8 100644 --- a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts @@ -372,12 +372,27 @@ interface R { value: number; } -export const func1 = (value: number) => - ({ type: 'X', value }) as const satisfies R; -export const func2 = (value: number) => - ({ type: 'X', value }) as const satisfies R; -export const func3 = (value: number) => x as const satisfies R; -export const func4 = (value: number) => x as const satisfies R; +const func1 = (value: number) => ({ type: 'X', value }) as const satisfies R; + `, + options: [ + { + allowDirectConstAssertionInArrowFunctions: true, + }, + ], + }, + { + code: ` +const func4 = (value: number) => x as const satisfies number; + `, + options: [ + { + allowDirectConstAssertionInArrowFunctions: true, + }, + ], + }, + { + code: ` +const func4 = (value: number) => x as const satisfies string; `, options: [ { @@ -1205,68 +1220,6 @@ export const func2 = (value: number) => ({ type: 'X', value }) as Action; }, { code: ` -interface R { - type: string; - value: number; -} - -export const func1 = (value: number) => ({ type: 'X', value }) satisfies R; -export const func2 = (value: number) => ({ type: 'X', value }) as any; - `, - errors: [ - { - column: 38, - endColumn: 40, - endLine: 7, - line: 7, - messageId: 'missingReturnType', - }, - { - column: 38, - endColumn: 40, - endLine: 8, - line: 8, - messageId: 'missingReturnType', - }, - ], - options: [ - { - allowDirectConstAssertionInArrowFunctions: true, - }, - ], - }, - { - code: ` -export const func1 = (value: number) => - ({ type: 'X', value }) as any satisfies any; - -export const func2 = (value: number) => - ({ type: 'X', value }) as Action satisfies Action; - `, - errors: [ - { - column: 38, - endColumn: 40, - endLine: 2, - line: 2, - messageId: 'missingReturnType', - }, - { - column: 38, - endColumn: 40, - endLine: 5, - line: 5, - messageId: 'missingReturnType', - }, - ], - options: [ - { - allowDirectConstAssertionInArrowFunctions: true, - }, - ], - }, - { - code: ` export const func = (value: number) => ({ type: 'X', value }) as const; `, errors: [ @@ -1291,15 +1244,14 @@ interface R { value: number; } -export const func = (value: number) => - ({ type: 'X', value }) as const satisfies R; +const func = (value: number) => ({ type: 'X', value }) as const satisfies R; `, errors: [ { column: 37, endColumn: 39, - endLine: 7, - line: 7, + endLine: 2, + line: 2, messageId: 'missingReturnType', }, ], @@ -1471,19 +1423,6 @@ export function foo(outer) { ], options: [{ allowDirectConstAssertionInArrowFunctions: true }], }, - { - code: 'export const baz = arg => arg as const satisfies unknown;', - errors: [ - { - data: { - name: 'arg', - }, - line: 1, - messageId: 'missingArgType', - }, - ], - options: [{ allowDirectConstAssertionInArrowFunctions: true }], - }, { code: ` const foo = arg => arg; From dbaf9fa5d0c7f628e10a13e068cb64d84f0a6115 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Sun, 10 Nov 2024 23:16:15 +0200 Subject: [PATCH 5/9] fix failing tests --- .../rules/explicit-function-return-type.test.ts | 4 ++-- .../rules/explicit-module-boundary-types.test.ts | 14 ++++++++------ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts index 9e4d08ea6f72..96a72b9ee671 100644 --- a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts @@ -1779,8 +1779,8 @@ const func = (value: number) => ({ type: 'X', value }) as const satisfies R; { column: 30, endColumn: 32, - endLine: 2, - line: 2, + endLine: 7, + line: 7, messageId: 'missingReturnType', }, ], diff --git a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts index 748c7ddad5c8..d67a08c211e0 100644 --- a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts @@ -372,7 +372,8 @@ interface R { value: number; } -const func1 = (value: number) => ({ type: 'X', value }) as const satisfies R; +export const func1 = (value: number) => + ({ type: 'X', value }) as const satisfies R; `, options: [ { @@ -382,7 +383,7 @@ const func1 = (value: number) => ({ type: 'X', value }) as const satisfies R; }, { code: ` -const func4 = (value: number) => x as const satisfies number; +export const func4 = (value: number) => x as const satisfies number; `, options: [ { @@ -392,7 +393,7 @@ const func4 = (value: number) => x as const satisfies number; }, { code: ` -const func4 = (value: number) => x as const satisfies string; +export const func4 = (value: number) => x as const satisfies string; `, options: [ { @@ -1244,14 +1245,15 @@ interface R { value: number; } -const func = (value: number) => ({ type: 'X', value }) as const satisfies R; +export const func = (value: number) => + ({ type: 'X', value }) as const satisfies R; `, errors: [ { column: 37, endColumn: 39, - endLine: 2, - line: 2, + endLine: 7, + line: 7, messageId: 'missingReturnType', }, ], From b39e1894a145d03b72cd79c8ea55685e91d97508 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Mon, 11 Nov 2024 20:49:42 +0200 Subject: [PATCH 6/9] Update packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts Co-authored-by: Kirk Waiblinger --- .../eslint-plugin/src/util/explicitReturnTypeUtils.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts b/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts index 38a0578951bd..e498d373a3e4 100644 --- a/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts +++ b/packages/eslint-plugin/src/util/explicitReturnTypeUtils.ts @@ -260,11 +260,12 @@ function isValidFunctionExpressionReturnType( return false; } - const { body } = node; + let body = node.body; + while (body.type === AST_NODE_TYPES.TSSatisfiesExpression) { + body = body.expression; + } - return isConstAssertion( - body.type === AST_NODE_TYPES.TSSatisfiesExpression ? body.expression : body, - ); + return isConstAssertion(body); } /** From 6e64bee92223b6de4f3d0700f2c1a520d8ba5b8d Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Mon, 11 Nov 2024 20:52:43 +0200 Subject: [PATCH 7/9] add tests for nested satisfies statements --- .../explicit-function-return-type.test.ts | 21 +++++++++++++++++++ .../explicit-module-boundary-types.test.ts | 11 ++++++++++ 2 files changed, 32 insertions(+) diff --git a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts index 96a72b9ee671..838d10ef1ed2 100644 --- a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts @@ -468,6 +468,27 @@ const func = (value: number) => x as const satisfies number; }, { code: ` +const func = (value: number) => x as const satisfies 10 satisfies number; + `, + options: [ + { + allowDirectConstAssertionInArrowFunctions: true, + }, + ], + }, + { + code: ` +const func = (value: number) => + x as const satisfies 10 satisfies number satisfies any; + `, + options: [ + { + allowDirectConstAssertionInArrowFunctions: true, + }, + ], + }, + { + code: ` const func = (value: number) => x as const satisfies string; `, options: [ diff --git a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts index d67a08c211e0..0fa6fadac715 100644 --- a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts @@ -393,6 +393,17 @@ export const func4 = (value: number) => x as const satisfies number; }, { code: ` +export const func4 = (value: number) => + x as const satisfies 10 satisfies number satisfies any; + `, + options: [ + { + allowDirectConstAssertionInArrowFunctions: true, + }, + ], + }, + { + code: ` export const func4 = (value: number) => x as const satisfies string; `, options: [ From d7a918302ae8d94ae86ea5876434968561635c85 Mon Sep 17 00:00:00 2001 From: Ronen Amiel Date: Mon, 11 Nov 2024 21:31:33 +0200 Subject: [PATCH 8/9] use valid typescript code for tests --- .../explicit-function-return-type.test.ts | 35 +++++++------------ .../explicit-module-boundary-types.test.ts | 29 +++++++-------- 2 files changed, 27 insertions(+), 37 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts index 838d10ef1ed2..1f68214163b1 100644 --- a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts @@ -458,28 +458,12 @@ const func = (value: number) => ({ type: 'X', value }) as const satisfies R; }, { code: ` -const func = (value: number) => x as const satisfies number; - `, - options: [ - { - allowDirectConstAssertionInArrowFunctions: true, - }, - ], - }, - { - code: ` -const func = (value: number) => x as const satisfies 10 satisfies number; - `, - options: [ - { - allowDirectConstAssertionInArrowFunctions: true, - }, - ], - }, - { - code: ` -const func = (value: number) => - x as const satisfies 10 satisfies number satisfies any; +interface R { + type: string; + value: number; +} + +const func = (value: number) => ({ type: 'X', value }) as const satisfies R satisfies R; `, options: [ { @@ -489,7 +473,12 @@ const func = (value: number) => }, { code: ` -const func = (value: number) => x as const satisfies string; +interface R { + type: string; + value: number; +} + +const func = (value: number) => ({ type: 'X', value }) as const satisfies R satisfies R satisfies R; `, options: [ { diff --git a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts index 0fa6fadac715..45deb7d1124f 100644 --- a/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-module-boundary-types.test.ts @@ -372,7 +372,7 @@ interface R { value: number; } -export const func1 = (value: number) => +export const func = (value: number) => ({ type: 'X', value }) as const satisfies R; `, options: [ @@ -383,18 +383,13 @@ export const func1 = (value: number) => }, { code: ` -export const func4 = (value: number) => x as const satisfies number; - `, - options: [ - { - allowDirectConstAssertionInArrowFunctions: true, - }, - ], - }, - { - code: ` -export const func4 = (value: number) => - x as const satisfies 10 satisfies number satisfies any; +interface R { + type: string; + value: number; +} + +export const func = (value: number) => + ({ type: 'X', value }) as const satisfies R satisfies R; `, options: [ { @@ -404,7 +399,13 @@ export const func4 = (value: number) => }, { code: ` -export const func4 = (value: number) => x as const satisfies string; +interface R { + type: string; + value: number; +} + +export const func = (value: number) => + ({ type: 'X', value }) as const satisfies R satisfies R satisfies R; `, options: [ { From f34addc981cc5c9fbe2015c3dc21fd4d07381b47 Mon Sep 17 00:00:00 2001 From: Brad Zacher Date: Fri, 15 Nov 2024 19:57:43 -0800 Subject: [PATCH 9/9] Update explicit-function-return-type.test.ts --- .../tests/rules/explicit-function-return-type.test.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts index 1f68214163b1..e02e701da7de 100644 --- a/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts +++ b/packages/eslint-plugin/tests/rules/explicit-function-return-type.test.ts @@ -463,7 +463,8 @@ interface R { value: number; } -const func = (value: number) => ({ type: 'X', value }) as const satisfies R satisfies R; +const func = (value: number) => + ({ type: 'X', value }) as const satisfies R satisfies R; `, options: [ { @@ -478,7 +479,8 @@ interface R { value: number; } -const func = (value: number) => ({ type: 'X', value }) as const satisfies R satisfies R satisfies R; +const func = (value: number) => + ({ type: 'X', value }) as const satisfies R satisfies R satisfies R; `, options: [ {