Skip to content

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

@Quanyails

Description

@Quanyails

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    awaiting responseWaiting for a reply from the OPwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions