@@ -22,28 +22,43 @@ yarn add --dev eslint eslint-plugin-jest
22
22
23
23
## Usage
24
24
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:
33
26
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:
36
30
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
+ ];
41
51
```
42
52
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:
44
55
45
56
``` json
46
57
{
58
+ "plugins" : [" jest" ],
59
+ "env" : {
60
+ "jest/globals" : true
61
+ },
47
62
"rules" : {
48
63
"jest/no-disabled-tests" : " warn" ,
49
64
"jest/no-focused-tests" : " error" ,
@@ -54,19 +69,10 @@ Then configure the rules you want to use under the rules section.
54
69
}
55
70
```
56
71
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
70
76
71
77
#### Aliased Jest globals
72
78
0 commit comments