eslint / rewrite

Monorepo for the new version of ESLint
Apache License 2.0
145 stars 11 forks source link

Change Request: Backwards compatibility utility for rules #4

Closed nzakas closed 4 months ago

nzakas commented 5 months ago

ESLint version

HEAD

What problem do you want to solve?

After talking with folks online, it seems that one of the big blockers for people upgrading to ESLint v9.x is that there are still a fair number of plugins that haven't made the changes we outlined in the blog post. This leaves users stuck because they can't migrate to v9.x when their config doesn't work.

What do you think is the correct solution?

I propose creating a new package, @eslint/backcompat, that contains functions that wrap existing rules to create a context object that looks like the pre-9.x object. This package would export three functions:

  1. fixupRule(rule) - to be applied directly to rule objects
  2. fixupPluginRules(plugin) - given a plugin, returns an object where all of the rules are wrapped with fixupRule()
  3. fixConfigRules(configs) - given an array of config objects, wraps all of the plugin definitions using fixupPluginRules().

In most cases people would probably use the package like this:

import { fixupConfigRules } from "@eslint/backcompat";

export default fixupConfigRules([
   // ... their config
]);

Participation

Additional comments

No response

mdjermanovic commented 5 months ago

Sounds good to me, though it might be tricky for the wrapper rule to determine the currently traversed node, which is needed when calling some of the new methods (e.g., SourceCode#getScope(node)).

nzakas commented 5 months ago

I actually already have a prototype of this working. :+1:

aladdin-add commented 5 months ago

SGTM! 👍

Re the naming of this package: there may be other versions needed in the future, considering@eslint/backcompat-v9?

nzakas commented 5 months ago

I think I'll go with @eslint/compat. I'd prefer not to have to create a new utility for every ESLint release, so we can keep adding stuff into this package as needed.