oxc-project / eslint-plugin-oxlint

Turn off all rules already supported by oxlint
MIT License
185 stars 12 forks source link

match typescript-extended rules inside `rules` block - `buildFromOxlintConfig` #228

Open Sysix opened 2 weeks ago

Sysix commented 2 weeks ago

Some of the typescript-extended rules are inherently supported by oxlint and thus are only advertised as a single rule.
It's a bit annoying having to match rules when they are different names.

Originally posted by @drvn-mr in https://github.com/oxc-project/eslint-plugin-oxlint/issues/226#issuecomment-2457554398

drvn-mr commented 2 weeks ago

I should've provided an example but I have a script parsing the oxlint --rules output to match our rules. This comes out for rules that are in both eslint and @typescript-eslint, for which only a single rule exists in oxlint:

{
  "@typescript-eslint/default-param-last": "default-param-last",
  "@typescript-eslint/no-array-constructor": "no-array-constructor",
  "@typescript-eslint/no-empty-function": "no-empty-function",
  "@typescript-eslint/no-unused-vars": "no-unused-vars",
  "@typescript-eslint/no-useless-constructor": "no-useless-constructor"
}

I'm not sure if they are currently aliased somehow, so I've renamed them to the oxlint equivalent in the config file. Some of them also don't mention typescript support in the documentation.

Sysix commented 2 weeks ago

oh your use case is fixed with #231.

I found another use case which is not supported:

  it('disables matching typescript and eslint rules', () => {
    for (const rule in [
      'no-unused-vars',
      '@typescript-eslint/no-unused-vars',
    ]) {
      const rules = buildFromOxlintConfig({
        rules: {
          [rule]: 'warn',
        },
      });

      expect(rules.length).toBe(1);
      expect(rules[0].rules).not.toBeUndefined();
      expect('no-unused-vars' in rules[0].rules!).toBe(true);
      expect('@typescript-eslint/no-unused-vars' in rules[0].rules!).toBe(true);
    }
  });