Commit 37478d8 1 parent 9aa7aee commit 37478d8 Copy full SHA for 37478d8
File tree 6 files changed +718
-1
lines changed
6 files changed +718
-1
lines changed Original file line number Diff line number Diff line change @@ -328,6 +328,7 @@ set to warn in.\
328
328
| [ prefer-expect-resolves] ( docs/rules/prefer-expect-resolves.md ) | Prefer ` await expect(...).resolves ` over ` expect(await ...) ` syntax | | | 🔧 | |
329
329
| [ prefer-hooks-in-order] ( docs/rules/prefer-hooks-in-order.md ) | Prefer having hooks in a consistent order | | | | |
330
330
| [ prefer-hooks-on-top] ( docs/rules/prefer-hooks-on-top.md ) | Suggest having hooks before any test cases | | | | |
331
+ | [ prefer-importing-jest-globals] ( docs/rules/prefer-importing-jest-globals.md ) | Prefer importing Jest globals | | | 🔧 | |
331
332
| [ prefer-lowercase-title] ( docs/rules/prefer-lowercase-title.md ) | Enforce lowercase test names | | | 🔧 | |
332
333
| [ prefer-mock-promise-shorthand] ( docs/rules/prefer-mock-promise-shorthand.md ) | Prefer mock resolved/rejected shorthands for promises | | | 🔧 | |
333
334
| [ prefer-snapshot-hint] ( docs/rules/prefer-snapshot-hint.md ) | Prefer including a hint with external snapshots | | | | |
Original file line number Diff line number Diff line change
1
+ # Prefer importing Jest globals (` prefer-importing-jest-globals ` )
2
+
3
+ 🔧 This rule is automatically fixable by the
4
+ [ ` --fix ` CLI option] ( https://eslint.org/docs/latest/user-guide/command-line-interface#--fix ) .
5
+
6
+ <!-- end auto-generated rule header -->
7
+
8
+ This rule aims to enforce explicit imports from ` @jest/globals ` .
9
+
10
+ 1 . This is useful for ensuring that the Jest APIs are imported the same way in
11
+ the codebase.
12
+ 2 . When you can't modify Jest's
13
+ [ ` injectGlobals ` ] ( https://jestjs.io/docs/configuration#injectglobals-boolean )
14
+ configuration property, this rule can help to ensure that the Jest globals
15
+ are imported explicitly and facilitate a migration to ` @jest/globals ` .
16
+
17
+ ## Rule details
18
+
19
+ Examples of ** incorrect** code for this rule
20
+
21
+ ``` js
22
+ /* eslint jest/prefer-importing-jest-globals: "error" */
23
+
24
+ describe (' foo' , () => {
25
+ it (' accepts this input' , () => {
26
+ // ...
27
+ });
28
+ });
29
+ ```
30
+
31
+ Examples of ** correct** code for this rule
32
+
33
+ ``` js
34
+ /* eslint jest/prefer-importing-jest-globals: "error" */
35
+
36
+ import { describe , it } from ' @jest/globals' ;
37
+
38
+ describe (' foo' , () => {
39
+ it (' accepts this input' , () => {
40
+ // ...
41
+ });
42
+ });
43
+ ```
44
+
45
+ ## Further Reading
46
+
47
+ - [ Documentation] ( https://jestjs.io/docs/api )
Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ exports[`rules should export configs that refer to actual rules 1`] = `
45
45
" jest/prefer-expect-resolves" : " error" ,
46
46
" jest/prefer-hooks-in-order" : " error" ,
47
47
" jest/prefer-hooks-on-top" : " error" ,
48
+ " jest/prefer-importing-jest-globals" : " error" ,
48
49
" jest/prefer-lowercase-title" : " error" ,
49
50
" jest/prefer-mock-promise-shorthand" : " error" ,
50
51
" jest/prefer-snapshot-hint" : " error" ,
@@ -126,6 +127,7 @@ exports[`rules should export configs that refer to actual rules 1`] = `
126
127
" jest/prefer-expect-resolves" : " error" ,
127
128
" jest/prefer-hooks-in-order" : " error" ,
128
129
" jest/prefer-hooks-on-top" : " error" ,
130
+ " jest/prefer-importing-jest-globals" : " error" ,
129
131
" jest/prefer-lowercase-title" : " error" ,
130
132
" jest/prefer-mock-promise-shorthand" : " error" ,
131
133
" jest/prefer-snapshot-hint" : " error" ,
Original file line number Diff line number Diff line change @@ -2,7 +2,7 @@ import { existsSync } from 'fs';
2
2
import { resolve } from 'path' ;
3
3
import plugin from '../' ;
4
4
5
- const numberOfRules = 52 ;
5
+ const numberOfRules = 53 ;
6
6
const ruleNames = Object . keys ( plugin . rules ) ;
7
7
const deprecatedRules = Object . entries ( plugin . rules )
8
8
. filter ( ( [ , rule ] ) => rule . meta . deprecated )
You can’t perform that action at this time.
0 commit comments