Skip to content

no-await-sync-query: false positive in non-test code #447

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
Quanyails opened this issue Aug 3, 2021 · 2 comments
Closed

no-await-sync-query: false positive in non-test code #447

Quanyails opened this issue Aug 3, 2021 · 2 comments
Labels
awaiting response Waiting for a reply from the OP wontfix This will not be worked on

Comments

@Quanyails
Copy link

Quanyails commented Aug 3, 2021

Plugin version

4.6.0

ESLint version

7.17.0

Node.js version

12.13.1

npm/yarn version

6.12.1

Operating system

macOS Catalina, Version 10.15.7

Bug description

Related to: #122

We're running into a false positive from this rule triggering outside of test files. In particular, it seems to match on any async function that starts with getBy*, regardless of whether the function is from testing-library.

Steps to reproduce

  1. Run ESLint as configured against the following file:
const getBytes = async () => Promise.resolve("myData");

export const doSomething = async () => {
  const bytes = await getBytes();
  console.log("Doing something to", bytes);
};

This applies to any other function that has the naming convention getBy*. It's possible to rename the function for our use case, but I wouldn't expect the rule to trigger when this file doesn't use testing-library.

Error output/screenshots

Output from running ESLint:

  4:23  error  `getBytes` query is sync so it does not need to be awaited  testing-library/no-await-sync-query

ESLint configuration

module.exports = {
  env: {
    browser: true,
    node: true,
  },
  extends: [],
  parser: "@typescript-eslint/parser",
  parserOptions: {
    sourceType: "module",
  },
  plugins: [
    "@typescript-eslint",
    "import",
    "jest",
    "jsdoc",
    "prefer-arrow",
    "react",
    "react-hooks",
    "testing-library",
  ],
  rules: {
    "testing-library/no-await-sync-query": "error",
  },
  settings: {
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"],
    },
    "import/resolver": {
      typescript: {
        alwaysTryTypes: true,
      },
    },
    react: {
      version: "detect",
    },
  },
};

Rule(s) affected

no-await-sync-query

Anything else?

#208 closed #122, which seems to have resolved this for await-async-query, but it doesn't look like it changed no-await-sync-query.

Do you want to submit a pull request to fix this bug?

No

@Quanyails Quanyails added the bug Something isn't working label Aug 3, 2021
@Belco90
Copy link
Member

Belco90 commented Aug 3, 2021

Hi @Quanyails!

I'm afraid that method is reported because of eslint-plugin-testing-library Aggressive Reporting, which is assuming getBytes is a Testing Library related util since starts by getBy*.

There are different ways of addressing this, you can check that in the Troubleshooting section.
Could you check one of those (the one that fits better for you) and let us know if it worked? I'd suggest limiting the scope of reported files by this plugin using overrides ESLint config key.

@Belco90 Belco90 added awaiting response Waiting for a reply from the OP and removed bug Something isn't working labels Aug 3, 2021
@stale
Copy link

stale bot commented Oct 4, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix This will not be worked on label Oct 4, 2021
@stale stale bot closed this as completed Oct 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response Waiting for a reply from the OP wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants