cursorless icon indicating copy to clipboard operation
cursorless copied to clipboard

Use or explicitly ignore all promises

Open bjaspan opened this issue 2 years ago • 5 comments

From Google's internal Typescript conformance checks (I'll look to see if these are open-source somewhere):

"When using async / await, it can be easy to forget to await a promise which can result in async tasks running in an unexpected order. Thus, we require that every promise in an async function is consumed in some way, so that there's a well-defined order in which async tasks are resolved. To fix this check, you can do one of the following:

  • Remove async from the function, and instead use normal promise chaining. await the promise.
  • Assign the promise to a variable and await it later.
  • If you really want to use async and don't want to await a particular Promise, you can use the void operator to signal your intent.
    void returnsPromise();
    
    This explicitly makes your intention to not await the promise clear."
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/actions/Find.ts:50:7 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

 50       showWarning(
          ~~~~~~~~~~~~
 51         ide().messages,
    ~~~~~~~~~~~~~~~~~~~~~~~
... 
 53         "Search text is longer than 200 characters; truncating",
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 54       );
    ~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/actions/GenerateSnippet/GenerateSnippet.ts:90:5 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

90     flashTargets(ide(), targets, FlashStyle.referenced);
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/actions/ShowParseTree.ts:52:5 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

52     ide().openUntitledTextDocument({
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53       language: "markdown",
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
54       content: results.join("\n\n"),
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55     });
   ~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/actions/Sort.ts:43:7 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

 43       showWarning(
          ~~~~~~~~~~~~
 44         ide().messages,
    ~~~~~~~~~~~~~~~~~~~~~~~
... 
 46         'This action works on multiple targets, e.g. "sort every line block" instead of "sort block".',
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 47       );
    ~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/core/Snippets.ts:155:9 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

155         showError(ide().messages, "snippetsDirError", errorMessage);
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/core/Snippets.ts:196:11 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

196           showError(
              ~~~~~~~~~~
197             ide().messages,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
... 
201             }`,
    ~~~~~~~~~~~~~~~
202           );
    ~~~~~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/spokenForms/CustomSpokenForms.ts:117:9 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

117         showError(
            ~~~~~~~~~~
118           ide().messages,
    ~~~~~~~~~~~~~~~~~~~~~~~~~
... 
122           }}}. Falling back to default spoken forms.`,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123         );
    ~~~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/testCaseRecorder/TestCaseRecorder.ts:111:7 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

111       showInfo(ide().messages, "recordStop", "Stopped recording test cases");
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/testCaseRecorder/TestCaseRecorder.ts:245:5 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

245     showInfo(
        ~~~~~~~~~
246       ide().messages,
    ~~~~~~~~~~~~~~~~~~~~~
... 
248       `Recording test cases for following commands in:\n${this.targetDirectory}`,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
249     );
    ~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/testCaseRecorder/TestCaseRecorder.ts:384:7 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

384       showInfo(ide().messages, "testCaseSaved", message, "View", "Delete").then(
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
385         async (action) => {
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
... 
398         },
    ~~~~~~~~~~
399       );
    ~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/testCaseRecorder/TestCaseRecorder.ts:422:7 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

422       showError(ide().messages, "promptSubdirectoryError", errorMessage);
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/actions/ShowParseTree.ts:52:5 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

52     ide().openUntitledTextDocument({
       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
53       language: "markdown",
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~
54       content: results.join("\n\n"),
   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55     });
   ~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/actions/Sort.ts:43:7 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

 43       showWarning(
          ~~~~~~~~~~~~
 44         ide().messages,
    ~~~~~~~~~~~~~~~~~~~~~~~
... 
 46         'This action works on multiple targets, e.g. "sort every line block" instead of "sort block".',
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 47       );
    ~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/core/Snippets.ts:155:9 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

155         showError(ide().messages, "snippetsDirError", errorMessage);
            ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/core/Snippets.ts:196:11 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

196           showError(
              ~~~~~~~~~~
197             ide().messages,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
... 
201             }`,
    ~~~~~~~~~~~~~~~
202           );
    ~~~~~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/spokenForms/CustomSpokenForms.ts:117:9 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

117         showError(
            ~~~~~~~~~~
118           ide().messages,
    ~~~~~~~~~~~~~~~~~~~~~~~~~
... 
122           }}}. Falling back to default spoken forms.`,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
123         );
    ~~~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/testCaseRecorder/TestCaseRecorder.ts:111:7 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

111       showInfo(ide().messages, "recordStop", "Stopped recording test cases");
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/testCaseRecorder/TestCaseRecorder.ts:245:5 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

245     showInfo(
        ~~~~~~~~~
246       ide().messages,
    ~~~~~~~~~~~~~~~~~~~~~
... 
248       `Recording test cases for following commands in:\n${this.targetDirectory}`,
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
249     );
    ~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/testCaseRecorder/TestCaseRecorder.ts:384:7 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

384       showInfo(ide().messages, "testCaseSaved", message, "View", "Delete").then(
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
385         async (action) => {
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~
... 
398         },
    ~~~~~~~~~~
399       );
    ~~~~~~~
third_party/vscode_ext/cursorless_vscode/packages/cursorless-engine/src/testCaseRecorder/TestCaseRecorder.ts:422:7 - error TS21225: [tsetse] All Promises in async functions must either be awaited or used in an expression.
	See http://go/ts-conformance#must-use-promises

422       showError(ide().messages, "promptSubdirectoryError", errorMessage);
          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

bjaspan avatar Oct 31 '23 15:10 bjaspan

Yeah unless there's an open source linter that will catch this, I think this goal is aspirational. @auscompgeek do you know of anything? I did a quick google and nothing came up that looked obviously like the right thing

pokey avatar Oct 31 '23 15:10 pokey

It appears that these rules are open-source as part of the Bazel build system (which I believe is open-sourced by Google), e.g.: https://github.com/bazelbuild/rules_nodejs/blob/3.x/third_party/github.com/bazelbuild/rules_typescript/docs/must-use-promises.md. How to incorporate this into your non-Bazel build process, I don't know.

bjaspan avatar Oct 31 '23 16:10 bjaspan

https://typescript-eslint.io/rules/no-floating-promises

auscompgeek avatar Oct 31 '23 21:10 auscompgeek

https://typescript-eslint.io/rules/no-floating-promises

Oh strange I saw that rule but it looked like it was just ensuring that errors were handled. But on second read maybe you're right? I can try switching it on and seeing if it picks up this case

pokey avatar Nov 01 '23 18:11 pokey

It looks like it's part of the recommended-type-checked config, so maybe we should bite the bullet and turn that all on. I'm curious what the impact on lint perf for us would be though. Type checking isn't exactly cheap.

auscompgeek avatar Nov 01 '23 23:11 auscompgeek