Skip to content
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

Feature: Generate typings for rules etc. #1469

Open
pauliesnug opened this issue Nov 16, 2023 · 4 comments
Open

Feature: Generate typings for rules etc. #1469

pauliesnug opened this issue Nov 16, 2023 · 4 comments

Comments

@pauliesnug
Copy link

Currently we package with Babel to pure JS, but it would be awesome if we could include some .d.ts files with the official build for programmatic, auto-completion, and extension use. This shouldn't be too difficult considering it's already written in TypeScript.

@G-Rath
Copy link
Collaborator

G-Rath commented Nov 16, 2023

Can you provide some real-world examples of where the types would actually be used? (beyond that someone could "one day" want to extend a rule, since I don't think anyone is doing that currently with our rules) My understanding is that ESLint tooling is still not in a good position to properly utilize typings for rules and that that doesn't change with the new flat config format.

The downsides with shipping types is that they add a bit to the package size and increase the surface area of our build infrastructure since Babel doesn't support generating types - neither are particularly costly but relative to not having an actual common real world usecase they're pretty expensive...

@pauliesnug
Copy link
Author

Can you provide some real-world examples of where the types would actually be used? (beyond that someone could "one day" want to extend a rule, since I don't think anyone is doing that currently with our rules) My understanding is that ESLint tooling is still not in a good position to properly utilize typings for rules and that that doesn't change with the new flat config format.

@G-Rath Sure! For this issue to be sparked, I was trying to implement a way to use eslint-plugin-jest with eslint-define-config which is a really awesome strongly-typed way to configure multiple ESLint plugins in a modular way. All of this is to say that without TypeScript types it's impossible to use the features of TypeScript and in some cases impossible to even use the plugin in the first place. Even just an interface with the structure of:

export interface RuleOptions {
       /**
        * this is an example of a description for the rule.
        * 
        * @see [rule-name](https://docs.example.com/rule-name.md)
        */
      'jest/rule-name': string;
}

would make all the difference. This would produce a much lesser impact. Alternatively, types could be provided in a separate package if bundle size is a concern.

@SimenB
Copy link
Member

SimenB commented Mar 6, 2024

I think it would be fine to ship types. We already run tsc, so it'd just be a quick config change to have it emit definition files. Are we certain the generated types helps with eslint-define-config? Seems to me like we need custom code to work with them (https://github.com/eslint-types/eslint-define-config/blob/main/README.md#want-to-support-your-own-plugin), which I don't think we should add (but happy to ship our types if that helps to create your own)

I don't really care about bundle size, but we could also bundle up the types into a single file like we do in Jest (via https://www.npmjs.com/package/@microsoft/api-extractor) in order to minimise the impact

@Logicer16
Copy link
Contributor

that doesn't change with the new flat config format

As the new flat config format requires users to import plugins and their configs themselves, plugins can now be type checked within the config. This is the extra level of support for flat configs currently being tracked within eslint/eslint#18093.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants