wikimedia / eslint-docgen

Automatically generate ESLint plugin documentation from rule metadata and test cases.
MIT License
10 stars 7 forks source link

Support for TSESlint #124

Open jpoehnelt opened 2 years ago

jpoehnelt commented 2 years ago

I use TSESLint, https://www.npmjs.com/package/@typescript-eslint/experimental-utils, for my custom rules which adds TypeScript support to the RuleTester. It would be nice if this was supported more cleanly.

My workaround is below.


import { ESLintUtils, TSESLint } from "@typescript-eslint/experimental-utils";
import { RuleTester as DocRuleTester } from "eslint-docgen";

export class RuleTester extends DocRuleTester implements TSESLint.RuleTester {
  constructor(options: TSESLint.RuleTesterConfig) {
    super(options);
  }

  public run<TMessageIds extends string, TOptions extends readonly unknown[]>(
    ruleName: string,
    rule: TSESLint.RuleModule<TMessageIds, TOptions, TSESLint.RuleListener>,
    tests: TSESLint.RunTests<TMessageIds, TOptions>
  ): void {
    return super.run.call(this, ruleName, rule, tests);
  }
  public defineRule<
    TMessageIds extends string,
    TOptions extends readonly unknown[]
  >(
    name: string,
    rule:
      | TSESLint.RuleModule<TMessageIds, TOptions, TSESLint.RuleListener>
      | TSESLint.RuleCreateFunction<
          TMessageIds,
          TOptions,
          TSESLint.RuleListener
        >
  ): void {
    super.defineRule.call(this, name, rule);
  }
}```
jpoehnelt commented 2 years ago

Probably need to extend/fix the TSESLint.RuleTesterConfig to match the JSON schema too.