eslint-plugin-jest 27.8.0 → 28.0.0-next.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -22,6 +22,15 @@ 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.
33
+
25
34
  Add `jest` to the plugins section of your `.eslintrc` configuration file. You
26
35
  can omit the `eslint-plugin-` prefix:
27
36
 
@@ -85,7 +94,7 @@ test-related. This means it's generally not suitable to include them in your
85
94
  top-level configuration as that applies to all files being linted which can
86
95
  include source files.
87
96
 
88
- You can use
97
+ For `.eslintrc` configs you can use
89
98
  [overrides](https://eslint.org/docs/user-guide/configuring/configuration-files#how-do-overrides-work)
90
99
  to have ESLint apply additional rules to specific files:
91
100
 
@@ -106,6 +115,30 @@ to have ESLint apply additional rules to specific files:
106
115
  }
107
116
  ```
108
117
 
118
+ For `eslint.config.js` you can use
119
+ [`files` and `ignores`](https://eslint.org/docs/latest/use/configure/configuration-files-new#specifying-files-and-ignores):
120
+
121
+ ```js
122
+ const jest = require('eslint-plugin-jest');
123
+
124
+ module.exports = [
125
+ ...require('@eslint/js').configs.recommended,
126
+ {
127
+ files: ['test/**'],
128
+ ...jest.configs['flat/recommended'],
129
+ rules: {
130
+ ...jest.configs['flat/recommended'].rules,
131
+ 'jest/prefer-expect-assertions': 'off',
132
+ },
133
+ },
134
+ // you can also configure jest rules in other objects, so long as some of the `files` match
135
+ {
136
+ files: ['test/**'],
137
+ rules: { 'jest/prefer-expect-assertions': 'off' },
138
+ },
139
+ ];
140
+ ```
141
+
109
142
  ### Jest `version` setting
110
143
 
111
144
  The behaviour of some rules (specifically [`no-deprecated-functions`][]) change
@@ -145,13 +178,18 @@ module.exports = {
145
178
 
146
179
  ## Shareable configurations
147
180
 
181
+ > [!NOTE]
182
+ >
183
+ > `eslint.config.js` compatible versions of configs are available prefixed with
184
+ > `flat/` and may be subject to small breaking changes while ESLint v9 is being
185
+ > finalized.
186
+
148
187
  ### Recommended
149
188
 
150
189
  This plugin exports a recommended configuration that enforces good testing
151
190
  practices.
152
191
 
153
- To enable this configuration use the `extends` property in your `.eslintrc`
154
- config file:
192
+ To enable this configuration with `.eslintrc`, use the `extends` property:
155
193
 
156
194
  ```json
157
195
  {
@@ -159,6 +197,22 @@ config file:
159
197
  }
160
198
  ```
161
199
 
200
+ To enable this configuration with `eslint.config.js`, use
201
+ `jest.configs['flat/recommended']`:
202
+
203
+ ```js
204
+ const jest = require('eslint-plugin-jest');
205
+
206
+ module.exports = [
207
+ {
208
+ files: [
209
+ /* glob matching your test files */
210
+ ],
211
+ ...jest.configs['flat/recommended'],
212
+ },
213
+ ];
214
+ ```
215
+
162
216
  ### Style
163
217
 
164
218
  This plugin also exports a configuration named `style`, which adds some
@@ -174,9 +228,21 @@ config file:
174
228
  }
175
229
  ```
176
230
 
177
- See
178
- [ESLint documentation](https://eslint.org/docs/user-guide/configuring/configuration-files#extending-configuration-files)
179
- for more information about extending configuration files.
231
+ To enable this configuration with `eslint.config.js`, use
232
+ `jest.configs['flat/style']`:
233
+
234
+ ```js
235
+ const jest = require('eslint-plugin-jest');
236
+
237
+ module.exports = [
238
+ {
239
+ files: [
240
+ /* glob matching your test files */
241
+ ],
242
+ ...jest.configs['flat/style'],
243
+ },
244
+ ];
245
+ ```
180
246
 
181
247
  ### All
182
248
 
@@ -189,10 +255,55 @@ If you want to enable all rules instead of only some you can do so by adding the
189
255
  }
190
256
  ```
191
257
 
258
+ To enable this configuration with `eslint.config.js`, use
259
+ `jest.configs['flat/all']`:
260
+
261
+ ```js
262
+ const jest = require('eslint-plugin-jest');
263
+
264
+ module.exports = [
265
+ {
266
+ files: [
267
+ /* glob matching your test files */
268
+ ],
269
+ ...jest.configs['flat/all'],
270
+ },
271
+ ];
272
+ ```
273
+
192
274
  While the `recommended` and `style` configurations only change in major versions
193
275
  the `all` configuration may change in any release and is thus unsuited for
194
276
  installations requiring long-term consistency.
195
277
 
278
+ ## Snapshot processing
279
+
280
+ > [!NOTE]
281
+ >
282
+ > This is only relevant for `eslint.config.js`
283
+
284
+ This plugin provides a
285
+ [custom processor](https://eslint.org/docs/latest/extend/custom-processors) to
286
+ allow rules to "lint" snapshot files.
287
+
288
+ For `.eslintrc` based configs, this is automatically enabled out of the box but
289
+ must be opted into for `eslint.config.js` using the `flat/snapshots` config:
290
+
291
+ ```js
292
+ const jest = require('eslint-plugin-jest');
293
+
294
+ module.exports = [
295
+ {
296
+ ...jest.configs['flat/snapshots'],
297
+ rules: {
298
+ 'jest/no-large-snapshots': ['error', { maxSize: 1 }],
299
+ },
300
+ },
301
+ ];
302
+ ```
303
+
304
+ Unlike other configs, this includes a `files` array that matches `.snap` files
305
+ meaning you can use it directly
306
+
196
307
  ## Rules
197
308
 
198
309
  <!-- begin auto-generated rules list -->
@@ -207,69 +318,67 @@ set to warn in.\
207
318
  🎨 Set in the `style` [configuration](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).\
208
319
  🔧 Automatically fixable by the
209
320
  [`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
210
- 💡 Manually fixable by [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).\
211
- ❌ Deprecated.
212
-
213
- | Name                          | Description | 💼 | ⚠️ | 🔧 | 💡 | |
214
- | :--------------------------------------------------------------------------- | :------------------------------------------------------------------------ | :-- | :-- | :-- | :-- | :-- |
215
- | [consistent-test-it](docs/rules/consistent-test-it.md) | Enforce `test` and `it` usage conventions | | | 🔧 | | |
216
- | [expect-expect](docs/rules/expect-expect.md) | Enforce assertion to be made in a test body | | ✅ | | | |
217
- | [max-expects](docs/rules/max-expects.md) | Enforces a maximum number assertion calls in a test body | | | | | |
218
- | [max-nested-describe](docs/rules/max-nested-describe.md) | Enforces a maximum depth to nested describe calls | | | | | |
219
- | [no-alias-methods](docs/rules/no-alias-methods.md) | Disallow alias methods | | 🎨 | 🔧 | | |
220
- | [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | Disallow commented out tests | | ✅ | | | |
221
- | [no-conditional-expect](docs/rules/no-conditional-expect.md) | Disallow calling `expect` conditionally | | | | | |
222
- | [no-conditional-in-test](docs/rules/no-conditional-in-test.md) | Disallow conditional logic in tests | | | | | |
223
- | [no-confusing-set-timeout](docs/rules/no-confusing-set-timeout.md) | Disallow confusing usages of jest.setTimeout | | | | | |
224
- | [no-deprecated-functions](docs/rules/no-deprecated-functions.md) | Disallow use of deprecated functions | ✅ | | 🔧 | | |
225
- | [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | | ✅ | | | |
226
- | [no-done-callback](docs/rules/no-done-callback.md) | Disallow using a callback in asynchronous tests and hooks || | | 💡 | |
227
- | [no-duplicate-hooks](docs/rules/no-duplicate-hooks.md) | Disallow duplicate setup and teardown hooks | | | | | |
228
- | [no-export](docs/rules/no-export.md) | Disallow using `exports` in files containing tests | ✅ | | | | |
229
- | [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | | | | 💡 | |
230
- | [no-hooks](docs/rules/no-hooks.md) | Disallow setup and teardown hooks | | | | | |
231
- | [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | ✅ | | | | |
232
- | [no-if](docs/rules/no-if.md) | Disallow conditional logic | | | | | ❌ |
233
- | [no-interpolation-in-snapshots](docs/rules/no-interpolation-in-snapshots.md) | Disallow string interpolation inside snapshots | ✅ | | | | |
234
- | [no-jasmine-globals](docs/rules/no-jasmine-globals.md) | Disallow Jasmine globals | ✅ | | 🔧 | | |
235
- | [no-large-snapshots](docs/rules/no-large-snapshots.md) | Disallow large snapshots | | | | | |
236
- | [no-mocks-import](docs/rules/no-mocks-import.md) | Disallow manually importing from `__mocks__` | ✅ | | | | |
237
- | [no-restricted-jest-methods](docs/rules/no-restricted-jest-methods.md) | Disallow specific `jest.` methods | | | | | |
238
- | [no-restricted-matchers](docs/rules/no-restricted-matchers.md) | Disallow specific matchers & modifiers | | | | | |
239
- | [no-standalone-expect](docs/rules/no-standalone-expect.md) | Disallow using `expect` outside of `it` or `test` blocks | ✅ | | | | |
240
- | [no-test-prefixes](docs/rules/no-test-prefixes.md) | Require using `.only` and `.skip` over `f` and `x` | | | 🔧 | | |
241
- | [no-test-return-statement](docs/rules/no-test-return-statement.md) | Disallow explicitly returning from tests | | | | | |
242
- | [no-untyped-mock-factory](docs/rules/no-untyped-mock-factory.md) | Disallow using `jest.mock()` factories without an explicit type parameter | | | 🔧 | | |
243
- | [prefer-called-with](docs/rules/prefer-called-with.md) | Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()` | | | | | |
244
- | [prefer-comparison-matcher](docs/rules/prefer-comparison-matcher.md) | Suggest using the built-in comparison matchers | | | 🔧 | | |
245
- | [prefer-each](docs/rules/prefer-each.md) | Prefer using `.each` rather than manual loops | | | | | |
246
- | [prefer-equality-matcher](docs/rules/prefer-equality-matcher.md) | Suggest using the built-in equality matchers | | | | 💡 | |
247
- | [prefer-expect-assertions](docs/rules/prefer-expect-assertions.md) | Suggest using `expect.assertions()` OR `expect.hasAssertions()` | | | | 💡 | |
248
- | [prefer-expect-resolves](docs/rules/prefer-expect-resolves.md) | Prefer `await expect(...).resolves` over `expect(await ...)` syntax | | | 🔧 | | |
249
- | [prefer-hooks-in-order](docs/rules/prefer-hooks-in-order.md) | Prefer having hooks in a consistent order | | | | | |
250
- | [prefer-hooks-on-top](docs/rules/prefer-hooks-on-top.md) | Suggest having hooks before any test cases | | | | | |
251
- | [prefer-lowercase-title](docs/rules/prefer-lowercase-title.md) | Enforce lowercase test names | | | 🔧 | | |
252
- | [prefer-mock-promise-shorthand](docs/rules/prefer-mock-promise-shorthand.md) | Prefer mock resolved/rejected shorthands for promises | | | 🔧 | | |
253
- | [prefer-snapshot-hint](docs/rules/prefer-snapshot-hint.md) | Prefer including a hint with external snapshots | | | | | |
254
- | [prefer-spy-on](docs/rules/prefer-spy-on.md) | Suggest using `jest.spyOn()` | | | 🔧 | | |
255
- | [prefer-strict-equal](docs/rules/prefer-strict-equal.md) | Suggest using `toStrictEqual()` | | | | 💡 | |
256
- | [prefer-to-be](docs/rules/prefer-to-be.md) | Suggest using `toBe()` for primitive literals | 🎨 | | 🔧 | | |
257
- | [prefer-to-contain](docs/rules/prefer-to-contain.md) | Suggest using `toContain()` | 🎨 | | 🔧 | | |
258
- | [prefer-to-have-length](docs/rules/prefer-to-have-length.md) | Suggest using `toHaveLength()` | 🎨 | | 🔧 | | |
259
- | [prefer-todo](docs/rules/prefer-todo.md) | Suggest using `test.todo` | | | 🔧 | | |
260
- | [require-hook](docs/rules/require-hook.md) | Require setup and teardown code to be within a hook | | | | | |
261
- | [require-to-throw-message](docs/rules/require-to-throw-message.md) | Require a message for `toThrow()` | | | | | |
262
- | [require-top-level-describe](docs/rules/require-top-level-describe.md) | Require test cases and hooks to be inside a `describe` block | | | | | |
263
- | [valid-describe-callback](docs/rules/valid-describe-callback.md) | Enforce valid `describe()` callback | ✅ | | | | |
264
- | [valid-expect](docs/rules/valid-expect.md) | Enforce valid `expect()` usage | ✅ | | | | |
265
- | [valid-expect-in-promise](docs/rules/valid-expect-in-promise.md) | Require promises that have expectations in their chain to be valid | ✅ | | | | |
266
- | [valid-title](docs/rules/valid-title.md) | Enforce valid titles | ✅ | | 🔧 | | |
321
+ 💡 Manually fixable by [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
322
+
323
+ | Name                          | Description | 💼 | ⚠️ | 🔧 | 💡 |
324
+ | :--------------------------------------------------------------------------- | :------------------------------------------------------------------------ | :-- | :-- | :-- | :-- |
325
+ | [consistent-test-it](docs/rules/consistent-test-it.md) | Enforce `test` and `it` usage conventions | | | 🔧 | |
326
+ | [expect-expect](docs/rules/expect-expect.md) | Enforce assertion to be made in a test body | | | | |
327
+ | [max-expects](docs/rules/max-expects.md) | Enforces a maximum number assertion calls in a test body | | | | |
328
+ | [max-nested-describe](docs/rules/max-nested-describe.md) | Enforces a maximum depth to nested describe calls | | | | |
329
+ | [no-alias-methods](docs/rules/no-alias-methods.md) | Disallow alias methods | ✅ | 🎨 | 🔧 | |
330
+ | [no-commented-out-tests](docs/rules/no-commented-out-tests.md) | Disallow commented out tests | | | | |
331
+ | [no-conditional-expect](docs/rules/no-conditional-expect.md) | Disallow calling `expect` conditionally | ✅ | | | |
332
+ | [no-conditional-in-test](docs/rules/no-conditional-in-test.md) | Disallow conditional logic in tests | | | | |
333
+ | [no-confusing-set-timeout](docs/rules/no-confusing-set-timeout.md) | Disallow confusing usages of jest.setTimeout | | | | |
334
+ | [no-deprecated-functions](docs/rules/no-deprecated-functions.md) | Disallow use of deprecated functions || | 🔧 | |
335
+ | [no-disabled-tests](docs/rules/no-disabled-tests.md) | Disallow disabled tests | | | | |
336
+ | [no-done-callback](docs/rules/no-done-callback.md) | Disallow using a callback in asynchronous tests and hooks | ✅ | | | 💡 |
337
+ | [no-duplicate-hooks](docs/rules/no-duplicate-hooks.md) | Disallow duplicate setup and teardown hooks | | | | |
338
+ | [no-export](docs/rules/no-export.md) | Disallow using `exports` in files containing tests || | | |
339
+ | [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ✅ | | | 💡 |
340
+ | [no-hooks](docs/rules/no-hooks.md) | Disallow setup and teardown hooks | | | | |
341
+ | [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | | | | |
342
+ | [no-interpolation-in-snapshots](docs/rules/no-interpolation-in-snapshots.md) | Disallow string interpolation inside snapshots | ✅ | | | |
343
+ | [no-jasmine-globals](docs/rules/no-jasmine-globals.md) | Disallow Jasmine globals || | 🔧 | |
344
+ | [no-large-snapshots](docs/rules/no-large-snapshots.md) | Disallow large snapshots | | | | |
345
+ | [no-mocks-import](docs/rules/no-mocks-import.md) | Disallow manually importing from `__mocks__` | ✅ | | | |
346
+ | [no-restricted-jest-methods](docs/rules/no-restricted-jest-methods.md) | Disallow specific `jest.` methods | | | | |
347
+ | [no-restricted-matchers](docs/rules/no-restricted-matchers.md) | Disallow specific matchers & modifiers | | | | |
348
+ | [no-standalone-expect](docs/rules/no-standalone-expect.md) | Disallow using `expect` outside of `it` or `test` blocks || | | |
349
+ | [no-test-prefixes](docs/rules/no-test-prefixes.md) | Require using `.only` and `.skip` over `f` and `x` || | 🔧 | |
350
+ | [no-test-return-statement](docs/rules/no-test-return-statement.md) | Disallow explicitly returning from tests | | | | |
351
+ | [no-untyped-mock-factory](docs/rules/no-untyped-mock-factory.md) | Disallow using `jest.mock()` factories without an explicit type parameter | | | 🔧 | |
352
+ | [prefer-called-with](docs/rules/prefer-called-with.md) | Suggest using `toBeCalledWith()` or `toHaveBeenCalledWith()` | | | | |
353
+ | [prefer-comparison-matcher](docs/rules/prefer-comparison-matcher.md) | Suggest using the built-in comparison matchers | | | 🔧 | |
354
+ | [prefer-each](docs/rules/prefer-each.md) | Prefer using `.each` rather than manual loops | | | | |
355
+ | [prefer-equality-matcher](docs/rules/prefer-equality-matcher.md) | Suggest using the built-in equality matchers | | | | 💡 |
356
+ | [prefer-expect-assertions](docs/rules/prefer-expect-assertions.md) | Suggest using `expect.assertions()` OR `expect.hasAssertions()` | | | | 💡 |
357
+ | [prefer-expect-resolves](docs/rules/prefer-expect-resolves.md) | Prefer `await expect(...).resolves` over `expect(await ...)` syntax | | | 🔧 | |
358
+ | [prefer-hooks-in-order](docs/rules/prefer-hooks-in-order.md) | Prefer having hooks in a consistent order | | | | |
359
+ | [prefer-hooks-on-top](docs/rules/prefer-hooks-on-top.md) | Suggest having hooks before any test cases | | | | |
360
+ | [prefer-lowercase-title](docs/rules/prefer-lowercase-title.md) | Enforce lowercase test names | | | 🔧 | |
361
+ | [prefer-mock-promise-shorthand](docs/rules/prefer-mock-promise-shorthand.md) | Prefer mock resolved/rejected shorthands for promises | | | 🔧 | |
362
+ | [prefer-snapshot-hint](docs/rules/prefer-snapshot-hint.md) | Prefer including a hint with external snapshots | | | | |
363
+ | [prefer-spy-on](docs/rules/prefer-spy-on.md) | Suggest using `jest.spyOn()` | | | 🔧 | |
364
+ | [prefer-strict-equal](docs/rules/prefer-strict-equal.md) | Suggest using `toStrictEqual()` | | | | 💡 |
365
+ | [prefer-to-be](docs/rules/prefer-to-be.md) | Suggest using `toBe()` for primitive literals | 🎨 | | 🔧 | |
366
+ | [prefer-to-contain](docs/rules/prefer-to-contain.md) | Suggest using `toContain()` | 🎨 | | 🔧 | |
367
+ | [prefer-to-have-length](docs/rules/prefer-to-have-length.md) | Suggest using `toHaveLength()` | 🎨 | | 🔧 | |
368
+ | [prefer-todo](docs/rules/prefer-todo.md) | Suggest using `test.todo` | | | 🔧 | |
369
+ | [require-hook](docs/rules/require-hook.md) | Require setup and teardown code to be within a hook | | | | |
370
+ | [require-to-throw-message](docs/rules/require-to-throw-message.md) | Require a message for `toThrow()` | | | | |
371
+ | [require-top-level-describe](docs/rules/require-top-level-describe.md) | Require test cases and hooks to be inside a `describe` block | | | | |
372
+ | [valid-describe-callback](docs/rules/valid-describe-callback.md) | Enforce valid `describe()` callback || | | |
373
+ | [valid-expect](docs/rules/valid-expect.md) | Enforce valid `expect()` usage || | | |
374
+ | [valid-expect-in-promise](docs/rules/valid-expect-in-promise.md) | Require promises that have expectations in their chain to be valid | ✅ | | | |
375
+ | [valid-title](docs/rules/valid-title.md) | Enforce valid titles | ✅ | | 🔧 | |
267
376
 
268
377
  ### Requires Type Checking
269
378
 
270
- | Name           | Description | 💼 | ⚠️ | 🔧 | 💡 | ❌ |
271
- | :--------------------------------------------- | :----------------------------------------------------------- | :-- | :-- | :-- | :-- | :-- |
272
- | [unbound-method](docs/rules/unbound-method.md) | Enforce unbound methods are called with their expected scope | | | | | |
379
+ | Name           | Description | 💼 | ⚠️ | 🔧 | 💡 |
380
+ | :--------------------------------------------- | :----------------------------------------------------------- | :-- | :-- | :-- | :-- |
381
+ | [unbound-method](docs/rules/unbound-method.md) | Enforce unbound methods are called with their expected scope | | | | |
273
382
 
274
383
  <!-- end auto-generated rules list -->
275
384
 
@@ -4,7 +4,7 @@
4
4
  [config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
5
5
 
6
6
  💡 This rule is manually fixable by
7
- [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
7
+ [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
8
8
 
9
9
  <!-- end auto-generated rule header -->
10
10
 
@@ -4,7 +4,7 @@
4
4
  [config](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).
5
5
 
6
6
  💡 This rule is manually fixable by
7
- [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
7
+ [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
8
8
 
9
9
  <!-- end auto-generated rule header -->
10
10
 
@@ -1,7 +1,7 @@
1
1
  # Suggest using the built-in equality matchers (`prefer-equality-matcher`)
2
2
 
3
3
  💡 This rule is manually fixable by
4
- [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
4
+ [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
5
5
 
6
6
  <!-- end auto-generated rule header -->
7
7
 
@@ -1,7 +1,7 @@
1
1
  # Suggest using `expect.assertions()` OR `expect.hasAssertions()` (`prefer-expect-assertions`)
2
2
 
3
3
  💡 This rule is manually fixable by
4
- [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
4
+ [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
5
5
 
6
6
  <!-- end auto-generated rule header -->
7
7
 
@@ -1,7 +1,7 @@
1
1
  # Suggest using `toStrictEqual()` (`prefer-strict-equal`)
2
2
 
3
3
  💡 This rule is manually fixable by
4
- [editor suggestions](https://eslint.org/docs/developer-guide/working-with-rules#providing-suggestions).
4
+ [editor suggestions](https://eslint.org/docs/latest/use/core-concepts#rule-suggestions).
5
5
 
6
6
  <!-- end auto-generated rule header -->
7
7
 
@@ -1,6 +1,7 @@
1
1
  # Enforce unbound methods are called with their expected scope (`unbound-method`)
2
2
 
3
- 💭 This rule requires type information.
3
+ 💭 This rule requires
4
+ [type information](https://typescript-eslint.io/linting/typed-linting).
4
5
 
5
6
  <!-- end auto-generated rule header -->
6
7
 
@@ -55,5 +56,4 @@ See [`@typescript-eslint/unbound-method`][original-rule] options (e.g.
55
56
 
56
57
  <sup>Taken with ❤️ [from `@typescript-eslint` core][original-rule]</sup>
57
58
 
58
- [original-rule]:
59
- https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/unbound-method.md
59
+ [original-rule]: https://typescript-eslint.io/rules/unbound-method
package/lib/index.js CHANGED
@@ -21,37 +21,83 @@ interopRequireDefault(require(moduleName)).default;
21
21
  const rulesDir = (0, _path.join)(__dirname, 'rules');
22
22
  const excludedFiles = ['__tests__', 'detectJestVersion', 'utils'];
23
23
  const rules = Object.fromEntries((0, _fs.readdirSync)(rulesDir).map(rule => (0, _path.parse)(rule).name).filter(rule => !excludedFiles.includes(rule)).map(rule => [rule, importDefault((0, _path.join)(rulesDir, rule))]));
24
- const recommendedRules = Object.fromEntries(Object.entries(rules).filter(([, rule]) => rule.meta.docs.recommended).map(([name, rule]) => [`jest/${name}`, rule.meta.docs.recommended]));
24
+ const recommendedRules = {
25
+ 'jest/expect-expect': 'warn',
26
+ 'jest/no-alias-methods': 'error',
27
+ 'jest/no-commented-out-tests': 'warn',
28
+ 'jest/no-conditional-expect': 'error',
29
+ 'jest/no-deprecated-functions': 'error',
30
+ 'jest/no-disabled-tests': 'warn',
31
+ 'jest/no-done-callback': 'error',
32
+ 'jest/no-export': 'error',
33
+ 'jest/no-focused-tests': 'error',
34
+ 'jest/no-identical-title': 'error',
35
+ 'jest/no-interpolation-in-snapshots': 'error',
36
+ 'jest/no-jasmine-globals': 'error',
37
+ 'jest/no-mocks-import': 'error',
38
+ 'jest/no-standalone-expect': 'error',
39
+ 'jest/no-test-prefixes': 'error',
40
+ 'jest/valid-describe-callback': 'error',
41
+ 'jest/valid-expect': 'error',
42
+ 'jest/valid-expect-in-promise': 'error',
43
+ 'jest/valid-title': 'error'
44
+ };
45
+ const styleRules = {
46
+ 'jest/no-alias-methods': 'warn',
47
+ 'jest/prefer-to-be': 'error',
48
+ 'jest/prefer-to-contain': 'error',
49
+ 'jest/prefer-to-have-length': 'error'
50
+ };
25
51
  const allRules = Object.fromEntries(Object.entries(rules).filter(([, rule]) => !rule.meta.deprecated).map(([name]) => [`jest/${name}`, 'error']));
26
- const createConfig = rules => ({
27
- plugins: ['jest'],
28
- env: {
29
- 'jest/globals': true
30
- },
31
- rules
32
- });
33
- module.exports = {
52
+ const plugin = {
34
53
  meta: {
35
54
  name: _package.name,
36
55
  version: _package.version
37
56
  },
38
- configs: {
39
- all: createConfig(allRules),
40
- recommended: createConfig(recommendedRules),
41
- style: createConfig({
42
- 'jest/no-alias-methods': 'warn',
43
- 'jest/prefer-to-be': 'error',
44
- 'jest/prefer-to-contain': 'error',
45
- 'jest/prefer-to-have-length': 'error'
46
- })
47
- },
57
+ // ugly cast for now to keep TypeScript happy since
58
+ // we don't have types for flat config yet
59
+ configs: {},
48
60
  environments: {
49
61
  globals: {
50
62
  globals: _globals.default
51
63
  }
52
64
  },
53
65
  processors: {
66
+ snapshots: snapshotProcessor,
54
67
  '.snap': snapshotProcessor
55
68
  },
56
69
  rules
57
- };
70
+ };
71
+ const createRCConfig = rules => ({
72
+ plugins: ['jest'],
73
+ env: {
74
+ 'jest/globals': true
75
+ },
76
+ rules
77
+ });
78
+ const createFlatConfig = rules => ({
79
+ plugins: {
80
+ jest: plugin
81
+ },
82
+ languageOptions: {
83
+ globals: _globals.default
84
+ },
85
+ rules
86
+ });
87
+ plugin.configs = {
88
+ all: createRCConfig(allRules),
89
+ recommended: createRCConfig(recommendedRules),
90
+ style: createRCConfig(styleRules),
91
+ 'flat/all': createFlatConfig(allRules),
92
+ 'flat/recommended': createFlatConfig(recommendedRules),
93
+ 'flat/style': createFlatConfig(styleRules),
94
+ 'flat/snapshots': {
95
+ // @ts-expect-error this is introduced in flat config
96
+ files: ['**/*.snap'],
97
+ plugins: {
98
+ jest: plugin
99
+ },
100
+ processor: 'jest/snapshots'
101
+ }
102
+ };
103
+ module.exports = plugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "27.8.0",
3
+ "version": "28.0.0-next.1",
4
4
  "description": "ESLint rules for Jest",
5
5
  "keywords": [
6
6
  "eslint",
@@ -21,7 +21,7 @@
21
21
  ],
22
22
  "scripts": {
23
23
  "build": "babel --extensions .js,.ts src --out-dir lib --copy-files && rimraf --glob lib/__tests__ 'lib/**/__tests__'",
24
- "_postinstall": "is-ci || husky install",
24
+ "_postinstall": "is-ci || husky",
25
25
  "lint": "eslint . --ignore-pattern '!.eslintrc.js' --ext js,ts",
26
26
  "prepack": "rimraf lib && yarn build",
27
27
  "prepublishOnly": "pinst --disable",
@@ -126,7 +126,7 @@
126
126
  "eslint-plugin-prettier": "^5.0.0",
127
127
  "eslint-remote-tester": "^3.0.0",
128
128
  "eslint-remote-tester-repositories": "~1.0.0",
129
- "husky": "^8.0.1",
129
+ "husky": "^9.0.1",
130
130
  "is-ci": "^3.0.0",
131
131
  "jest": "^29.0.0",
132
132
  "jest-runner-eslint": "^2.0.0",
@@ -135,7 +135,7 @@
135
135
  "pinst": "^3.0.0",
136
136
  "prettier": "^3.0.0",
137
137
  "rimraf": "^5.0.0",
138
- "semantic-release": "^22.0.0",
138
+ "semantic-release": "^23.0.0",
139
139
  "semver": "^7.3.5",
140
140
  "strip-ansi": "^6.0.0",
141
141
  "ts-node": "^10.2.1",
@@ -154,7 +154,7 @@
154
154
  "optional": true
155
155
  }
156
156
  },
157
- "packageManager": "yarn@3.8.0",
157
+ "packageManager": "yarn@3.8.1",
158
158
  "engines": {
159
159
  "node": "^14.15.0 || ^16.10.0 || >=18.0.0"
160
160
  },
@@ -162,6 +162,6 @@
162
162
  "provenance": true
163
163
  },
164
164
  "resolutions": {
165
- "typescript": "~5.2.2"
165
+ "@typescript-eslint/typescript-estree@5.62.0": "patch:@typescript-eslint/typescript-estree@npm:^5.62.0#./.yarn/patches/@typescript-eslint-typescript-estree-npm-5.62.0-5d1ea132a9.patch"
166
166
  }
167
167
  }
@@ -1,58 +0,0 @@
1
- # Disallow conditional logic (`no-if`)
2
-
3
- ❌ This rule is deprecated. It was replaced by
4
- [`jest/no-conditional-in-test`](no-conditional-in-test.md).
5
-
6
- <!-- end auto-generated rule header -->
7
-
8
- Conditional logic in tests is usually an indication that a test is attempting to
9
- cover too much, and not testing the logic it intends to. Each branch of code
10
- executing within an if statement will usually be better served by a test devoted
11
- to it.
12
-
13
- Conditionals are often used to satisfy the typescript type checker. In these
14
- cases, using the non-null assertion operator (!) would be best.
15
-
16
- ## Rule details
17
-
18
- This rule prevents the use of if/ else statements and conditional (ternary)
19
- operations in tests.
20
-
21
- The following patterns are considered warnings:
22
-
23
- ```js
24
- it('foo', () => {
25
- if ('bar') {
26
- // an if statement here is invalid
27
- // you are probably testing too much
28
- }
29
- });
30
-
31
- it('foo', () => {
32
- const bar = foo ? 'bar' : null;
33
- });
34
- ```
35
-
36
- These patterns would not be considered warnings:
37
-
38
- ```js
39
- it('foo', () => {
40
- // only test the 'foo' case
41
- });
42
-
43
- it('bar', () => {
44
- // test the 'bar' case separately
45
- });
46
-
47
- it('foo', () => {
48
- function foo(bar) {
49
- // nested functions are valid
50
- return foo ? bar : null;
51
- }
52
- });
53
- ```
54
-
55
- ## When Not To Use It
56
-
57
- If you do not wish to prevent the use of if statements in tests, you can safely
58
- disable this rule.
@@ -1,86 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- var _utils = require("@typescript-eslint/utils");
8
- var _utils2 = require("./utils");
9
- const testCaseNames = new Set([...Object.keys(_utils2.TestCaseName), 'it.only', 'it.only', 'it.skip', 'it.skip', 'test.only', 'test.only', 'test.skip', 'test.skip', 'fit.concurrent']);
10
- const isTestFunctionExpression = node => node.parent !== undefined && node.parent.type === _utils.AST_NODE_TYPES.CallExpression && testCaseNames.has((0, _utils2.getNodeName)(node.parent.callee));
11
- const conditionName = {
12
- [_utils.AST_NODE_TYPES.ConditionalExpression]: 'conditional',
13
- [_utils.AST_NODE_TYPES.SwitchStatement]: 'switch',
14
- [_utils.AST_NODE_TYPES.IfStatement]: 'if'
15
- };
16
- var _default = exports.default = (0, _utils2.createRule)({
17
- name: __filename,
18
- meta: {
19
- docs: {
20
- description: 'Disallow conditional logic',
21
- category: 'Best Practices',
22
- recommended: false
23
- },
24
- messages: {
25
- conditionalInTest: 'Test should not contain {{ condition }} statements'
26
- },
27
- deprecated: true,
28
- replacedBy: ['no-conditional-in-test'],
29
- schema: [],
30
- type: 'suggestion'
31
- },
32
- defaultOptions: [],
33
- create(context) {
34
- const stack = [];
35
- function validate(node) {
36
- const lastElementInStack = stack[stack.length - 1];
37
- if (stack.length === 0 || !lastElementInStack) {
38
- return;
39
- }
40
- context.report({
41
- data: {
42
- condition: conditionName[node.type]
43
- },
44
- messageId: 'conditionalInTest',
45
- node
46
- });
47
- }
48
- return {
49
- CallExpression(node) {
50
- const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
51
- if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) === 'test') {
52
- stack.push(true);
53
- if (jestFnCall.members.some(s => (0, _utils2.getAccessorValue)(s) === 'each')) {
54
- stack.push(true);
55
- }
56
- }
57
- },
58
- FunctionExpression(node) {
59
- stack.push(isTestFunctionExpression(node));
60
- },
61
- FunctionDeclaration(node) {
62
- const declaredVariables = (0, _utils2.getDeclaredVariables)(context, node);
63
- const testCallExpressions = (0, _utils2.getTestCallExpressionsFromDeclaredVariables)(declaredVariables, context);
64
- stack.push(testCallExpressions.length > 0);
65
- },
66
- ArrowFunctionExpression(node) {
67
- stack.push(isTestFunctionExpression(node));
68
- },
69
- IfStatement: validate,
70
- SwitchStatement: validate,
71
- ConditionalExpression: validate,
72
- 'CallExpression:exit'() {
73
- stack.pop();
74
- },
75
- 'FunctionExpression:exit'() {
76
- stack.pop();
77
- },
78
- 'FunctionDeclaration:exit'() {
79
- stack.pop();
80
- },
81
- 'ArrowFunctionExpression:exit'() {
82
- stack.pop();
83
- }
84
- };
85
- }
86
- });