-
Couldn't load subscription status.
- Fork 49.7k
[eprh] Adhere to ESLint.Plugin type #34994
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
base: main
Are you sure you want to change the base?
Conversation
- Use TS `satisfies` operator to ensure `plugin` adheres to the
ESLint.Plugin shape while retaining its actual shape for export.
- Assign configs as part of `plugin` assignment, only delaying the
assignment of the `plugin` property in flat configs. This improves
exported types without hacky assertions.
- BREAKING CHANGE: flatten `configs` to match the expected shape:
- Flat configs are now the default:
- `configs.recommended`
- `configs['recommended-latest']`
- Legacy configs are now prefixed:
- `configs['legacy-recommended']`
- `configs['legacy-recommended-latest']`
|
Un-nesting the flat configs is a good change 👍 It aligns with the consensus we reached back in October 2024. For context, see this comment from the maintainer of eslint (and the surrounding conversation): #30774 (comment) |
|
Should |
- Switch to legacy suffix instead of prefix
I'm impartial. I wasn't actually aware of any of these conversations when I posted this. I went ahead and changed to suffix. |
|
cc @michaelfaith @poteto this PR is a revisiting of the config shape changes discussed with @nzakas in #30774: |
I agree. All-in-all, a big fan of this change. The only thing that might be slightly confusing from a user's perspective is |
| rules: recommendedRuleConfigs, | ||
| }, | ||
| 'recommended-latest': { | ||
| plugins: {'react-hooks': {}}, |
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 might suggest using a get accessor here, rather than assigning to an empty object and then re-assigning later. This is what we're doing in several of the plugins I work on:
e.g.
https://github.com/eslint-community/eslint-plugin-eslint-plugin/blob/main/lib/index.ts#L71-L75
recommended: {
plugins: {
get 'react-hooks'(): ESLint.Plugin {
return plugin;
}
},
rules: recommendedRuleConfigs,
},Not a huge difference in the end, but keeps it self-contained.
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 would like to avoid using ESLint.Plugin directly in the exported type, relying on it only for the satisfies check. Using a getter as proposed requires this type assignment, though; it could not be inferred. {} satisfies the type for initial assignment (which is then replaced) and I don't see this negatively affecting users in a practical sense.
Summary
satisfiesoperator to ensurepluginadheres to the ESLint.Plugin shape while retaining its actual shape for export.pluginassignment, only delaying the assignment of thepluginproperty in flat configs. This improves exported types without hacky assertions.configsto match the expected shape:configs.recommendedconfigs['recommended-latest']configs['recommended-legacy']configs['recommended-latest-legacy']