Closed as not planned
Description
What is your suggestion?
To enable a new ESLint rule: @typescript-eslint/no-floating-promises
Why do you want this feature?
We believe it would have prevented issues like #5442 and any future issues related to floating promises.
Are there any workarounds to get this functionality today?
Manually checking code myself to see if we have any floating promises.
Are you interested in submitting a PR for this?
Yes, but it might take some work. I did some initial investigation. See below:
Expand to see
To add this rule, we need to:
- adjust our
.eslintrc.yaml
file
diff --git a/.eslintrc.yaml b/.eslintrc.yaml
index 1bbbbd09..9388ad15 100644
--- a/.eslintrc.yaml
+++ b/.eslintrc.yaml
@@ -8,10 +8,12 @@ env:
parserOptions:
ecmaVersion: 2018
sourceType: module
+ project: './tsconfig.json'
extends:
- eslint:recommended
- plugin:@typescript-eslint/recommended
+ # - plugin:@typescript-eslint/recommended-requiring-type-checking
- plugin:import/recommended
- plugin:import/typescript
- plugin:prettier/recommended
@@ -32,6 +34,7 @@ rules:
"@typescript-eslint/explicit-module-boundary-types": off
"@typescript-eslint/no-explicit-any": off
"@typescript-eslint/no-extra-semi": off
+ "@typescript-eslint/no-floating-promises": 2
eqeqeq: error
import/order:
[error, { alphabetize: { order: "asc" }, groups: [["builtin", "external", "internal"], "parent", "sibling"] }]
@@ -41,3 +44,5 @@ settings:
import/resolver:
typescript:
alwaysTryTypes: true
+
+ignorePatterns: "/test"
\ No newline at end of file
- remove
--max-warnings=0
fromlint.sh
- fix all 16 errors
Because of an issue in ESLint -- eslint/eslint#15010 -- it's not possible to both ignore files from being linted without eslint
counting them as warnings in CLI output.
BUT that assumes we don't want to lint test files. If we do, we need to add the "./test/tsconfig.json"
to project
.
Here are all 32 errors found by the linter (including test files):
yarn run v1.22.18
$ ./ci/dev/lint.sh
/Users/jp/dev/coder/code-server/ci/dev/watch.ts
0:0 error Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: ci/dev/watch.ts.
The file must be included in at least one of the projects provided
/Users/jp/dev/coder/code-server/src/node/heart.ts
64:7 error 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 @typescript-eslint/no-floating-promises
/Users/jp/dev/coder/code-server/src/node/main.ts
191:7 error 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 @typescript-eslint/no-floating-promises
/Users/jp/dev/coder/code-server/src/node/routes/index.ts
61:7 error 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 @typescript-eslint/no-floating-promises
175:5 error 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 @typescript-eslint/no-floating-promises
/Users/jp/dev/coder/code-server/src/node/routes/vscode.ts
125:5 error 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 @typescript-eslint/no-floating-promises
/Users/jp/dev/coder/code-server/src/node/socket.ts
25:7 error 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 @typescript-eslint/no-floating-promises
50:9 error 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 @typescript-eslint/no-floating-promises
60:13 error 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 @typescript-eslint/no-floating-promises
/Users/jp/dev/coder/code-server/src/node/update.ts
45:7 error 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 @typescript-eslint/no-floating-promises
/Users/jp/dev/coder/code-server/src/node/wrapper.ts
118:7 error 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 @typescript-eslint/no-floating-promises
166:9 error 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 @typescript-eslint/no-floating-promises
228:7 error 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 @typescript-eslint/no-floating-promises
233:7 error 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 @typescript-eslint/no-floating-promises
250:11 error 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 @typescript-eslint/no-floating-promises
272:5 error 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 @typescript-eslint/no-floating-promises
/Users/jp/dev/coder/code-server/test/e2e/extensions/test-extension/extension.ts
7:9 error 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 @typescript-eslint/no-floating-promises
9:9 error 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 @typescript-eslint/no-floating-promises
/Users/jp/dev/coder/code-server/test/unit/common/emitter.test.ts
52:5 error 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 @typescript-eslint/no-floating-promises
55:5 error 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 @typescript-eslint/no-floating-promises
/Users/jp/dev/coder/code-server/test/unit/helpers.test.ts
16:5 error 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 @typescript-eslint/no-floating-promises
/Users/jp/dev/coder/code-server/test/unit/node/app.test.ts
54:5 error 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 @typescript-eslint/no-floating-promises
73:5 error 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 @typescript-eslint/no-floating-promises
92:7 error 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 @typescript-eslint/no-floating-promises
95:5 error 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 @typescript-eslint/no-floating-promises
107:5 error 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 @typescript-eslint/no-floating-promises
119:5 error 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 @typescript-eslint/no-floating-promises
137:5 error 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 @typescript-eslint/no-floating-promises
/Users/jp/dev/coder/code-server/test/unit/node/cli.test.ts
740:5 error 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 @typescript-eslint/no-floating-promises
/Users/jp/dev/coder/code-server/test/unit/node/socket.test.ts
40:9 error 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 @typescript-eslint/no-floating-promises
/Users/jp/dev/coder/code-server/test/unit/node/test-plugin/.eslintrc.js
0:0 error Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser.
The file does not match your project config: test/unit/node/test-plugin/.eslintrc.js.
The file must be included in at least one of the projects provided
/Users/jp/dev/coder/code-server/test/unit/node/util.test.ts
154:5 error 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 @typescript-eslint/no-floating-promises
✖ 32 problems (32 errors, 0 warnings)
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.