Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Enhancement: Move RuleCreator into its own package with fewer dependencies than utils #10383

Open
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Before You File a Proposal Please Confirm You Have Done The Following...

Relevant Package

utils

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Description

Coming over from ArnaudBarre/eslint-plugin-react-refresh#62 (comment): @typescript-eslint/utils has quite a few dependencies that are not necessary for RuleCreator: ts-api-utils, @typescript-eslint/scope-manager, @typescript-eslint/typescript-estree. Even once JoshuaKGoldberg/ts-api-utils#573 is fixed that's >1 MB!

It does seem unfortunate to me that if you want to use typescript-eslint's RuleCreator, you have to pull in multiple other packages beyond @typescript-eslint/utils. Some plugins are intended to work in JS(X) environments. Unlike with TS(X), those users might not already have @typescript-eslint/*, ts-api-utils, typescript, etc. already installed.

Proposal: how about we split out a new package that exports RuleCreator and its relevant types? That way users can import { RuleCreator } without taking a dependency on scope-manager, typescript-estree, etc.

I'm not sure what we'd want to call it:

  • @typescript-eslint/rule-creator: but per notes later, I think we'll also want to export module stuff
  • @typescript-eslint/plugin-kit: in isolation I like this name, but @eslint/plugin-kit has the similar name and is about a completely different idea of "plugins"

For now, I'm going to suggest @typescript-eslint/plugin-kit.

Additional Info

Note that "relevant types" will include RuleModule, which at the moment is stored in @typescript-eslint/utils and accessed as TSESLint.RuleModule. I think we'd want to move RuleModule and its associated types to @typescript-eslint/plugin-kit.

For reference, the package storing the typescript-estree AST types is @typescript-eslint/types, which is 173KB per https://pkg-size.dev/@typescript-eslint%2Ftypes?no-peers. Roughly every plugin I remember seeing does have some internal handling for TS AST types - including eslint-plugin-react-refresh (e.g. handling TSEnumDeclaration, handling type assertions).

Also note that I think there's a desire to make plugins not have a full dependency on AST types at all. If a plugin is meant to be used in ESLint config files, it probably only wants to export types for the plugin and its rules + options. I think that means the @typescript-eslint/plugin-kit package will need to be careful with dependencies:

  • It would be a full dependency on any package that uses it: since RuleCreator is a runtime construct
  • It would have an optional peer dependency on @typescript-eslint/types: since AST types would only be relevant during development, and plugin exports would not include any AST info

This was prompted by @ArnaudBarre noting in ArnaudBarre/eslint-plugin-react-refresh#62 (comment) a desire to have nicely typed rule options for a plugin without many megabytes of added dependencies. Thanks for the prod @ArnaudBarre!

💖

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requestteam assignedA member of the typescript-eslint team should work on this.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions