lasselupe33 / eslint-plugin-comment-length

MIT License
13 stars 3 forks source link

The ESLint plugin has an incorrect TypeScript type #9

Closed jaydenseric closed 10 months ago

jaydenseric commented 10 months ago

ESLint has a new configuration system where you programmatically compose your config using regular JS, and this can be done with type safety via TypeScript:

https://eslint.org/docs/latest/use/configure/configuration-files-new#using-plugins-in-your-configuration

Unfortunately, this ESLint plugin doesn’t satisfy the type import("eslint").ESLint.Plugin.

With this eslint.config.js module:

// @ts-check

import eslintPluginCommentLength from "eslint-plugin-comment-length";

/**
 * ESLint config.
 * @satisfies {Array<import("eslint").Linter.FlatConfig>}
 */
const eslintConfig = [
  {
    files: ["**/*.js"],
    plugins: {
      "comment-length": eslintPluginCommentLength,
    },
    rules: {
      "comment-length/limit-single-line-comments": "error",
      "comment-length/limit-multi-line-comments": "error",
    },
  },
];

export default eslintConfig;

On line 13 the plugin has an invalid type, with this TypeScript error:

Type 'typeof import("[redacted]/node_modules/eslint-plugin-comment-length/lib/index")' is not assignable to type 'Plugin'.
  Types of property 'configs' are incompatible.
    Type '{ recommended: { plugins: string[]; rules: { "comment-length/limit-single-line-comments": string[]; "comment-length/limit-multi-line-comments": string[]; }; }; }' is not assignable to type 'Record<string, FlatConfig | FlatConfig[] | ConfigData<RulesRecord>>'.
      Property 'recommended' is incompatible with index signature.
        Type '{ plugins: string[]; rules: { "comment-length/limit-single-line-comments": string[]; "comment-length/limit-multi-line-comments": string[]; }; }' is not assignable to type 'FlatConfig | FlatConfig[] | ConfigData<RulesRecord>'.
          Type '{ plugins: string[]; rules: { "comment-length/limit-single-line-comments": string[]; "comment-length/limit-multi-line-comments": string[]; }; }' is not assignable to type 'ConfigData<RulesRecord>'.
            Types of property 'rules' are incompatible.
              Type '{ "comment-length/limit-single-line-comments": string[]; "comment-length/limit-multi-line-comments": string[]; }' is not assignable to type 'Partial<RulesRecord>'.
                Property '"comment-length/limit-single-line-comments"' is incompatible with index signature.
                  Type 'string[]' is not assignable to type 'RuleEntry<any[]> | undefined'.
                    Type 'string[]' is not assignable to type '[_: RuleLevel, ..._1: any[]]'.
                      Source provides no match for required element at position 0 in target.
Screenshot 2023-08-17 at 1 30 39 pm
lasselupe33 commented 10 months ago

Hi @jaydenseric, the plugin should now support the ESLint Flat Config, starting from v1.6.1. :)