Skip to content

Enhancement: Support Lazy Loading Rules #11029

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

Open
4 tasks done
mr-sanders opened this issue Apr 3, 2025 · 5 comments
Open
4 tasks done

Enhancement: Support Lazy Loading Rules #11029

mr-sanders opened this issue Apr 3, 2025 · 5 comments
Labels
blocked by external API Blocked by a tool we depend on exposing an API, such as TypeScript's Type Relationship API enhancement New feature or request

Comments

@mr-sanders
Copy link

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

Relevant Package

eslint-plugin

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

I propose the addition of lazy loading support for rule definitions. As the number of rules grows, it becomes increasingly inefficient to load them all at once. Currently, all rules are loaded eagerly, which can lead to unnecessary memory usage and slower startup times, especially for configurations that use only a subset of rules (e.g., non-type-checking). Additionally, the lack of this mechanism breaks the lazy loading already implemented in the ESLint repository - all rules in the current repository that use the getESLintCoreRule utility eagerly load core rules.

Additional Info

ESLint Config

import tseslint from 'typescript-eslint';

export default tseslint.config({
  files: ['**/*.ts'],
  extends: [tseslint.configs.base],
});

eslint ./index.ts --debug

Expected Result

no eslint rules loaded

Actual Result

  ...
  eslint:rules Loading rule 'consistent-return' (remaining=289) +0ms
  eslint:rules Loading rule 'dot-notation' (remaining=288) +13ms
  eslint:rules Loading rule 'init-declarations' (remaining=287) +5ms
  eslint:rules Loading rule 'max-params' (remaining=286) +1ms
  eslint:rules Loading rule 'no-dupe-class-members' (remaining=285) +16ms
  eslint:rules Loading rule 'no-empty-function' (remaining=284) +4ms
  eslint:rules Loading rule 'no-invalid-this' (remaining=283) +10ms
  eslint:rules Loading rule 'no-loop-func' (remaining=282) +1ms
  eslint:rules Loading rule 'no-loss-of-precision' (remaining=281) +1ms
  eslint:rules Loading rule 'no-magic-numbers' (remaining=280) +1ms
  eslint:rules Loading rule 'no-restricted-imports' (remaining=279) +15ms
  eslint:rules Loading rule 'no-unused-expressions' (remaining=278) +32ms
  eslint:rules Loading rule 'no-useless-constructor' (remaining=277) +2ms
  eslint:rules Loading rule 'prefer-destructuring' (remaining=276) +7ms
  ...
@mr-sanders mr-sanders added enhancement New feature or request triage Waiting for team members to take a look labels Apr 3, 2025
@bradzacher
Copy link
Member

bradzacher commented Apr 4, 2025

I don't know if we can do this. In the past eslint's own API eagerly loaded all of the rules for each plugin because it would eagerly iterate the plugin's .rules property. iirc it called Object.entries(plugin.rules) which meant that any lazy loading implementation didn't do anything.

I filed this with eslint core a whole back and I don't know if they ever changed their implementation. If they have then we could finally rework things to lazily load rules.

@JoshuaKGoldberg
Copy link
Member

Ooh yes lazy-loading rules would be wonderful. This is such a universally useful request I don't think it should be specific typescript-eslint - I think core and every plugin should be ideally do it.

Looking back through the filing history...

  1. Support Lazy Loading Rules from 3rd Party Plugins eslint/eslint#14862: originally marked as blocked pending the new flat config system
  2. eslint/eslint@06439a6 & eslint/eslint@7130a27 & eslint/eslint@32ac37a: marked as closing that issue with tests to confirm flat config rules are lazy loaded

I think this should be filed on ESLint core then. What do you all think?

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Apr 7, 2025
@bradzacher
Copy link
Member

Eslint core can't do anything here - the plugins all need to manually set it up with a proxy or something.

If someone was to build a reusable package that made it easy to export a lazy loaded rule map though...... Might be a good thing for us to build and publish as a package...?

@JoshuaKGoldberg
Copy link
Member

JoshuaKGoldberg commented Apr 7, 2025

Hmm, it would be nice if ESLint core provided its own definePlugin / defineRule. They already provide RuleTester, defineConfig, etc. - seems like a natural next step. I don't love that we in typescript-eslint are now taking on the responsibility of figuring out lazy-loading rules.

@eslint/plugin-kit exists but it's really more of a "languages" kit. Its exports are Directive, ConfigCommentParser, etc. - nothing around defining plugins. I separately tried searching plugin-kit and similar terms on ESLint's issue tracker. This was mentioned almost a decade ago in eslint/eslint#4301 (comment) but that's about it. Filed: eslint/rewrite#176

Back in typescript-eslint: this ties into #10383. We've been wanting to do this for a bit but haven't had the time. It's definitely something we'd love to tackle eventually... but will take a lot of time and dependency shuffling. In the meantime, I think having a standalone plugin-creator package would be a great first step and something we can keep extracted out on its own.

Proposal: let's wait until discussion in eslint/rewrite#176 settles? If ESLint core is up for creating a plugin utils package then I'd think we'd want to wait until their API settles before taking any action.

@JoshuaKGoldberg
Copy link
Member

Marking as blocked pending resolution to eslint/rfcs#132. Whether & how ESLint provides a lazy-loading rules in its definePlugin will determine what we do here.

@JoshuaKGoldberg JoshuaKGoldberg added blocked by external API Blocked by a tool we depend on exposing an API, such as TypeScript's Type Relationship API and removed triage Waiting for team members to take a look awaiting response Issues waiting for a reply from the OP or another party labels May 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked by external API Blocked by a tool we depend on exposing an API, such as TypeScript's Type Relationship API enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants