-
-
Notifications
You must be signed in to change notification settings - Fork 638
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add support for Flat Config #993
Conversation
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 ```json { "extends": ["plugin:jsx-a11y/recommended"] } ``` Flat ```js 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', }, }, ]; ```
New and removed dependencies detected. Learn more about Socket for GitHub ↗︎
|
f69dfa3
to
25b13a2
Compare
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ 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 ☔ View full report in Codecov by Sentry. |
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. |
25b13a2
to
12fff83
Compare
I went ahead and set the two |
12fff83
to
72c98fe
Compare
README.md
Outdated
const jsxA11y = require('eslint-plugin-jsx-a11y'); | ||
|
||
export default [ | ||
jsxA11y.configs['flat/recommended'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this might be nicer to use as a flat
object, with a recommended
property?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that. I was going back and forth with that, and landed on this approach because I saw a few others doing it. But there's no real strong need to have them added to the legacy configs
object. I'll make that update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about flatConfigs
rather than flat
so that it parallels the configs
prop?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Create configs to plugin object
const configs = {
recommended: createConfig(recommendedRules),
strict: createConfig(strictRules),
};
const flatConfigs = {
recommended: createConfig(recommendedRules, 'recommended'),
strict: createConfig(strictRules, 'strict'),
};
module.exports = { ...jsxA11y, configs, flatConfigs };
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went ahead and updated with the above. Let me know what you think about that.
examples/flat-cjs/package.json
Outdated
"dependencies": { | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0" | ||
}, | ||
"devDependencies": { | ||
"@eslint/js": "^9.5.0", | ||
"@types/react": "^18.2.66", | ||
"@types/react-dom": "^18.2.22", | ||
"@vitejs/plugin-react": "^4.2.1", | ||
"cross-env": "^7.0.3", | ||
"eslint": "^8.57.0", | ||
"eslint-plugin-jsx-a11y": "file:../..", | ||
"globals": "^15.6.0", | ||
"vite": "^5.2.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we really need all these deps in the repo to showcase eslint config code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I was aiming to have it be as "real world" of an example as possible. I just generated a new React app using vite
and left everything as is, except for the lint config.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we don't need a working app to demonstrate linting, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've removed vite
, its config, and associated build/test commands (along with the boilerplate README and .gitignore). I did leave react
, react-dom
and their associated types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Went ahead and removed the @types/*
too.
b08c258
to
bb7d65b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - i'll make some tweaks so we can run the examples tests in CI, but otherwise this seems like it'll work.
bb7d65b
to
6b5f096
Compare
v6.9.0 has been released. |
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
andstrict
, and the other two are the newflat/recommended
andflat/strict
. The twoflat
ones are setup with the new config format, while the original two have the same options as before.Usage
Legacy
Flat
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.