hluisson / eslint-plugin-jsx-expressions

Rules for safe logical expressions in JSX
95 stars 12 forks source link

ESLint v9 support? #18

Open karlhorky opened 3 months ago

karlhorky commented 3 months ago

Hi @hluisson, hope things are good with you!

Running the Quickstart setup for typescript-eslint works with ESLint v9, but adding eslint-plugin-jsx-expressions along with the languageOptions.parserOptions config afterwards leads to an error:

➜  a pnpm eslint . --max-warnings 0                   

Oops! Something went wrong! :(

ESLint: 9.0.0

Error: Error while loading rule 'jsx-expressions/strict-logical-expressions': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser.
Note: detected a parser other than @typescript-eslint/parser. Make sure the parser is configured to forward "parserOptions.project" to @typescript-eslint/parser.
Occurred while linting /Users/k/p/a/eslint.config.js
    at throwError (/Users/k/p/a/node_modules/.pnpm/@typescript-eslint+utils@6.21.0_eslint@9.0.0_typescript@5.4.4/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:39:11)
    at Object.getParserServices (/Users/k/p/a/node_modules/.pnpm/@typescript-eslint+utils@6.21.0_eslint@9.0.0_typescript@5.4.4/node_modules/@typescript-eslint/utils/dist/eslint-utils/getParserServices.js:23:9)
    at create (/Users/k/p/a/node_modules/.pnpm/eslint-plugin-jsx-expressions@1.3.2_@typescript-eslint+parser@7.6.0_eslint@9.0.0_typescript@5_psweyfgckaeztdobw6zk24wuua/node_modules/eslint-plugin-jsx-expressions/dist/rules/strict-logical-expressions.js:60:52)
    at Object.create (/Users/k/p/a/node_modules/.pnpm/@typescript-eslint+utils@6.21.0_eslint@9.0.0_typescript@5.4.4/node_modules/@typescript-eslint/utils/dist/eslint-utils/RuleCreator.js:38:20)
    at createRuleListeners (/Users/k/p/a/node_modules/.pnpm/eslint@9.0.0/node_modules/eslint/lib/linter/linter.js:1003:21)
    at /Users/k/p/a/node_modules/.pnpm/eslint@9.0.0/node_modules/eslint/lib/linter/linter.js:1129:84
    at Array.forEach (<anonymous>)
    at runRules (/Users/k/p/a/node_modules/.pnpm/eslint@9.0.0/node_modules/eslint/lib/linter/linter.js:1061:34)
    at Linter._verifyWithFlatConfigArrayAndWithoutProcessors (/Users/k/p/a/node_modules/.pnpm/eslint@9.0.0/node_modules/eslint/lib/linter/linter.js:1910:31)
    at Linter._verifyWithFlatConfigArray (/Users/k/p/a/node_modules/.pnpm/eslint@9.0.0/node_modules/eslint/lib/linter/linter.js:2046:21)

Config (ESLint Flat Config):

eslint.config.js

// @ts-check

import eslint from '@eslint/js';
import jsxExpressions from 'eslint-plugin-jsx-expressions';
import tseslint from 'typescript-eslint';

export default tseslint.config(
  eslint.configs.recommended,
  ...tseslint.configs.recommendedTypeChecked,
  {
    languageOptions: {
      parserOptions: {
        project: true,
        tsconfigRootDir: import.meta.dirname,
      },
    },
  },
  {
    plugins: { 'jsx-expressions': jsxExpressions },
    rules: {
      'jsx-expressions/strict-logical-expressions': 'error',
    },
  },
);

Downgrading to ESLint v8 (eslint@8.57.0) resolves the issue (1 error is expected):

$ pnpm i
Packages: +28 -18
++++++++++++++++++++++++++++------------------
Progress: resolved 140, reused 140, downloaded 0, added 28, done
The following dependencies have build scripts that were ignored: 

devDependencies:
- @eslint/js 9.0.0
+ @eslint/js 8.57.0 (9.0.0 is available)
- eslint 9.0.0
+ eslint 8.57.0 (9.0.0 is available)

 WARN  Issues with peer dependencies found
.
└─┬ eslint-plugin-jsx-expressions 1.3.2
  └── ✕ unmet peer @typescript-eslint/parser@"^4.0.0 || ^5.0.0 || ^6.0.0": found 7.6.0 in typescript-eslint

Done in 1.1s
$ pnpm eslint . --max-warnings 0

/Users/k/p/repro-eslint-plugin-jsx-expressions-eslint-v9-error/index.ts
  1:7  error  'a' is assigned a value but never used  @typescript-eslint/no-unused-vars

✖ 1 problems (1 errors, 0 warnings)

Reproduction:

cc @JoshuaKGoldberg

JoshuaKGoldberg commented 2 months ago

This should be fixed by #17, I think.