eslint / rewrite

Monorepo for the new version of ESLint
Apache License 2.0
65 stars 4 forks source link

Bug: can't enable recommendedTypeChecked and lint tsx files #58

Closed damianobarbati closed 2 weeks ago

damianobarbati commented 2 weeks ago

Which packages are affected?

Environment

Node version: 22 pnpm version: 9 ESLint version: 9 Operating System: MacOS

What did you do?

I migrated to eslint 9.

What did you expect to happen?

Have tsx files linted.

What actually happened?

I cannot have a valid eslint 9 + react + typescript configuration file working if I enable the tslint.configs.recommendedTypeChecked.

Repro here: https://github.com/damianobarbati/eslint-v9

To reproduce:

git clone git@github.com:damianobarbati/eslint-v9.git
cd eslint-v9
pnpm i
pnpm eslint src/__tests__/test.tsx

Output:

Oops! Something went wrong! :(

ESLint: 9.5.0

ConfigError: Config (unnamed): Unexpected key "0" found.
    at rethrowConfigError (/Users/damians/Desktop/eslint-v9/node_modules/.pnpm/@eslint+config-array@0.16.0/node_modules/@eslint/config-array/dist/cjs/index.cjs:302:8)
    at /Users/damians/Desktop/eslint-v9/node_modules/.pnpm/@eslint+config-array@0.16.0/node_modules/@eslint/config-array/dist/cjs/index.cjs:1097:5
    at Array.reduce (<anonymous>)
    at FlatConfigArray.getConfigWithStatus (/Users/damians/Desktop/eslint-v9/node_modules/.pnpm/@eslint+config-array@0.16.0/node_modules/@eslint/config-array/dist/cjs/index.cjs:1090:43)
    at FlatConfigArray.getConfig (/Users/damians/Desktop/eslint-v9/node_modules/.pnpm/@eslint+config-array@0.16.0/node_modules/@eslint/config-array/dist/cjs/index.cjs:1119:15)
    at /Users/damians/Desktop/eslint-v9/node_modules/.pnpm/eslint@9.5.0/node_modules/eslint/lib/eslint/eslint.js:870:40
    at Array.map (<anonymous>)
    at ESLint.lintFiles (/Users/damians/Desktop/eslint-v9/node_modules/.pnpm/eslint@9.5.0/node_modules/eslint/lib/eslint/eslint.js:868:23)
    at async Object.execute (/Users/damians/Desktop/eslint-v9/node_modules/.pnpm/eslint@9.5.0/node_modules/eslint/lib/cli.js:500:23)
    at async main (/Users/damians/Desktop/eslint-v9/node_modules/.pnpm/eslint@9.5.0/node_modules/eslint/bin/eslint.js:153:22)

Also trying to apply the following, results in the file being excluded from parsing for now apparent reason:

// @ts-check
import { fixupPluginRules } from '@eslint/compat';
import pluginReact from 'eslint-plugin-react';
import pluginReactHooks from 'eslint-plugin-react-hooks';

/** @type {import('@typescript-eslint/utils').TSESLint.FlatConfig.ConfigFile} */
export const reactConfig = [
  {
    files: ['**/*.{jsx,tsx}'],
    languageOptions: {
      parserOptions: {
        project: ['tsconfig.json'],
        ecmaFeatures: { jsx: true },
      },
    },
    settings: {
      react: {
        version: 'detect',
      },
    },
    plugins: {
      react: fixupPluginRules(pluginReact),
      'react-hooks': pluginReactHooks,
    },
    rules: {
      'react/void-dom-elements-no-children': 'error',
      'react-hooks/rules-of-hooks': 'error',
      'react-hooks/exhaustive-deps': 'error',
    },
  },
];

Link to Minimal Reproducible Example

https://github.com/damianobarbati/eslint-v9

Participation

Additional comments

Following up this issue (https://github.com/typescript-eslint/typescript-eslint/issues/9368) that @bradzacher gently closed without providing valid reasoning,

damianobarbati commented 2 weeks ago

I'll move this to typescript-eslint github as I think this is mostly due to a problem with their plugin and not this one.

damianobarbati commented 2 weeks ago

Sorry for the noise, that's where I had originally raised the issue and they just closed reporting it was an issue with eslint compat.

bradzacher commented 2 weeks ago

gently closed without providing valid reasoning

You chose to just react to my comments instead of responding? I closed it because my original statement is correct:

This isn't a bug with anything. Your config is just wrong somewhere.

We have many users using our configs - including our own monorepo. Something is wrong in your config somewhere. ESLint's error is opaque and unclear but it's unlikely to be a bug within eslint itself.

The error message states Config (unnamed):. unnamed because it's one of your local config objects without a name or another 3rd-party config without a name. The typescript eslint configs have names defined - so it's not one of the typescript-eslint ones.

I'll ask the same question which you just thumbed down instead of responding to:

Have you tried debugging to figure out which specific config is breaking? For example - comment each config [object] out one by one to determine which [config object] is the one that's breaking things?

damianobarbati commented 2 weeks ago

You chose to just react to my comments instead of responding? Sorry, I saw the issue closed right away, I thought I could not answer there (@_@). I'm closing this here and reporting there.

@bradzacher yes I did, I also went back to tslint.config wrapping the configs, but the problem is still there which makes me think the problem is typescript / tsconfig itself, which I'm focusing on right now.