-
Notifications
You must be signed in to change notification settings - Fork 26.8k
Support flat config #3081
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
Draft
9takoyakii
wants to merge
9
commits into
airbnb:master
Choose a base branch
from
9takoyakii:support-flat-config
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Support flat config #3081
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
58a970b
Add flat config support for eslint-config-airbnb-base
9takoyakii dd32e26
Add flat config support for eslint-config-airbnb
9takoyakii 2558f31
[eslint config] add eslint config using flat config
9takoyakii c728e72
[readme] add documentation for how to use flat config
9takoyakii 9828d85
Fix issue in hooks-flat
9takoyakii 58040d1
Remove duplicate codes
9takoyakii c8ba811
Add flat config support for eslint-config-airbnb-base/whitespace and …
9takoyakii 4d34479
[readme] add documentation for how to use flat config of whitespace
9takoyakii 4015956
Fix issue of ESLint.calculateConfigForFile
9takoyakii 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module.exports = [ | ||
...require('./flat'), | ||
{ | ||
rules: { | ||
// disable requiring trailing commas because it might be nice to revert to | ||
// being JSON at some point, and I don't want to make big changes now. | ||
"comma-dangle": 0, | ||
|
||
"max-len": 0 | ||
} | ||
} | ||
]; |
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,21 @@ | ||
module.exports = [ | ||
...([ | ||
'./rules/flat/best-practices', | ||
'./rules/flat/errors', | ||
'./rules/flat/node', | ||
'./rules/flat/style', | ||
'./rules/flat/variables', | ||
'./rules/flat/es6', | ||
'./rules/flat/imports', | ||
'./rules/flat/strict', | ||
].reduce((p, c) => p.concat(require(c)), [])), // eslint-disable-line global-require, import/no-dynamic-require | ||
{ | ||
languageOptions: { | ||
parserOptions: { | ||
ecmaVersion: 2018, | ||
sourceType: 'module' | ||
} | ||
}, | ||
rules: {} | ||
} | ||
]; |
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
6 changes: 6 additions & 0 deletions
6
packages/eslint-config-airbnb-base/rules/flat/best-practices.js
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,6 @@ | ||
const baseConfig = require('../best-practices'); | ||
|
||
module.exports = [{ | ||
name: 'eslint-config-airbnb-base/best-practices', | ||
rules: baseConfig.rules | ||
}]; |
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,6 @@ | ||
const baseConfig = require('../errors'); | ||
|
||
module.exports = [{ | ||
name: 'eslint-config-airbnb-base/errors', | ||
rules: baseConfig.rules | ||
}]; |
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,11 @@ | ||
const globals = require('globals'); | ||
const baseConfig = require('../es6'); | ||
|
||
module.exports = [{ | ||
name: 'eslint-config-airbnb-base/es6', | ||
languageOptions: { | ||
globals: globals.es2015, | ||
parserOptions: baseConfig.parserOptions | ||
}, | ||
rules: baseConfig.rules | ||
}]; |
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,13 @@ | ||
const importPlugin = require('eslint-plugin-import'); | ||
const globals = require('globals'); | ||
const baseConfig = require('../imports'); | ||
|
||
module.exports = [importPlugin.flatConfigs.recommended, { | ||
name: 'eslint-config-airbnb-base/imports', | ||
languageOptions: { | ||
globals: globals.es2015, | ||
parserOptions: baseConfig.parserOptions | ||
}, | ||
settings: baseConfig.settings, | ||
rules: baseConfig.rules | ||
}]; |
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,10 @@ | ||
const globals = require('globals'); | ||
const base = require('../node'); | ||
|
||
module.exports = [{ | ||
name: 'eslint-config-airbnb-base/node', | ||
languageOptions: { | ||
globals: globals.node | ||
}, | ||
rules: base.rules | ||
}]; |
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,6 @@ | ||
const base = require('../strict'); | ||
|
||
module.exports = [{ | ||
name: 'eslint-config-airbnb-base/strict', | ||
rules: base.rules | ||
}]; |
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,6 @@ | ||
const base = require('../style'); | ||
|
||
module.exports = [{ | ||
name: 'eslint-config-airbnb-base/style', | ||
rules: base.rules | ||
}]; |
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,6 @@ | ||
const base = require('../variables'); | ||
|
||
module.exports = [{ | ||
name: 'eslint-config-airbnb-base/variables', | ||
rules: base.rules | ||
}]; |
49 changes: 49 additions & 0 deletions
49
packages/eslint-config-airbnb-base/whitespace-flat-async.js
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,49 @@ | ||
#!/usr/bin/env node | ||
|
||
const { isArray } = Array; | ||
const { entries } = Object; | ||
const { ESLint } = require('eslint'); | ||
|
||
const baseConfig = require('./flat'); | ||
const whitespaceRules = require('./whitespaceRules'); | ||
|
||
const severities = ['off', 'warn', 'error']; | ||
|
||
function getSeverity(ruleConfig) { | ||
if (isArray(ruleConfig)) { | ||
return getSeverity(ruleConfig[0]); | ||
} | ||
if (typeof ruleConfig === 'number') { | ||
return severities[ruleConfig]; | ||
} | ||
return ruleConfig; | ||
} | ||
|
||
async function onlyErrorOnRules(rulesToError, config) { | ||
const errorsOnly = { | ||
languageOptions: config[config.length - 1].languageOptions || {}, | ||
rules: config[config.length - 1].rules || {}, | ||
}; | ||
const cli = new ESLint({ baseConfig: config }); | ||
const baseRules = (await cli.calculateConfigForFile(require.resolve('./flat'))).rules; | ||
|
||
entries(baseRules).forEach((rule) => { | ||
const ruleName = rule[0]; | ||
const ruleConfig = rule[1]; | ||
const severity = getSeverity(ruleConfig); | ||
|
||
if (rulesToError.indexOf(ruleName) === -1 && severity === 'error') { | ||
if (isArray(ruleConfig)) { | ||
errorsOnly.rules[ruleName] = ['warn'].concat(ruleConfig.slice(1)); | ||
} else if (typeof ruleConfig === 'number') { | ||
errorsOnly.rules[ruleName] = 1; | ||
} else { | ||
errorsOnly.rules[ruleName] = 'warn'; | ||
} | ||
} | ||
}); | ||
|
||
return errorsOnly; | ||
} | ||
|
||
onlyErrorOnRules(whitespaceRules, baseConfig).then((config) => console.log(JSON.stringify(config))); |
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,13 @@ | ||
/* eslint global-require: 0 */ | ||
|
||
const path = require('path'); | ||
const { execSync } = require('child_process'); | ||
|
||
// NOTE: ESLint adds runtime statistics to the output (so it's no longer JSON) if TIMING is set | ||
module.exports = JSON.parse(String(execSync(path.join(__dirname, 'whitespace-flat-async.js'), { | ||
cwd: __dirname, // NOTE: cwd is set to prevent ESLint.calculateConfigForFile return {} | ||
env: { | ||
...process.env, | ||
TIMING: undefined, | ||
} | ||
}))); |
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,10 @@ | ||
module.exports = [ | ||
...require('./flat'), // eslint-disable-line global-require | ||
{ | ||
rules: { | ||
// disable requiring trailing commas because it might be nice to revert to | ||
// being JSON at some point, and I don't want to make big changes now. | ||
'comma-dangle': 0, | ||
} | ||
} | ||
]; |
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,8 @@ | ||
module.exports = [ | ||
...([ | ||
'eslint-config-airbnb-base/flat', | ||
'./rules/flat/react', | ||
'./rules/flat/react-a11y', | ||
// eslint-disable-next-line global-require, import/no-dynamic-require | ||
].reduce((p, c) => p.concat(require(c)), [])) | ||
]; |
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 @@ | ||
module.exports = require('./rules/flat/react-hooks'); |
Oops, something went wrong.
Oops, something went wrong.
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.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.