Skip to content

[Chore]: enable @typescript-eslint/no-floating-promises #5459

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
jsjoeio opened this issue Aug 15, 2022 · 1 comment
Closed

[Chore]: enable @typescript-eslint/no-floating-promises #5459

jsjoeio opened this issue Aug 15, 2022 · 1 comment
Assignees
Labels
enhancement Some improvement that isn't a feature

Comments

@jsjoeio
Copy link
Contributor

jsjoeio commented Aug 15, 2022

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:

  1. 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
  1. remove --max-warnings=0 from lint.sh
  2. 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.
@jsjoeio jsjoeio added the enhancement Some improvement that isn't a feature label Aug 15, 2022
@jsjoeio
Copy link
Contributor Author

jsjoeio commented Aug 15, 2022

We should probably add no-misused-promises as well
-@code-asher

@jsjoeio jsjoeio self-assigned this Aug 17, 2022
@code-asher code-asher closed this as not planned Won't fix, can't repro, duplicate, stale Jul 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Some improvement that isn't a feature
Projects
None yet
Development

No branches or pull requests

2 participants