Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit fd8e822

Browse files
committed
Add rule @typescript-eslint/no-floating-promises
1 parent 05966e5 commit fd8e822

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/rules/typescript-eslint/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import type { NamingConventionRule } from './naming-convention';
1616
import type { NoEmptyFunctionRule } from './no-empty-function';
1717
import type { NoEmptyInterfaceRule } from './no-empty-interface';
1818
import type { NoExplicitAnyRule } from './no-explicit-any';
19+
import type { NoFloatingPromisesRule } from './no-floating-promises';
1920
import type { NoInferrableTypesRule } from './no-inferrable-types';
2021
import type { NoParameterPropertiesRule } from './no-parameter-properties';
2122
import type { NoUnsafeAssignmentRule } from './no-unsafe-assignment';
@@ -48,6 +49,7 @@ export type TypeScriptEslintRules = AdjacentOverloadSignaturesRule &
4849
NoEmptyFunctionRule &
4950
NoEmptyInterfaceRule &
5051
NoExplicitAnyRule &
52+
NoFloatingPromisesRule &
5153
NoInferrableTypesRule &
5254
NoParameterPropertiesRule &
5355
NoUnsafeAssignmentRule &
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export type NoFloatingPromisesOption = {
7+
/**
8+
* This allows you to stop the rule reporting promises consumed with void operator. This can be a good way to explicitly mark a promise as intentionally not awaited.
9+
*
10+
* @default true
11+
*
12+
* @see [ignoreVoid](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-floating-promises.md#ignorevoid)
13+
*/
14+
ignoreVoid?: boolean;
15+
/**
16+
* This allows you to skip checking of async iife.
17+
*
18+
* @default false
19+
*
20+
* @see [ignoreIIFE](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-floating-promises.md#ignoreiife)
21+
*/
22+
ignoreIIFE?: boolean;
23+
};
24+
25+
/**
26+
* Options.
27+
*/
28+
export type NoFloatingPromisesOptions = [NoFloatingPromisesOption?];
29+
30+
/**
31+
* Requires Promise-like values to be handled appropriately.
32+
*
33+
* This rule forbids usage of Promise-like values in statements without handling their errors appropriately.
34+
* Unhandled promises can cause several issues, such as improperly sequenced operations, ignored Promise rejections and more.
35+
* Valid ways of handling a Promise-valued statement include awaiting, returning, and either calling `.then()` with two arguments or `.catch()` with one argument.
36+
*
37+
* @see [no-floating-promises](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-floating-promises.md)
38+
*/
39+
export type NoFloatingPromisesRuleConfig = RuleConfig<NoFloatingPromisesOptions>;
40+
41+
/**
42+
* Requires Promise-like values to be handled appropriately.
43+
*
44+
* This rule forbids usage of Promise-like values in statements without handling their errors appropriately.
45+
* Unhandled promises can cause several issues, such as improperly sequenced operations, ignored Promise rejections and more.
46+
* Valid ways of handling a Promise-valued statement include awaiting, returning, and either calling `.then()` with two arguments or `.catch()` with one argument.
47+
*
48+
* @see [no-floating-promises](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-floating-promises.md)
49+
*/
50+
export interface NoFloatingPromisesRule {
51+
/**
52+
* Requires Promise-like values to be handled appropriately.
53+
*
54+
* This rule forbids usage of Promise-like values in statements without handling their errors appropriately.
55+
* Unhandled promises can cause several issues, such as improperly sequenced operations, ignored Promise rejections and more.
56+
* Valid ways of handling a Promise-valued statement include awaiting, returning, and either calling `.then()` with two arguments or `.catch()` with one argument.
57+
*
58+
* @see [no-floating-promises](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-floating-promises.md)
59+
*/
60+
'@typescript-eslint/no-floating-promises': NoFloatingPromisesRuleConfig;
61+
}

0 commit comments

Comments
 (0)