Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint Flat Configuration TypeScript example does not work. #178

Open
thedanchez opened this issue Jan 14, 2025 · 3 comments
Open

ESLint Flat Configuration TypeScript example does not work. #178

thedanchez opened this issue Jan 14, 2025 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@thedanchez
Copy link

thedanchez commented Jan 14, 2025

Describe the bug
I am trying to configure ESLint for Solid using the new flat configuration file format for ESLint and running into errors in the configuration of the plugin.

Expected behavior
I expect the ESLint Flat config file example to work without any problems.

Environment (please complete the following information):

  • OS: macOS 15.1
  • Node version (node --version): 22.11.0
  • eslint-plugin-solid version (npm list eslint-plugin-solid/yarn why eslint-plugin-solid): ^0.14.5
  • eslint version (npm list eslint/yarn why eslint): 9.18.0

Additional context
Using TypeScript config file for ESLint (https://eslint.org/docs/latest/use/configure/configuration-files#typescript-configuration-files)

To Reproduce
Here is my flat config file eslint.config.ts:

import js from "@eslint/js";
import * as tsParser from "@typescript-eslint/parser";
import type { Linter } from "eslint";
import simpleImportSort from "eslint-plugin-simple-import-sort";
import solid from "eslint-plugin-solid/configs/typescript";
import globals from "globals";

export default [
    js.configs.recommended,
    {
        plugins: {
            "simple-import-sort": simpleImportSort,
        },
        rules: {
            "simple-import-sort/imports": "error",
            "simple-import-sort/exports": "error",
        },
    },
    {
        files: ["**/*.ts", "**/*.tsx"],
        ...solid,  // <--- spreading this in causes issues with satisfies Linter.Config[]
        languageOptions: {
            parser: tsParser,
            parserOptions: {
                sourceType: "module",
                project: "./tsconfig.json",
                ecmaFeatures: {
                    jsx: true,
                },
            },
            globals: {
                ...globals.browser,
                ...globals.es2022,
            },
        }
    },
    {
        files: ["backend/**/*.ts"],
        languageOptions: {
            parser: tsParser,
            parserOptions: {
                sourceType: "module",
                project: "./tsconfig.json",
            },
            globals: {
                Bun: true,
            },
        },
    },
    {
        files: ["__tests__/**/*.ts", "__tests__/**/*.tsx"],
        languageOptions: {
            globals: {
                ...globals.node,
                ...globals.vitest,
            }
        },
    },
] satisfies Linter.Config[];

After attempting to spread in the Solid plugin configuration ...solid I get the following error from TypeScript:

Type '{ languageOptions: { parser: typeof tsParser; parserOptions: { sourceType: "module"; project: string; ecmaFeatures: { jsx: true; }; }; globals: { AggregateError: false; Array: false; ArrayBuffer: false; ... 1184 more ...; XSLTProcessor: false; }; }; plugins: { solid: { meta: { name: any; version: any; }; rules: { "c...' is not assignable to type 'Config<RulesRecord>'.
  Types of property 'plugins' are incompatible.
    Type '{ solid: { meta: { name: any; version: any; }; rules: { "components-return-once": RuleModule<"noEarlyReturn" | "noConditionalReturn", [], unknown, RuleListener>; "event-handlers": RuleModule<...>; ... 17 more ...; "no-array-handlers": RuleModule<...>; }; }; }' is not assignable to type 'Record<string, Plugin>'.
      Property 'solid' is incompatible with index signature.
        Type '{ meta: { name: any; version: any; }; rules: { "components-return-once": RuleModule<"noEarlyReturn" | "noConditionalReturn", [], unknown, RuleListener>; "event-handlers": RuleModule<...>; ... 17 more ...; "no-array-handlers": RuleModule<...>; }; }' is not assignable to type 'Plugin'.
          Types of property 'rules' are incompatible.
            Type '{ "components-return-once": RuleModule<"noEarlyReturn" | "noConditionalReturn", [], unknown, RuleListener>; "event-handlers": RuleModule<"naming" | "capitalization" | ... 4 more ... | "spread-handler", [...?], unknown, RuleListener>; ... 17 more ...; "no-array-handlers": RuleModule<...>; }' is not assignable to type 'Record<string, RuleModule>'.
              Property '"components-return-once"' is incompatible with index signature.
                Type 'RuleModule<"noEarlyReturn" | "noConditionalReturn", [], unknown, RuleListener>' is not assignable to type 'RuleModule'.
                  Types of property 'create' are incompatible.
                    Type '(context: Readonly<RuleContext<"noEarlyReturn" | "noConditionalReturn", []>>) => RuleListener' is not assignable to type '(context: RuleContext) => RuleListener'.
                      Types of parameters 'context' and 'context' are incompatible.
                        Type 'RuleContext' is not assignable to type 'Readonly<RuleContext<"noEarlyReturn" | "noConditionalReturn", []>>'.
                          Types of property 'options' are incompatible.
                            Type 'any[]' is not assignable to type '[]'.
                              Target allows only 0 element(s) but source may have more.ts(2322)

I'm unsure exactly what is happening, but I would expect the example in the repository to work without issue.

@thedanchez thedanchez added the bug Something isn't working label Jan 14, 2025
@DustinEwan
Copy link

This looks like a namespace collision issue. I was able to get it to work by doing:

import pluginSolid from "eslint-plug-solid/configs/recommended";

export default [
    // All your other config ...
    pluginSolid,
]

@thedanchez thedanchez changed the title ESLint Flat Configuration example does not work. ESLint Flat Configuration TypeScript example does not work. Jan 21, 2025
@thedanchez
Copy link
Author

This looks like a namespace collision issue. I was able to get it to work by doing:

import pluginSolid from "eslint-plug-solid/configs/recommended";

export default [
// All your other config ...
pluginSolid,
]

Appreciate the reply -- unfortunately, that doesn't apply to TypeScript.

import solid from "eslint-plugin-solid/configs/typescript";

But your example is using:

import pluginSolid from "eslint-plug-solid/configs/recommended";

The crux of the issue has to do with this snippet in the readme not being correct:

import js from "@eslint/js";
import solid from "eslint-plugin-solid/configs/typescript";
import * as tsParser from "@typescript-eslint/parser";

export default [
  js.configs.recommended,
  {
    files: ["**/*.{ts,tsx}"],
    ...solid,
    languageOptions: {
      parser: tsParser,
      parserOptions: {
        project: "tsconfig.json",
      },
    },
  },
];

@thedanchez
Copy link
Author

Are there any updates on this? Would really love to get the ESLint rules working for TypeScript using the new flat config structure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants