-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Imports rules: add eslint flat config support #2818
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
Closed
OlivierZal
wants to merge
8
commits into
airbnb:master
from
OlivierZal:olivierzal/imports_rules/eslint_flat_config_support
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
de58edc
Imports rules: add eslint flat config support
OlivierZal 0d3b2ae
Apply suggestions from code review
OlivierZal 0113c09
Chnages after review
OlivierZal 95472d3
Update flat.js
OlivierZal 68f3f2f
Handle plugins key by spreading
OlivierZal 5c34065
Update packages/eslint-config-airbnb-base/flat.js
OlivierZal 9770191
Fixes
OlivierZal 7930b02
Add missing trailing commas
OlivierZal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| /** | ||
| * Changes to support the flat config format: | ||
| * - The `extends` key has been deprecated. | ||
| * - The `parserOptions` key has been moved under the new `languageOptions` key. | ||
| * - The `env` key has been deprecated and moved to `languageOptions.globals`. | ||
| * - The `plugins` key is no longer a list but an object. | ||
| */ | ||
|
|
||
| const { | ||
| extends: airbnbRules, | ||
| ...airbnbConfig | ||
| } = require('.'); | ||
| const importPlugin = require('eslint-plugin-import/flat'); | ||
| const envs = require('globals'); | ||
|
|
||
| const envMapping = { | ||
| builtin: 'builtin', | ||
| es5: 'es5', | ||
| es6: 'es2015', | ||
| es2016: 'es2015', | ||
| es2017: 'es2017', | ||
| es2018: 'es2017', | ||
| es2019: 'es2017', | ||
| es2020: 'es2020', | ||
| es2021: 'es2021', | ||
| es2022: 'es2021', | ||
| es2023: 'es2021', | ||
| es2024: 'es2021', | ||
| browser: 'browser', | ||
| worker: 'worker', | ||
| node: 'node', | ||
| nodeBuiltin: 'nodeBuiltin', | ||
| commonjs: 'commonjs', | ||
| amd: 'amd', | ||
| mocha: 'mocha', | ||
| jasmine: 'jasmine', | ||
| jest: 'jest', | ||
| qunit: 'qunit', | ||
| phantomjs: 'phantomjs', | ||
| couch: 'couch', | ||
| rhino: 'rhino', | ||
| nashorn: 'nashorn', | ||
| wsh: 'wsh', | ||
| jquery: 'jquery', | ||
| yui: 'yui', | ||
| shelljs: 'shelljs', | ||
| prototypejs: 'prototypejs', | ||
| meteor: 'meteor', | ||
| mongo: 'mongo', | ||
| applescript: 'applescript', | ||
| serviceworker: 'serviceworker', | ||
| atomtest: 'atomtest', | ||
| embertest: 'embertest', | ||
| protractor: 'protractor', | ||
| 'shared-node-browser': 'shared-node-browser', | ||
| webextensions: 'webextensions', | ||
| greasemonkey: 'greasemonkey', | ||
| devtools: 'devtools' | ||
| }; | ||
|
|
||
| function convertIntoEslintFlatConfig(config) { | ||
| const { | ||
| env, // convert to explicit `globals` list | ||
| parserOptions, // move into `languageOptions` | ||
| plugins, // remove the `plugins` key as it will be spread directly during export | ||
| ...oldConfig | ||
| } = config | ||
| return { | ||
| ...oldConfig, | ||
| languageOptions: { | ||
| ...('env' in config && { | ||
| globals: Object.fromEntries( | ||
| Object.keys(env) | ||
| .filter((key) => env[key] === true && key in envMapping && envMapping[key] in envs) | ||
| .flatMap((key) => Object.entries(envs[envMapping[key]])) | ||
| ), | ||
| ...('parserOptions' in config && { | ||
| parserOptions, | ||
| }), | ||
| }), | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| module.exports = [ | ||
| ...airbnbRules.map((rule) => convertIntoEslintFlatConfig(require(rule))), | ||
| convertIntoEslintFlatConfig(airbnbConfig), | ||
| ...importPlugin, | ||
| ]; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.