Skip to content

Bug: eslint-plugin-react-hooks v.6.1.0 recommended config uses array instead of object #34679

@anthonyblond

Description

@anthonyblond

Not sure if this is technically a bug, or just a convention choice.

It's not possible to use the recommended config directly in a flat eslint config array in version 6.1.0

The recommended-latest config (now deprecated) will work, but the new recommended config will not.

The plugin is defined as:

Object.assign(plugin.configs, {
    'recommended-legacy': {
        plugins: ['react-hooks'],
        rules: ruleConfigs,
    },
    'flat/recommended': [
        {
            plugins: {
                'react-hooks': plugin,
            },
            rules: ruleConfigs,
        },
    ],
    'recommended-latest': [
        {
            plugins: {
                'react-hooks': plugin,
            },
            rules: ruleConfigs,
        },
    ],
    recommended: {
        plugins: ['react-hooks'],
        rules: ruleConfigs,
    },
});

The last property should be

    recommended: {
         plugins: {
             'react-hooks': plugin,
         },
        rules: ruleConfigs,
    },

as per https://eslint.org/docs/latest/use/configure/configuration-files#configuration-objects which states

plugins - An object containing a name-value mapping of plugin names to plugin objects. When files is specified, these plugins are only available to the matching files.

React version: 19.1.1

Steps To Reproduce

// eslint.config.js
import jsEslint from '@eslint/js';
import reactHooks from 'eslint-plugin-react-hooks';
import { defineConfig } from 'eslint/config';

export default defineConfig([
  jsEslint.configs.recommended, 
  reactHooks.configs.recommended
]);

The current behaviour

Running eslint

Oops! Something went wrong! :(

ESLint: 9.36.0


A config object has a "plugins" key defined as an array of strings. It looks something like this:

    {
        "plugins": ["react-hooks"]
    }

Flat config requires "plugins" to be an object, like this:

    {
        plugins: {
            react-hooks: pluginObject
        }
    }

Please see the following page for information on how to convert your config object into the correct format:
https://eslint.org/docs/latest/use/configure/migration-guide#importing-plugins-and-custom-parsers

If you're using a shareable config that you cannot rewrite in flat config format, then use the compatibility utility:
https://eslint.org/docs/latest/use/configure/migration-guide#using-eslintrc-configs-in-flat-config

The expected behaviour

For it to work the same as if using reactHooks.configs['recommended-latest'] instead.

This isn't a huge deal since there are only two rules, so its easy to just skip the recommended config like the following, but it would nice to be consistent with the way other eslint plugins share their configs.

  {
    plugins: {
      'react-hooks': reactHooksPlugin,
    },
    rules: {
      'react-hooks/exhaustive-deps': 'error',
      'react-hooks/rules-of-hooks': 'error',
    },
  },

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions