Skip to content

False positive for await-async-utils #715

Closed
@matheusmb

Description

@matheusmb

Have you read the Troubleshooting section?

Yes

Plugin version

v5.9.1

ESLint version

v7.32.0

Node.js version

v14.18.1

package manager and version

6.14.17

Operating system

WSL2

Bug description

On creating a wrapper around a testing-library async util, eslint triggers the false positive rule await-async-utils.

Steps to reproduce

I created the following helper in my setup function:

function setup() {
  mockedGetCurrentUserProfile.mockResolvedValue(INITIAL_VALUES);
  const utils = render(<ProfileSettingsPanel open onClose={jest.fn()} />);

  const waitForLoadComplete = () => {
    return waitForElementToBeRemoved(screen.queryByRole('progressbar'));
  };

  return { waitForLoadComplete, ...utils };
}

When I try to use it inside a test:

it('example', () => {
    const { user, waitForLoadComplete } = setup();
               // ^^^^^^^^^^^^^ -> Promise returned from waitForLoadComplete wrapper over async util must be handled
    await waitForLoadComplete();
// ...
});

Error output/screenshots

No response

ESLint configuration

const path = require('path');
const { printSchema } = require('graphql');
const { loadSchemaSync } = require('@graphql-tools/load');
const { GraphQLFileLoader } = require('@graphql-tools/graphql-file-loader');
const hq = require('alias-hq');

const webpackMap = hq.get('webpack');
const aliasMap = Object.keys(webpackMap).map((k) => [k, webpackMap[k]]);

const schemaPath = path.join(__dirname, './client/apollo/schema.graphql');
const schema = loadSchemaSync(schemaPath, {
  loaders: [new GraphQLFileLoader()],
});
const schemaString = printSchema(schema);

/** @type {eslint/ESLint.ConfigData} */
const config = {
  ignorePatterns: [
    'client/apollo/autogenTypes.ts',
    'client/apollo/schema.graphql',
    'server/index.ts',
  ],
  extends: ['@private-company', 'plugin:@next/next/recommended'],
  plugins: ['graphql', 'import'],
  settings: {
    /**
     * Path aliasing needs specific configuration.
     * This depends on
     * https://www.npmjs.com/package/eslint-import-resolver-alias
     */
    'import/resolver': {
      alias: {
        map: aliasMap,
        extensions: ['.ts', '.tsx', '.js', '.jsx', '.json'],
      },
    },
  },
  rules: {
    // From eslint-plugin-graphql
    'react/jsx-no-target-blank': 0,
    'no-console': 'error',
    '@typescript-eslint/no-unused-vars': 'error',
    'graphql/template-strings': [
      'error',
      {
        env: 'apollo',
        schemaString,
      },
      {
        env: 'literal',
        schemaString,
      },
    ],
  },
  overrides: [
    {
      files: ['*.ts', '*.tsx'],
      rules: {
        '@typescript-eslint/explicit-module-boundary-types': 'warn',
      },
    },
    {
      files: ['.eslintrc.js', 'jest.config.js'],
      rules: {
        'import/no-extraneous-dependencies': 'off',
      },
    },
  ],
};

module.exports = config;

Rule(s) affected

await-async-utils

Anything else?

No response

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

No

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions