testing-library / eslint-plugin-testing-library

ESLint plugin to follow best practices and anticipate common mistakes when writing tests with Testing Library
https://npm.im/eslint-plugin-testing-library
MIT License
982 stars 137 forks source link

Prepare the rules for ESLint v9 #899

Open Belco90 opened 5 months ago

Belco90 commented 5 months ago

Plugin version

n/a

What problem do you want to solve?

Your take on the correct solution?

Apply the changes mentioned in the linked migration docs so the custom rules are adapted to ESLint v9 and the

Anything else?

No response

Do you want to submit a pull request to implement this change?

Yes

thenbe commented 4 months ago

An example of a similar migration on another eslint plugin: https://github.com/eslint-community/eslint-plugin-security/pull/145/files

Belco90 commented 4 months ago

@thenbe Thanks for the example! It will definitely help when migrating this plugin.

thenbe commented 4 months ago

For anyone tracking this PR: eslint released some compatibility utilities that allows users to use this plugin in its current state with eslint v9.

tldr:

// eslint.config.js
import testingLibrary from 'eslint-plugin-testing-library';
+ import { fixupPluginRules } from '@eslint/compat';

    {
        files: ['**/*.test.{js,ts,jsx,tsx}'],
        plugins: {
-           'testing-library': {
-               rules: testingLibrary.rules,
-           },
+           'testing-library': fixupPluginRules({
+               rules: testingLibrary.rules,
+           }),
        },
        rules: testingLibrary.configs.react.rules,
    }
jagretz commented 4 months ago

For anyone tracking this PR: eslint released some compatibility utilities that allows users to use this plugin in its current state with eslint v9.

Thank you for this. I didn't remember this existed when I went through the flat-config docs.

For anyone using with eslint-plugin-import, when I add the compat lib, I receive an eslint error above the import statement:

// Parse errors in imported module '@eslint/compat': parserPath or languageOptions.parser is required! (undefined:undefined)  import/namespace
import { fixupPluginRules } from "@eslint/compat";

It's important to note that eslint-plugin-import is (also) not quite ready for flat-config, however, I tested a few rules from eslint-plugin-testing-library and the solution offered by @thenbe is working properly based on my limited testing.

SalahAdDin commented 1 month ago

is there Any ETA for it?

G-Rath commented 1 month ago

I have opened #925 which should resolve this without requiring a new major