jsx-eslint / eslint-plugin-jsx-a11y

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

feat: add support for Flat Config #993

Closed michaelfaith closed 4 months ago

michaelfaith commented 4 months ago

This change adds support for ESLint's new Flat config system. It maintains backwards compatibility with eslintrc style configs as well.

To achieve this, we're now dynamically creating four configs: two are the original recommended and strict, and the other two are the new flat/recommended and flat/strict. The two flat ones are setup with the new config format, while the original two have the same options as before.

Usage

Legacy

{
  "extends": ["plugin:jsx-a11y/recommended"]
}

Flat

import globals from 'globals';
import js from '@eslint/js';
import jsxA11y from 'eslint-plugin-jsx-a11y';

export default [
  js.configs.recommended,
  jsxA11y.flatConfigs.recommended,
  {
    files: ['**/*.{js,mjs,cjs,jsx,mjsx,ts,tsx,mtsx}'],
    languageOptions: {
      ecmaVersion: 'latest',
      sourceType: 'module',
      globals: globals.browser,
    },
    ignores: ['dist', 'eslint.config.js'],
    rules: {
      'no-unused-vars': 'warn',
      'jsx-a11y/anchor-ambiguous-text': 'warn',
      'jsx-a11y/anchor-is-valid': 'warn',
    },
  },
];

And just to be clear, this does not close the v9 support Issue, as there may be additional work needed on the rules themselves to enable compatibility with v9. This change is solely focused on providing support for the new Flat Config.

socket-security[bot] commented 4 months ago

New and removed dependencies detected. Learn more about Socket for GitHub ↗︎

Package New capabilities Transitives Size Publisher
npm/@eslint/js@9.5.0 None 0 14.2 kB eslintbot
npm/cross-env@7.0.3 environment Transitive: filesystem, shell +6 81.2 kB kentcdodds
npm/globals@15.6.0 None 0 170 kB sindresorhus
npm/react-dom@18.3.1 environment +3 4.63 MB react-bot
npm/react@18.3.1 environment +2 339 kB react-bot

View full report↗︎

codecov[bot] commented 4 months ago

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 98.48%. Comparing base (0d5321a) to head (bb7d65b). Report is 6 commits behind head on main.

:exclamation: Current head bb7d65b differs from pull request most recent head 6b5f096

Please upload reports for the commit 6b5f096 to get more accurate results.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #993 +/- ## ========================================== - Coverage 99.02% 98.48% -0.54% ========================================== Files 105 107 +2 Lines 1636 1650 +14 Branches 579 581 +2 ========================================== + Hits 1620 1625 +5 - Misses 16 25 +9 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

michaelfaith commented 4 months ago

Looks like the rule doc generator may need new icons for the two new flat configs. Not sure if you want to use the same check and lock as the legacy configs. Since the rulesets are the same, it does seem a bit redundant to have both in the table, but I'm not sure how you'd want to represent that.

michaelfaith commented 4 months ago

I went ahead and set the two flat/ configs to ignore on the doc generator, since they're mirrors of recommended and strict. Though it still looks like it's having issues with some formatting (maybe because I'm on Windows and line endings generated on my machine differ?). I reran the generate from my Mac and it resolved the formatting issue.

ljharb commented 4 months ago

v6.9.0 has been released.