jsx-eslint / eslint-plugin-jsx-a11y

Static AST checker for a11y rules on JSX elements.
MIT License
3.39k stars 637 forks source link

How to configure `eslint-plugin-jsx-a11y` in `eslint.config.js` #965

Closed rakleed closed 11 months ago

rakleed commented 11 months ago

From the next version 9, ESLint will deprecate the current eslintrc format, and by default will use the new flat config format (eslint.config.js). Already from version 8.2.23 you can fully use the flat config format. But your README (which is used as a description for the NPM package) doesn’t say anything about how to configure it correctly. Although the README eslint-plugin-react contains this information. Please add this information to the documentation.

ljharb commented 11 months ago

That's because this plugin doesn't support flat config yet, so it's correct to not be in the documentation. See #891.

vmerino commented 7 months ago

I also spent some time looking through PR issues that mention "flat config" to finally find this one. I think it might be valuable to add a note to the readme that says it's currently not supported but coming soon?

ljharb commented 7 months ago

@vmerino then i'd get no end to issues asking "when" :-p

gregjacobs commented 7 months ago

@ljharb So I was able to make the plugin work with the following config object in the flat config with v6.8.0 (for anyone else finding this thread):

import jsxA11y from 'eslint-plugin-jsx-a11y';

// ...

{
    plugins: {
        'jsx-a11y': {
            rules: jsxA11y.rules,
        },
    },
    rules: jsxA11y.configs.recommended.rules,
},

It may also need the languageOptions config for jsx but probably works in mine because I already have eslint-plugin-react in there.

If you don't want to make any changes to the code itself, could just put the above snippet in the readme?

ljharb commented 7 months ago

@gregjacobs if you can confirm that all of the rules actually work that way, then I'd be happy to accept a PR with a flat entrypoint that does that (including relevant docs).