eslint-plugin-jest 27.9.0 β 28.0.0-next.2
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 +59 -61
- package/docs/rules/no-done-callback.md +1 -1
- package/docs/rules/no-focused-tests.md +1 -1
- package/docs/rules/prefer-equality-matcher.md +1 -1
- package/docs/rules/prefer-expect-assertions.md +1 -1
- package/docs/rules/prefer-strict-equal.md +1 -1
- package/docs/rules/unbound-method.md +3 -3
- package/lib/index.js +29 -13
- package/lib/rules/max-expects.js +2 -4
- package/lib/rules/no-alias-methods.js +1 -1
- package/lib/rules/no-deprecated-functions.js +1 -2
- package/lib/rules/no-done-callback.js +4 -6
- package/lib/rules/no-duplicate-hooks.js +3 -4
- package/lib/rules/no-focused-tests.js +1 -1
- package/lib/rules/no-hooks.js +1 -1
- package/lib/rules/no-interpolation-in-snapshots.js +1 -1
- package/lib/rules/no-large-snapshots.js +1 -1
- package/lib/rules/no-restricted-jest-methods.js +1 -1
- package/lib/rules/no-restricted-matchers.js +1 -1
- package/lib/rules/no-standalone-expect.js +4 -6
- package/lib/rules/no-test-prefixes.js +1 -1
- package/lib/rules/no-untyped-mock-factory.js +1 -1
- package/lib/rules/prefer-called-with.js +1 -1
- package/lib/rules/prefer-comparison-matcher.js +3 -3
- package/lib/rules/prefer-equality-matcher.js +3 -3
- package/lib/rules/prefer-expect-assertions.js +5 -7
- package/lib/rules/prefer-expect-resolves.js +3 -3
- package/lib/rules/prefer-hooks-in-order.js +1 -1
- package/lib/rules/prefer-mock-promise-shorthand.js +2 -3
- package/lib/rules/prefer-snapshot-hint.js +2 -2
- package/lib/rules/prefer-spy-on.js +1 -2
- package/lib/rules/prefer-strict-equal.js +1 -1
- package/lib/rules/prefer-to-be.js +2 -3
- package/lib/rules/prefer-to-contain.js +2 -2
- package/lib/rules/prefer-to-have-length.js +3 -3
- package/lib/rules/prefer-todo.js +1 -1
- package/lib/rules/require-hook.js +1 -2
- package/lib/rules/require-to-throw-message.js +1 -1
- package/lib/rules/unbound-method.js +6 -7
- package/lib/rules/utils/misc.js +1 -1
- package/lib/rules/utils/parseJestFnCall.js +8 -16
- package/lib/rules/valid-describe-callback.js +1 -1
- package/lib/rules/valid-expect-in-promise.js +6 -8
- package/lib/rules/valid-expect.js +6 -11
- package/lib/rules/valid-title.js +1 -1
- package/package.json +7 -7
- package/docs/rules/no-if.md +0 -58
- package/lib/rules/no-if.js +0 -86
package/README.md
CHANGED
|
@@ -127,7 +127,7 @@ module.exports = [
|
|
|
127
127
|
files: ['test/**'],
|
|
128
128
|
...jest.configs['flat/recommended'],
|
|
129
129
|
rules: {
|
|
130
|
-
...jest.configs['flat/recommended'],
|
|
130
|
+
...jest.configs['flat/recommended'].rules,
|
|
131
131
|
'jest/prefer-expect-assertions': 'off',
|
|
132
132
|
},
|
|
133
133
|
},
|
|
@@ -318,69 +318,67 @@ set to warn in.\
|
|
|
318
318
|
π¨ Set in the `style` [configuration](https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations).\
|
|
319
319
|
π§ Automatically fixable by the
|
|
320
320
|
[`--fix` CLI option](https://eslint.org/docs/user-guide/command-line-interface#--fix).\
|
|
321
|
-
π‘ Manually fixable by [editor suggestions](https://eslint.org/docs/
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
|
325
|
-
|
|
|
326
|
-
| [
|
|
327
|
-
| [
|
|
328
|
-
| [max-
|
|
329
|
-
| [
|
|
330
|
-
| [no-
|
|
331
|
-
| [no-
|
|
332
|
-
| [no-conditional-
|
|
333
|
-
| [no-
|
|
334
|
-
| [no-
|
|
335
|
-
| [no-
|
|
336
|
-
| [no-
|
|
337
|
-
| [no-
|
|
338
|
-
| [no-
|
|
339
|
-
| [no-
|
|
340
|
-
| [no-
|
|
341
|
-
| [no-
|
|
342
|
-
| [no-
|
|
343
|
-
| [no-
|
|
344
|
-
| [no-
|
|
345
|
-
| [no-
|
|
346
|
-
| [no-
|
|
347
|
-
| [no-
|
|
348
|
-
| [no-
|
|
349
|
-
| [no-
|
|
350
|
-
| [no-
|
|
351
|
-
| [no-
|
|
352
|
-
| [
|
|
353
|
-
| [
|
|
354
|
-
| [prefer-
|
|
355
|
-
| [prefer-
|
|
356
|
-
| [prefer-
|
|
357
|
-
| [prefer-
|
|
358
|
-
| [prefer-
|
|
359
|
-
| [prefer-
|
|
360
|
-
| [prefer-
|
|
361
|
-
| [prefer-
|
|
362
|
-
| [prefer-
|
|
363
|
-
| [prefer-
|
|
364
|
-
| [prefer-
|
|
365
|
-
| [prefer-
|
|
366
|
-
| [prefer-
|
|
367
|
-
| [prefer-to-
|
|
368
|
-
| [prefer-
|
|
369
|
-
| [
|
|
370
|
-
| [
|
|
371
|
-
| [require-
|
|
372
|
-
| [
|
|
373
|
-
| [
|
|
374
|
-
| [valid-
|
|
375
|
-
| [valid-
|
|
376
|
-
| [valid-expect-in-promise](docs/rules/valid-expect-in-promise.md) | Require promises that have expectations in their chain to be valid | β
| | | | |
|
|
377
|
-
| [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 | β
| | π§ | |
|
|
378
376
|
|
|
379
377
|
### Requires Type Checking
|
|
380
378
|
|
|
381
|
-
| NameΒ Β Β Β Β Β Β Β Β Β | Description | πΌ | β οΈ | π§ | π‘ |
|
|
382
|
-
| :--------------------------------------------- | :----------------------------------------------------------- | :-- | :-- | :-- | :-- |
|
|
383
|
-
| [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 | | | | |
|
|
384
382
|
|
|
385
383
|
<!-- end auto-generated rules list -->
|
|
386
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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
|
|
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,7 +21,33 @@ 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 =
|
|
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
52
|
const plugin = {
|
|
27
53
|
meta: {
|
|
@@ -61,20 +87,10 @@ const createFlatConfig = rules => ({
|
|
|
61
87
|
plugin.configs = {
|
|
62
88
|
all: createRCConfig(allRules),
|
|
63
89
|
recommended: createRCConfig(recommendedRules),
|
|
64
|
-
style: createRCConfig(
|
|
65
|
-
'jest/no-alias-methods': 'warn',
|
|
66
|
-
'jest/prefer-to-be': 'error',
|
|
67
|
-
'jest/prefer-to-contain': 'error',
|
|
68
|
-
'jest/prefer-to-have-length': 'error'
|
|
69
|
-
}),
|
|
90
|
+
style: createRCConfig(styleRules),
|
|
70
91
|
'flat/all': createFlatConfig(allRules),
|
|
71
92
|
'flat/recommended': createFlatConfig(recommendedRules),
|
|
72
|
-
'flat/style': createFlatConfig(
|
|
73
|
-
'jest/no-alias-methods': 'warn',
|
|
74
|
-
'jest/prefer-to-be': 'error',
|
|
75
|
-
'jest/prefer-to-contain': 'error',
|
|
76
|
-
'jest/prefer-to-have-length': 'error'
|
|
77
|
-
}),
|
|
93
|
+
'flat/style': createFlatConfig(styleRules),
|
|
78
94
|
'flat/snapshots': {
|
|
79
95
|
// @ts-expect-error this is introduced in flat config
|
|
80
96
|
files: ['**/*.snap'],
|
package/lib/rules/max-expects.js
CHANGED
|
@@ -37,8 +37,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
37
37
|
}]) {
|
|
38
38
|
let count = 0;
|
|
39
39
|
const maybeResetCount = node => {
|
|
40
|
-
|
|
41
|
-
const isTestFn = ((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) !== _utils.AST_NODE_TYPES.CallExpression || (0, _utils2.isTypeOfJestFnCall)(node.parent, context, ['test']);
|
|
40
|
+
const isTestFn = node.parent?.type !== _utils.AST_NODE_TYPES.CallExpression || (0, _utils2.isTypeOfJestFnCall)(node.parent, context, ['test']);
|
|
42
41
|
if (isTestFn) {
|
|
43
42
|
count = 0;
|
|
44
43
|
}
|
|
@@ -49,9 +48,8 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
49
48
|
ArrowFunctionExpression: maybeResetCount,
|
|
50
49
|
'ArrowFunctionExpression:exit': maybeResetCount,
|
|
51
50
|
CallExpression(node) {
|
|
52
|
-
var _jestFnCall$head$node;
|
|
53
51
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
54
|
-
if (
|
|
52
|
+
if (jestFnCall?.type !== 'expect' || jestFnCall.head.node.parent?.type === _utils.AST_NODE_TYPES.MemberExpression) {
|
|
55
53
|
return;
|
|
56
54
|
}
|
|
57
55
|
count += 1;
|
|
@@ -39,7 +39,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
39
39
|
return {
|
|
40
40
|
CallExpression(node) {
|
|
41
41
|
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
42
|
-
if (
|
|
42
|
+
if (jestFnCall?.type !== 'expect') {
|
|
43
43
|
return;
|
|
44
44
|
}
|
|
45
45
|
const {
|
|
@@ -30,8 +30,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
30
30
|
},
|
|
31
31
|
defaultOptions: [],
|
|
32
32
|
create(context) {
|
|
33
|
-
|
|
34
|
-
const jestVersion = parseJestVersion(((_context$settings = context.settings) === null || _context$settings === void 0 || (_context$settings = _context$settings.jest) === null || _context$settings === void 0 ? void 0 : _context$settings.version) || (0, _utils2.detectJestVersion)());
|
|
33
|
+
const jestVersion = parseJestVersion(context.settings?.jest?.version || (0, _utils2.detectJestVersion)());
|
|
35
34
|
const deprecations = {
|
|
36
35
|
...(jestVersion >= 15 && {
|
|
37
36
|
'jest.resetModuleRegistry': 'jest.resetModules'
|
|
@@ -11,10 +11,10 @@ const findCallbackArg = (node, isJestEach, context) => {
|
|
|
11
11
|
return node.arguments[1];
|
|
12
12
|
}
|
|
13
13
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
14
|
-
if (
|
|
14
|
+
if (jestFnCall?.type === 'hook' && node.arguments.length >= 1) {
|
|
15
15
|
return node.arguments[0];
|
|
16
16
|
}
|
|
17
|
-
if (
|
|
17
|
+
if (jestFnCall?.type === 'test' && node.arguments.length >= 2) {
|
|
18
18
|
return node.arguments[1];
|
|
19
19
|
}
|
|
20
20
|
return null;
|
|
@@ -40,9 +40,8 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
40
40
|
create(context) {
|
|
41
41
|
return {
|
|
42
42
|
CallExpression(node) {
|
|
43
|
-
var _getNodeName;
|
|
44
43
|
// done is the second argument for it.each, not the first
|
|
45
|
-
const isJestEach = (
|
|
44
|
+
const isJestEach = (0, _utils2.getNodeName)(node.callee)?.endsWith('.each') ?? false;
|
|
46
45
|
if (isJestEach && node.callee.type !== _utils.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
47
46
|
// isJestEach but not a TaggedTemplateExpression, so this must be
|
|
48
47
|
// the `jest.each([])()` syntax which this rule doesn't support due
|
|
@@ -78,7 +77,6 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
78
77
|
callback: argument.name
|
|
79
78
|
},
|
|
80
79
|
fix(fixer) {
|
|
81
|
-
var _tokenAfterLastParam;
|
|
82
80
|
const {
|
|
83
81
|
body,
|
|
84
82
|
params
|
|
@@ -90,7 +88,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
90
88
|
const lastParam = params[params.length - 1];
|
|
91
89
|
const tokenBeforeFirstParam = sourceCode.getTokenBefore(firstParam);
|
|
92
90
|
let tokenAfterLastParam = sourceCode.getTokenAfter(lastParam);
|
|
93
|
-
if (
|
|
91
|
+
if (tokenAfterLastParam?.value === ',') {
|
|
94
92
|
tokenAfterLastParam = sourceCode.getTokenAfter(tokenAfterLastParam);
|
|
95
93
|
}
|
|
96
94
|
|
|
@@ -24,16 +24,15 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
24
24
|
const hookContexts = [{}];
|
|
25
25
|
return {
|
|
26
26
|
CallExpression(node) {
|
|
27
|
-
var _jestFnCall$name;
|
|
28
27
|
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
29
|
-
if (
|
|
28
|
+
if (jestFnCall?.type === 'describe') {
|
|
30
29
|
hookContexts.push({});
|
|
31
30
|
}
|
|
32
|
-
if (
|
|
31
|
+
if (jestFnCall?.type !== 'hook') {
|
|
33
32
|
return;
|
|
34
33
|
}
|
|
35
34
|
const currentLayer = hookContexts[hookContexts.length - 1];
|
|
36
|
-
currentLayer[
|
|
35
|
+
currentLayer[jestFnCall.name] ||= 0;
|
|
37
36
|
currentLayer[jestFnCall.name] += 1;
|
|
38
37
|
if (currentLayer[jestFnCall.name] > 1) {
|
|
39
38
|
context.report({
|
|
@@ -27,7 +27,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
27
27
|
return {
|
|
28
28
|
CallExpression(node) {
|
|
29
29
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
30
|
-
if (
|
|
30
|
+
if (jestFnCall?.type !== 'test' && jestFnCall?.type !== 'describe') {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
if (jestFnCall.name.startsWith('f')) {
|
package/lib/rules/no-hooks.js
CHANGED
|
@@ -37,7 +37,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
37
37
|
return {
|
|
38
38
|
CallExpression(node) {
|
|
39
39
|
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
40
|
-
if (
|
|
40
|
+
if (jestFnCall?.type === 'hook' && !allow.includes(jestFnCall.name)) {
|
|
41
41
|
context.report({
|
|
42
42
|
node,
|
|
43
43
|
messageId: 'unexpectedHook',
|
|
@@ -25,7 +25,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
25
25
|
return {
|
|
26
26
|
CallExpression(node) {
|
|
27
27
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
28
|
-
if (
|
|
28
|
+
if (jestFnCall?.type !== 'expect') {
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
31
|
if (['toMatchInlineSnapshot', 'toThrowErrorMatchingInlineSnapshot'].includes((0, _utils2.getAccessorValue)(jestFnCall.matcher))) {
|
|
@@ -87,7 +87,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
87
87
|
return {
|
|
88
88
|
CallExpression(node) {
|
|
89
89
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
90
|
-
if (
|
|
90
|
+
if (jestFnCall?.type !== 'expect') {
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
93
|
if (['toMatchInlineSnapshot', 'toThrowErrorMatchingInlineSnapshot'].includes((0, _utils2.getAccessorValue)(jestFnCall.matcher)) && jestFnCall.args.length) {
|
|
@@ -31,7 +31,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
31
31
|
return {
|
|
32
32
|
CallExpression(node) {
|
|
33
33
|
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
34
|
-
if (
|
|
34
|
+
if (jestFnCall?.type !== 'jest' || jestFnCall.members.length === 0) {
|
|
35
35
|
return;
|
|
36
36
|
}
|
|
37
37
|
const method = (0, _utils.getAccessorValue)(jestFnCall.members[0]);
|
|
@@ -36,7 +36,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
36
36
|
return {
|
|
37
37
|
CallExpression(node) {
|
|
38
38
|
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
39
|
-
if (
|
|
39
|
+
if (jestFnCall?.type !== 'expect') {
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
42
|
const chain = jestFnCall.members.map(nod => (0, _utils.getAccessorValue)(nod)).join('.');
|
|
@@ -68,9 +68,8 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
68
68
|
return {
|
|
69
69
|
CallExpression(node) {
|
|
70
70
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
if (((_jestFnCall$head$node = jestFnCall.head.node.parent) === null || _jestFnCall$head$node === void 0 ? void 0 : _jestFnCall$head$node.type) === _utils.AST_NODE_TYPES.MemberExpression && jestFnCall.members.length === 1 && !['assertions', 'hasAssertions'].includes((0, _utils2.getAccessorValue)(jestFnCall.members[0]))) {
|
|
71
|
+
if (jestFnCall?.type === 'expect') {
|
|
72
|
+
if (jestFnCall.head.node.parent?.type === _utils.AST_NODE_TYPES.MemberExpression && jestFnCall.members.length === 1 && !['assertions', 'hasAssertions'].includes((0, _utils2.getAccessorValue)(jestFnCall.members[0]))) {
|
|
74
73
|
return;
|
|
75
74
|
}
|
|
76
75
|
const parent = callStack[callStack.length - 1];
|
|
@@ -82,7 +81,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
82
81
|
}
|
|
83
82
|
return;
|
|
84
83
|
}
|
|
85
|
-
if (
|
|
84
|
+
if (jestFnCall?.type === 'test' || isCustomTestBlockFunction(node)) {
|
|
86
85
|
callStack.push('test');
|
|
87
86
|
}
|
|
88
87
|
if (node.callee.type === _utils.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
@@ -107,8 +106,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
107
106
|
}
|
|
108
107
|
},
|
|
109
108
|
ArrowFunctionExpression(node) {
|
|
110
|
-
|
|
111
|
-
if (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) !== _utils.AST_NODE_TYPES.CallExpression) {
|
|
109
|
+
if (node.parent?.type !== _utils.AST_NODE_TYPES.CallExpression) {
|
|
112
110
|
callStack.push('arrow');
|
|
113
111
|
}
|
|
114
112
|
},
|
|
@@ -26,7 +26,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
26
26
|
return {
|
|
27
27
|
CallExpression(node) {
|
|
28
28
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
29
|
-
if (
|
|
29
|
+
if (jestFnCall?.type !== 'describe' && jestFnCall?.type !== 'test') {
|
|
30
30
|
return;
|
|
31
31
|
}
|
|
32
32
|
if (jestFnCall.name[0] !== 'f' && jestFnCall.name[0] !== 'x') {
|
|
@@ -52,7 +52,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
52
52
|
context.report({
|
|
53
53
|
messageId: 'addTypeParameterToModuleMock',
|
|
54
54
|
data: {
|
|
55
|
-
moduleName:
|
|
55
|
+
moduleName: moduleName?.raw ?? './module-name'
|
|
56
56
|
},
|
|
57
57
|
node,
|
|
58
58
|
fix(fixer) {
|
|
@@ -24,7 +24,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
24
24
|
return {
|
|
25
25
|
CallExpression(node) {
|
|
26
26
|
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
27
|
-
if (
|
|
27
|
+
if (jestFnCall?.type !== 'expect') {
|
|
28
28
|
return;
|
|
29
29
|
}
|
|
30
30
|
if (jestFnCall.modifiers.some(nod => (0, _utils.getAccessorValue)(nod) === 'not')) {
|
|
@@ -59,13 +59,13 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
59
59
|
return {
|
|
60
60
|
CallExpression(node) {
|
|
61
61
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
62
|
-
if (
|
|
62
|
+
if (jestFnCall?.type !== 'expect' || jestFnCall.args.length === 0) {
|
|
63
63
|
return;
|
|
64
64
|
}
|
|
65
65
|
const {
|
|
66
66
|
parent: expect
|
|
67
67
|
} = jestFnCall.head.node;
|
|
68
|
-
if (
|
|
68
|
+
if (expect?.type !== _utils.AST_NODE_TYPES.CallExpression) {
|
|
69
69
|
return;
|
|
70
70
|
}
|
|
71
71
|
const {
|
|
@@ -76,7 +76,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
76
76
|
matcher
|
|
77
77
|
} = jestFnCall;
|
|
78
78
|
const matcherArg = (0, _utils2.getFirstMatcherArg)(jestFnCall);
|
|
79
|
-
if (
|
|
79
|
+
if (comparison?.type !== _utils.AST_NODE_TYPES.BinaryExpression || isComparingToString(comparison) || !_utils2.EqualityMatcher.hasOwnProperty((0, _utils2.getAccessorValue)(matcher)) || !(0, _utils2.isBooleanLiteral)(matcherArg)) {
|
|
80
80
|
return;
|
|
81
81
|
}
|
|
82
82
|
const [modifier] = jestFnCall.modifiers;
|
|
@@ -27,13 +27,13 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
27
27
|
return {
|
|
28
28
|
CallExpression(node) {
|
|
29
29
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
30
|
-
if (
|
|
30
|
+
if (jestFnCall?.type !== 'expect' || jestFnCall.args.length === 0) {
|
|
31
31
|
return;
|
|
32
32
|
}
|
|
33
33
|
const {
|
|
34
34
|
parent: expect
|
|
35
35
|
} = jestFnCall.head.node;
|
|
36
|
-
if (
|
|
36
|
+
if (expect?.type !== _utils.AST_NODE_TYPES.CallExpression) {
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
39
|
const {
|
|
@@ -44,7 +44,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
44
44
|
matcher
|
|
45
45
|
} = jestFnCall;
|
|
46
46
|
const matcherArg = (0, _utils2.getFirstMatcherArg)(jestFnCall);
|
|
47
|
-
if (
|
|
47
|
+
if (comparison?.type !== _utils.AST_NODE_TYPES.BinaryExpression || comparison.operator !== '===' && comparison.operator !== '!==' || !_utils2.EqualityMatcher.hasOwnProperty((0, _utils2.getAccessorValue)(matcher)) || !(0, _utils2.isBooleanLiteral)(matcherArg)) {
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
50
|
const matcherValue = matcherArg.value;
|