sindresorhus / eslint-plugin-unicorn

More than 100 powerful ESLint rules
MIT License
3.98k stars 361 forks source link

Type checking fails in index.js #2394

Closed ericbn closed 5 days ago

ericbn commented 1 week ago

Type checking fails in eslint.config.js containing:

// @ts-check
"use strict";
const eslintPluginUnicorn = require("eslint-plugin-unicorn");
const tseslint = require("typescript-eslint");

module.exports = tseslint.config(
    ...tseslint.configs.recommended,
    eslintPluginUnicorn.configs["flat/recommended"],
//  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    {
        rules: {
            "@typescript-eslint/no-var-requires": "off",
            "unicorn/prefer-module": "off",
            "unicorn/prefer-top-level-await": "off",
        },
    },
);

First error is:

Argument of type '{ rules: any; name: true; plugins: { unicorn: { meta: { name: string; version: string; }; rules: { [x: string]: RuleModule; }; }; }; languageOptions: { globals: any; }; } | { rules: any; plugins: string[]; env: { ...; }; parserOptions: { ...; }; }' is not assignable to parameter of type 'ConfigWithExtends'.
  Type '{ rules: any; name: true; plugins: { unicorn: { meta: { name: string; version: string; }; rules: { [x: string]: Rule.RuleModule; }; }; }; languageOptions: { globals: any; }; }' is not assignable to type 'ConfigWithExtends'.
    Types of property 'name' are incompatible.
      Type 'boolean' is not assignable to type 'string'.ts(2345)

which can be fixed by the following change in index.js:

-const createConfig = (rules, flatConfigName = false) => ({
+const createConfig = (rules, flatConfigName = '') => ({

The following error is:

Argument of type '{ rules: any; name: string; plugins: { unicorn: { meta: { name: string; version: string; }; rules: { [x: string]: RuleModule; }; }; }; languageOptions: { globals: any; }; } | { rules: any; plugins: string[]; env: { ...; }; parserOptions: { ...; }; }' is not assignable to parameter of type 'ConfigWithExtends'.
  Type '{ rules: any; plugins: string[]; env: { es2024: boolean; }; parserOptions: { ecmaVersion: string; sourceType: string; }; }' is not assignable to type 'ConfigWithExtends'.
    Types of property 'plugins' are incompatible.
      Type 'string[]' is not assignable to type 'Plugins'.
        Index signature for type 'string' is missing in type 'string[]'.ts(2345)

Not sure if this is valid change in index.js:

-           : {...legacyConfigBase, plugins: ['unicorn']}
+           : {...legacyConfigBase, plugins: {unicorn}}
johanbook commented 6 days ago

I also bumped into this type error when installing the latest of eslint-plugin-unicorn

ericbn commented 5 days ago

Looks like this is going to be fixed with the next version, with #2382.