@@ -22,28 +22,43 @@ yarn add --dev eslint eslint-plugin-jest
2222
2323## Usage
2424
25- > [ !NOTE]
26- >
27- > ` eslint.config.js ` is supported, though most of the plugin documentation still
28- > currently uses ` .eslintrc ` syntax.
29- >
30- > Refer to the
31- > [ ESLint documentation on the new configuration file format] ( https://eslint.org/docs/latest/use/configure/configuration-files-new )
32- > for more.
25+ If you're using flat configuration:
3326
34- Add ` jest ` to the plugins section of your ` .eslintrc ` configuration file. You
35- can omit the ` eslint-plugin- ` prefix:
27+ With
28+ [ flat configuration] ( https://eslint.org/docs/latest/use/configure/configuration-files ) ,
29+ just import the plugin and away you go:
3630
37- ``` json
38- {
39- "plugins" : [" jest" ]
40- }
31+ ``` js
32+ const pluginJest = require (' eslint-plugin-jest' );
33+
34+ module .exports = [
35+ {
36+ // update this to match your test files
37+ files: [' **/*.spec.js' , ' **/*.test.js' ],
38+ plugins: { jest: pluginJest },
39+ languageOptions: {
40+ globals: pluginJest .environments .globals .globals ,
41+ },
42+ rules: {
43+ ' jest/no-disabled-tests' : ' warn' ,
44+ ' jest/no-focused-tests' : ' error' ,
45+ ' jest/no-identical-title' : ' error' ,
46+ ' jest/prefer-to-have-length' : ' warn' ,
47+ ' jest/valid-expect' : ' error' ,
48+ },
49+ },
50+ ];
4151```
4252
43- Then configure the rules you want to use under the rules section.
53+ With legacy configuration, add ` jest ` to the plugins section of your ` .eslintrc `
54+ configuration file. You can omit the ` eslint-plugin- ` prefix:
4455
4556``` json
4657{
58+ "plugins" : [" jest" ],
59+ "env" : {
60+ "jest/globals" : true
61+ },
4762 "rules" : {
4863 "jest/no-disabled-tests" : " warn" ,
4964 "jest/no-focused-tests" : " error" ,
@@ -54,19 +69,10 @@ Then configure the rules you want to use under the rules section.
5469}
5570```
5671
57- You can also tell ESLint about the environment variables provided by Jest by
58- doing:
59-
60- ``` json
61- {
62- "env" : {
63- "jest/globals" : true
64- }
65- }
66- ```
67-
68- This is included in all configs shared by this plugin, so can be omitted if
69- extending them.
72+ > [ !NOTE]
73+ >
74+ > You only need to explicitly include our globals if you're not using one of our
75+ > shared configs
7076
7177#### Aliased Jest globals
7278
0 commit comments