-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Enhancement(eslint-plugin): Export types of rules option for flat config #8571
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
Comments
And so I raise this PR |
Personally I think could be a good and reasonable idea. Now that configs can be typed and are generally made in JS/TS land, folks will want to have nice typing around their rule options. cc @bradzacher as this goes pretty directly against: typescript-eslint/packages/eslint-plugin/rules.d.ts Lines 2 to 4 in 8ef5f4b
See the rest of that long comment. It has a lot of good info for why this isn't easy or straightforward to do. I think it could be made to work by just keying the rule names and their types, rather than the rules themselves - but it might be tricky. In order to get this to work, I think we have a couple of blockers:
A few tangential notes, by the way...
Err, ESLint that I know of doesn't support
We strongly recommend not doing this. If you refer to rules from the same plugin with a different prefix than another shared config, then they can get configured twice. 😬 |
This is something I have wanted to do for a while and is one of the reasons that I built the type generator for json schema (that we use for tests and docs). Flat config does give us a good way to do it now - but it is quite complicated to get the types working safely. We don't really want to just do global type augmentation and instead we would want something using generics. But the generics are hard because the user can do whatever they want with plugin namespaces. Shareable configs also complicate things cos they can do the same, but obfuscated. If you remember this was the genesis behind this idea for an API - we could make the types safe if we make the user declare the canonical form up-front. Would also make the generics easy. |
Side note that because we chose not to do anything with legacy configs there was this project that spun up. |
Yeah maybe this would be a good first step towards an API? We can treat this issue as tracking just the exposure of the canonical rule names & options, and use that as a basis to work on more scaffolding next. |
It doesn't go against it. We still won't want to generate declarations via Ideally this would be a new tool that we'd release for the ecosystem! |
@linlinyang With the current direction of eslint/rfcs#126, static analysis of rule options looks like a possibility to be proposed upstream in eslint, and I'd like to see such a proposal happen. I'm happy to adapt your POC to make sense for eslint and give you co-author credit. Or, if you'd like to initiate the proposal yourself, you're welcome to. Let |
I'm trying to provide similar functionalities for my shared config package via https://github.com/antfu/eslint-typegen. But there's an issue that prevents me from doing so: Would the team be open to a pull request that refactors this type and makes userland solutions like |
Before You File a Proposal Please Confirm You Have Done The Following...
Description
I hope I can define ts lint rules in my flat
eslint.config.ts
which will be compared toeslint.config.js
like this:And It helpful for define rule with prefix:
In use of:
The text was updated successfully, but these errors were encountered: