Skip to content
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

add linter to ensure we always await async function calls/promises #2040

Open
holic opened this issue Dec 7, 2023 · 1 comment
Open

add linter to ensure we always await async function calls/promises #2040

holic opened this issue Dec 7, 2023 · 1 comment
Labels
good first issue Good for newcomers

Comments

@holic
Copy link
Member

holic commented Dec 7, 2023

More often than not, we want to await and not doing so leads to scary bugs. For cases where we explicitly don't want to await, we can add a lint ignore line comment.

https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/docs/rules/no-floating-promises.md

@holic
Copy link
Member Author

holic commented Sep 3, 2024

tried to enable this but ran into some issues

new .eslintrc

{
  "root": true,
  "parser": "@typescript-eslint/parser",
  "plugins": ["@typescript-eslint"],
  "extends": ["eslint:recommended"],
  "rules": {
    "max-len": ["error", { "code": 180, "comments": 180 }],
  },
  "overrides": [
    {
      "files": ["*.ts", "*.tsx"],
      "extends": ["plugin:@typescript-eslint/eslint-recommended", "plugin:@typescript-eslint/recommended"],
      "parserOptions": {
        "project": ["./tsconfig.json"],
      },
      "rules": {
        "@typescript-eslint/ban-types": [
          "error",
          {
            "extendDefaults": true,
            "types": {
              // don't throw an error for the empty object type ({})
              "{}": false,
            },
          },
        ],
        "@typescript-eslint/no-floating-promises": "error",
      },
    },
  ],
}

running pnpm lint in CLI shows this (and does catch some await errors)

/Users/kevin/Projects/latticexyz/mud/packages/cli/dist/index.d.ts
  0:0  error  Parsing error: ESLint was configured to run on `<tsconfigRootDir>/dist/index.d.ts` using `parserOptions.project`: /users/kevin/projects/latticexyz/mud/tsconfig.json
However, that TSConfig does not include this file. Either:
- Change ESLint's list of included files to not include this file
- Change that TSConfig to include this file
- Create a new TSConfig that includes this file and include it in your parserOptions.project
See the typescript-eslint docs for more info: https://typescript-eslint.io/linting/troubleshooting#i-get-errors-telling-me-eslint-was-configured-to-run--however-that-tsconfig-does-not--none-of-those-tsconfigs-include-this-file

but it doesn't seem to be catching the issue in #3119

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant