-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
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
chore: use eslint-plugin-eslint-plugin flat configs #17204
Conversation
✅ Deploy Preview for docs-eslint canceled.
|
"eslint-plugin/no-missing-message-ids": "error", | ||
"eslint-plugin/no-unused-message-ids": "error", | ||
"eslint-plugin/prefer-message-ids": "error", |
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.
These three rules are now already in the rules recommended config, so I removed them from here.
rules: { | ||
"eslint-plugin/require-meta-docs-url": ["error", { pattern: "https://eslint.org/docs/latest/rules/{{name}}" }] | ||
} | ||
}, | ||
{ | ||
files: ["tests/lib/rules/*", "tests/tools/internal-rules/*"], | ||
rules: { | ||
...eslintPlugin.configs["tests-recommended"].rules, | ||
"eslint-plugin/prefer-output-null": "error", |
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 rule is now already in the tests recommended config, so I removed it from here.
@@ -188,7 +188,6 @@ module.exports = { | |||
}] | |||
}, | |||
fixable: "code", | |||
// eslint-disable-next-line eslint-plugin/require-meta-has-suggestions -- Does not detect conditional suggestions |
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 false positive has been fixed in the new version of eslint-plugin/require-meta-has-suggestions
.
@@ -212,7 +212,6 @@ module.exports = { | |||
context.report({ | |||
node, | |||
messageId: "unexpected", | |||
data: { identifier: node.name }, |
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 was caught by the new version of eslint-plugin/no-unused-placeholders
.
@@ -231,7 +230,6 @@ module.exports = { | |||
context.report({ | |||
node, | |||
messageId: "expected", | |||
data: { identifier: node.name }, |
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 was caught by the new version of eslint-plugin/no-unused-placeholders.
Looks like some tests that use this project's eslint config files are failing because |
can we just use const eslintPlugin = require("eslint-plugin-eslint-plugin");
module.exports = [{
files: ["lib/rules/*", "tools/internal-rules/*"],
plugins: {'eslint-plugin': eslintPlugin},
rules: {...eslintPlugin.configs.recommended.rules},
}]; The only difference eslintrc vs. flat is: the |
We can certainly do that. I think that's how we're actually using Line 133 in 5b68d51
I just wanted to change this to use the flat config exports for testing purposes, as that would be a production example of a flat config that uses a shared flat config. Now, that alone doesn't justify the effort of updating 50 tests, but this might be a good opportunity to update those tests to use fixture configs so that we're able to change this project's lint configs without worrying about it affecting the tests in any way. |
64b3388
to
21a6225
Compare
All tests are passing now. |
const eslintPluginRulesRecommendedConfig = require("eslint-plugin-eslint-plugin/configs/rules-recommended"); | ||
const eslintPluginTestsRecommendedConfig = require("eslint-plugin-eslint-plugin/configs/tests-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.
Can you destructure these configs from require('eslint-plugin-eslint-plugin')
? That will be more future-proof than reaching directly into specific files in the event that the plugin more-strictly defines its Node API.
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 believe this is the only way to use flat configs from eslint-plugin-eslint-plugin
at the moment.
https://github.com/eslint-community/eslint-plugin-eslint-plugin#eslintconfigjs-requires-eslintv8230
Configs in require('eslint-plugin-eslint-plugin').configs
are in the eslintrc format.
@aladdin-add is that correct?
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.
(not blocking) @aladdin-add shouldn't we export the flat configs too? Reaching into specific files is fragile especially if we were to move things around.
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.
they are exported. The default predefined configs are eslintrc, and to not affect the use of eslintrc, I added a new directory to place the flat configs: https://github.com/eslint-community/eslint-plugin-eslint-plugin/tree/main/configs. Any better suggestions?
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'm going to merge this as it correctly uses the current interface of eslint-plugin-eslint-plugin. We can update the usage if and when the interface changes.
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.
So require('eslint-plugin-eslint-plugin').configs
will always have to be in the eslintrc format for backwards compatibility, but flat configs have to be accessed by file path e.g. require("eslint-plugin-eslint-plugin/configs/rules-recommended")
? Is there a cleaner, long-term plan or recommendation for supporting both config formats (instead of just having to access the newer one by file path)?
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.
So
require('eslint-plugin-eslint-plugin').configs
will always have to be in the eslintrc format for backwards compatibility, but flat configs have to be accessed by file path e.g.require("eslint-plugin-eslint-plugin/configs/rules-recommended")
? Is there a cleaner, long-term plan or recommendation for supporting both config formats (instead of just having to access the newer one by file path)?
I think we could discuss that in #17242.
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.
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
[ ] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[x] Other, please explain:
Upgrades
eslint-plugin-eslint-plugin
to the latest version and switches to using its flat config exports (eslint-community/eslint-plugin-eslint-plugin#347).What changes did you make? (Give an overview)
Updated package.json to require
^5.1.0
ofeslint-plugin-eslint-plugin
, updatedeslint.config.js
to use the new flat configs ofeslint-plugin-eslint-plugin
and fixed a few new lint errors.Is there anything you'd like reviewers to focus on?