From f4d5daeb5ac92f90f293b4b43f1f800e66ac4f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=AC=EC=9A=B1?= Date: Mon, 28 Jul 2025 19:31:03 +0900 Subject: [PATCH 1/3] Chore: add test cases for no-floating-promises allowForKnownSafeCalls option Add test cases to verify that function name-based allowForKnownSafeCalls configuration works correctly for locally defined async functions. --- .../tests/rules/no-floating-promises.test.ts | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/packages/eslint-plugin/tests/rules/no-floating-promises.test.ts b/packages/eslint-plugin/tests/rules/no-floating-promises.test.ts index 4835087e7cb6..dc4ee2e3cab8 100644 --- a/packages/eslint-plugin/tests/rules/no-floating-promises.test.ts +++ b/packages/eslint-plugin/tests/rules/no-floating-promises.test.ts @@ -866,6 +866,34 @@ declare function createMyThenable(): MyThenable; createMyThenable(); `, + { + code: ` +const randomAsyncFunction = async () => { + return Promise.resolve(true); +}; + +randomAsyncFunction(); + `, + options: [ + { + allowForKnownSafeCalls: ['randomAsyncFunction'], + }, + ], + }, + { + code: ` +async function myAsyncFunction() { + return Promise.resolve('test'); +} + +myAsyncFunction(); + `, + options: [ + { + allowForKnownSafeCalls: ['myAsyncFunction'], + }, + ], + }, ], invalid: [ From 8c1cc909dca363df8c467d6a5893707c30075c82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=AC=EC=9A=B1?= Date: Mon, 28 Jul 2025 19:32:24 +0900 Subject: [PATCH 2/3] Fix: no-floating-promises allowForKnownSafeCalls not working for function names (#11423) The allowForKnownSafeCalls option was only checking type-based matching and not value-based matching, causing function name specifications like ["myAsyncFunction"] to be ignored. Now properly checks both value and type matching using valueMatchesSomeSpecifier. --- .../eslint-plugin/src/rules/no-floating-promises.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/packages/eslint-plugin/src/rules/no-floating-promises.ts b/packages/eslint-plugin/src/rules/no-floating-promises.ts index 50965093ee98..8a46b328c464 100644 --- a/packages/eslint-plugin/src/rules/no-floating-promises.ts +++ b/packages/eslint-plugin/src/rules/no-floating-promises.ts @@ -16,6 +16,7 @@ import { readonlynessOptionsSchema, skipChainExpression, typeMatchesSomeSpecifier, + valueMatchesSomeSpecifier, } from '../util'; import { parseCatchCall, @@ -242,6 +243,17 @@ export default createRule({ const type = services.getTypeAtLocation(node.callee); + if ( + valueMatchesSomeSpecifier( + node.callee, + allowForKnownSafeCalls, + services.program, + type, + ) + ) { + return true; + } + return typeMatchesSomeSpecifier( type, allowForKnownSafeCalls, From af92aeac3fc0816d6cc1e34b6c2b7bafee933f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9E=AC=EC=9A=B1?= Date: Mon, 28 Jul 2025 22:12:12 +0900 Subject: [PATCH 3/3] Chore: update docs and snapshots for no-floating-promises fix - Remove skipValidation from allowForKnownSafeCalls example - Update test snapshots after fixing function name matching --- .../snapshots/2-TSESTree-Tokens.shot | 4 +- .../snapshots/6-AST-Alignment-Tokens.shot | 6 +-- .../snapshots/2-TSESTree-Tokens.shot | 4 +- .../snapshots/6-AST-Alignment-Tokens.shot | 6 +-- .../snapshots/2-TSESTree-Tokens.shot | 28 ++++++------- .../snapshots/6-AST-Alignment-Tokens.shot | 42 +++++++------------ .../snapshots/2-TSESTree-Tokens.shot | 8 ++-- .../snapshots/6-AST-Alignment-Tokens.shot | 12 ++---- .../docs/rules/no-floating-promises.mdx | 2 +- .../no-floating-promises.shot | 1 - 10 files changed, 45 insertions(+), 68 deletions(-) diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/typed-this/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/typed-this/snapshots/2-TSESTree-Tokens.shot index 573d00dfabbf..c7bbf886221e 100644 --- a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/typed-this/snapshots/2-TSESTree-Tokens.shot +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/typed-this/snapshots/2-TSESTree-Tokens.shot @@ -79,8 +79,8 @@ end: { column: 29, line: 4 }, }, }, - Keyword { - type: "Keyword", + Identifier { + type: "Identifier", value: "this", range: [124, 128], diff --git a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/typed-this/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/typed-this/snapshots/6-AST-Alignment-Tokens.shot index cf45b4578a48..e60f93635f64 100644 --- a/packages/ast-spec/src/legacy-fixtures/basics/fixtures/typed-this/snapshots/6-AST-Alignment-Tokens.shot +++ b/packages/ast-spec/src/legacy-fixtures/basics/fixtures/typed-this/snapshots/6-AST-Alignment-Tokens.shot @@ -88,10 +88,8 @@ Snapshot Diff: end: { column: 29, line: 4 }, }, }, -- Keyword { -- type: 'Keyword', -+ Identifier { -+ type: 'Identifier', + Identifier { + type: 'Identifier', value: 'this', range: [124, 128], diff --git a/packages/ast-spec/src/legacy-fixtures/types/fixtures/function-with-this/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/legacy-fixtures/types/fixtures/function-with-this/snapshots/2-TSESTree-Tokens.shot index 4ed3f2a15270..7384c5b71f9c 100644 --- a/packages/ast-spec/src/legacy-fixtures/types/fixtures/function-with-this/snapshots/2-TSESTree-Tokens.shot +++ b/packages/ast-spec/src/legacy-fixtures/types/fixtures/function-with-this/snapshots/2-TSESTree-Tokens.shot @@ -39,8 +39,8 @@ end: { column: 8, line: 3 }, }, }, - Keyword { - type: "Keyword", + Identifier { + type: "Identifier", value: "this", range: [81, 85], diff --git a/packages/ast-spec/src/legacy-fixtures/types/fixtures/function-with-this/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/legacy-fixtures/types/fixtures/function-with-this/snapshots/6-AST-Alignment-Tokens.shot index 4dd08bd918b5..f2753dc6195f 100644 --- a/packages/ast-spec/src/legacy-fixtures/types/fixtures/function-with-this/snapshots/6-AST-Alignment-Tokens.shot +++ b/packages/ast-spec/src/legacy-fixtures/types/fixtures/function-with-this/snapshots/6-AST-Alignment-Tokens.shot @@ -48,10 +48,8 @@ Snapshot Diff: end: { column: 8, line: 3 }, }, }, -- Keyword { -- type: 'Keyword', -+ Identifier { -+ type: 'Identifier', + Identifier { + type: 'Identifier', value: 'this', range: [81, 85], diff --git a/packages/ast-spec/src/legacy-fixtures/types/fixtures/this-type-expanded/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/legacy-fixtures/types/fixtures/this-type-expanded/snapshots/2-TSESTree-Tokens.shot index 1deb60e039ac..f41521a4d6ef 100644 --- a/packages/ast-spec/src/legacy-fixtures/types/fixtures/this-type-expanded/snapshots/2-TSESTree-Tokens.shot +++ b/packages/ast-spec/src/legacy-fixtures/types/fixtures/this-type-expanded/snapshots/2-TSESTree-Tokens.shot @@ -109,8 +109,8 @@ end: { column: 16, line: 6 }, }, }, - Keyword { - type: "Keyword", + Identifier { + type: "Identifier", value: "this", range: [120, 124], @@ -269,8 +269,8 @@ end: { column: 17, line: 10 }, }, }, - Keyword { - type: "Keyword", + Identifier { + type: "Identifier", value: "this", range: [183, 187], @@ -429,8 +429,8 @@ end: { column: 17, line: 14 }, }, }, - Keyword { - type: "Keyword", + Identifier { + type: "Identifier", value: "this", range: [241, 245], @@ -689,8 +689,8 @@ end: { column: 17, line: 19 }, }, }, - Keyword { - type: "Keyword", + Identifier { + type: "Identifier", value: "this", range: [329, 333], @@ -949,8 +949,8 @@ end: { column: 22, line: 24 }, }, }, - Keyword { - type: "Keyword", + Identifier { + type: "Identifier", value: "this", range: [419, 423], @@ -1089,8 +1089,8 @@ end: { column: 8, line: 28 }, }, }, - Keyword { - type: "Keyword", + Identifier { + type: "Identifier", value: "typeof", range: [471, 477], @@ -1109,8 +1109,8 @@ end: { column: 16, line: 28 }, }, }, - Keyword { - type: "Keyword", + Identifier { + type: "Identifier", value: "this", range: [478, 482], diff --git a/packages/ast-spec/src/legacy-fixtures/types/fixtures/this-type-expanded/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/legacy-fixtures/types/fixtures/this-type-expanded/snapshots/6-AST-Alignment-Tokens.shot index a00c84b46b57..3abc427e91f4 100644 --- a/packages/ast-spec/src/legacy-fixtures/types/fixtures/this-type-expanded/snapshots/6-AST-Alignment-Tokens.shot +++ b/packages/ast-spec/src/legacy-fixtures/types/fixtures/this-type-expanded/snapshots/6-AST-Alignment-Tokens.shot @@ -120,10 +120,8 @@ Snapshot Diff: end: { column: 16, line: 6 }, }, }, -- Keyword { -- type: 'Keyword', -+ Identifier { -+ type: 'Identifier', + Identifier { + type: 'Identifier', value: 'this', range: [120, 124], @@ -284,10 +282,8 @@ Snapshot Diff: end: { column: 17, line: 10 }, }, }, -- Keyword { -- type: 'Keyword', -+ Identifier { -+ type: 'Identifier', + Identifier { + type: 'Identifier', value: 'this', range: [183, 187], @@ -448,10 +444,8 @@ Snapshot Diff: end: { column: 17, line: 14 }, }, }, -- Keyword { -- type: 'Keyword', -+ Identifier { -+ type: 'Identifier', + Identifier { + type: 'Identifier', value: 'this', range: [241, 245], @@ -712,10 +706,8 @@ Snapshot Diff: end: { column: 17, line: 19 }, }, }, -- Keyword { -- type: 'Keyword', -+ Identifier { -+ type: 'Identifier', + Identifier { + type: 'Identifier', value: 'this', range: [329, 333], @@ -974,10 +966,8 @@ Snapshot Diff: end: { column: 22, line: 24 }, }, }, -- Keyword { -- type: 'Keyword', -+ Identifier { -+ type: 'Identifier', + Identifier { + type: 'Identifier', value: 'this', range: [419, 423], @@ -1116,10 +1106,8 @@ Snapshot Diff: end: { column: 8, line: 28 }, }, }, -- Keyword { -- type: 'Keyword', -+ Identifier { -+ type: 'Identifier', + Identifier { + type: 'Identifier', value: 'typeof', range: [471, 477], @@ -1138,10 +1126,8 @@ Snapshot Diff: end: { column: 16, line: 28 }, }, }, -- Keyword { -- type: 'Keyword', -+ Identifier { -+ type: 'Identifier', + Identifier { + type: 'Identifier', value: 'this', range: [478, 482], diff --git a/packages/ast-spec/src/legacy-fixtures/types/fixtures/typeof-this/snapshots/2-TSESTree-Tokens.shot b/packages/ast-spec/src/legacy-fixtures/types/fixtures/typeof-this/snapshots/2-TSESTree-Tokens.shot index accecbdf3e6c..9257d8476df2 100644 --- a/packages/ast-spec/src/legacy-fixtures/types/fixtures/typeof-this/snapshots/2-TSESTree-Tokens.shot +++ b/packages/ast-spec/src/legacy-fixtures/types/fixtures/typeof-this/snapshots/2-TSESTree-Tokens.shot @@ -39,8 +39,8 @@ end: { column: 16, line: 3 }, }, }, - Keyword { - type: "Keyword", + Identifier { + type: "Identifier", value: "this", range: [90, 94], @@ -99,8 +99,8 @@ end: { column: 15, line: 4 }, }, }, - Keyword { - type: "Keyword", + Identifier { + type: "Identifier", value: "this", range: [112, 116], diff --git a/packages/ast-spec/src/legacy-fixtures/types/fixtures/typeof-this/snapshots/6-AST-Alignment-Tokens.shot b/packages/ast-spec/src/legacy-fixtures/types/fixtures/typeof-this/snapshots/6-AST-Alignment-Tokens.shot index c76669826b20..fdcc7a211dbb 100644 --- a/packages/ast-spec/src/legacy-fixtures/types/fixtures/typeof-this/snapshots/6-AST-Alignment-Tokens.shot +++ b/packages/ast-spec/src/legacy-fixtures/types/fixtures/typeof-this/snapshots/6-AST-Alignment-Tokens.shot @@ -48,10 +48,8 @@ Snapshot Diff: end: { column: 16, line: 3 }, }, }, -- Keyword { -- type: 'Keyword', -+ Identifier { -+ type: 'Identifier', + Identifier { + type: 'Identifier', value: 'this', range: [90, 94], @@ -112,10 +110,8 @@ Snapshot Diff: end: { column: 15, line: 4 }, }, }, -- Keyword { -- type: 'Keyword', -+ Identifier { -+ type: 'Identifier', + Identifier { + type: 'Identifier', value: 'this', range: [112, 116], diff --git a/packages/eslint-plugin/docs/rules/no-floating-promises.mdx b/packages/eslint-plugin/docs/rules/no-floating-promises.mdx index 12bf7465b537..977b10b2a078 100644 --- a/packages/eslint-plugin/docs/rules/no-floating-promises.mdx +++ b/packages/eslint-plugin/docs/rules/no-floating-promises.mdx @@ -258,7 +258,7 @@ unsafe('...', () => {}); -```ts option='{"allowForKnownSafeCalls":[{"from":"file","name":"safe","path":"input.ts"}]}' skipValidation +```ts option='{"allowForKnownSafeCalls":[{"from":"file","name":"safe","path":"input.ts"}]}' declare function safe(...args: unknown[]): Promise; safe('...', () => {}); diff --git a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/no-floating-promises.shot b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/no-floating-promises.shot index 8cdd60d375d6..9a5130ce0c07 100644 --- a/packages/eslint-plugin/tests/docs-eslint-output-snapshots/no-floating-promises.shot +++ b/packages/eslint-plugin/tests/docs-eslint-output-snapshots/no-floating-promises.shot @@ -135,4 +135,3 @@ Options: {"allowForKnownSafeCalls":[{"from":"file","name":"safe","path":"input.t declare function safe(...args: unknown[]): Promise; safe('...', () => {}); -~~~~~~~~~~~~~~~~~~~~~~ Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator.