eslint-plugin-jest 24.2.0 → 24.3.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/CHANGELOG.md +28 -0
- package/README.md +27 -2
- package/docs/rules/unbound-method.md +54 -0
- package/lib/rules/consistent-test-it.js +1 -1
- package/lib/rules/no-focused-tests.js +1 -1
- package/lib/rules/no-identical-title.js +4 -4
- package/lib/rules/unbound-method.js +110 -0
- package/package.json +9 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
## [24.3.2](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.1...v24.3.2) (2021-03-16)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **consistent-test-it:** properly handle `describe.each` ([#796](https://github.com/jest-community/eslint-plugin-jest/issues/796)) ([035bd30](https://github.com/jest-community/eslint-plugin-jest/commit/035bd30af43f1215e65bf1b26c2ef2e6d174d3c8)), closes [#795](https://github.com/jest-community/eslint-plugin-jest/issues/795)
|
|
7
|
+
|
|
8
|
+
## [24.3.1](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.0...v24.3.1) (2021-03-13)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **no-focused-tests:** report on `skip` instead of `concurrent` ([#791](https://github.com/jest-community/eslint-plugin-jest/issues/791)) ([2b65b49](https://github.com/jest-community/eslint-plugin-jest/commit/2b65b491cea2c956e4ba314a809915b9ec62933b))
|
|
14
|
+
|
|
15
|
+
# [24.3.0](https://github.com/jest-community/eslint-plugin-jest/compare/v24.2.1...v24.3.0) (2021-03-13)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* **unbound-method:** create rule ([#765](https://github.com/jest-community/eslint-plugin-jest/issues/765)) ([b1f4ed3](https://github.com/jest-community/eslint-plugin-jest/commit/b1f4ed3f6bb0264fdefb5138ba913fa2bacc725c))
|
|
21
|
+
|
|
22
|
+
## [24.2.1](https://github.com/jest-community/eslint-plugin-jest/compare/v24.2.0...v24.2.1) (2021-03-10)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* **no-identical-titles:** support nested describes ([#790](https://github.com/jest-community/eslint-plugin-jest/issues/790)) ([ce26621](https://github.com/jest-community/eslint-plugin-jest/commit/ce26621a06169fb6728d2d015645d31401de523f))
|
|
28
|
+
|
|
1
29
|
# [24.2.0](https://github.com/jest-community/eslint-plugin-jest/compare/v24.1.10...v24.2.0) (2021-03-09)
|
|
2
30
|
|
|
3
31
|
|
package/README.md
CHANGED
|
@@ -128,7 +128,7 @@ installations requiring long-term consistency.
|
|
|
128
128
|
|
|
129
129
|
## Rules
|
|
130
130
|
|
|
131
|
-
<!-- begin rules list -->
|
|
131
|
+
<!-- begin base rules list -->
|
|
132
132
|
|
|
133
133
|
| Rule | Description | Configurations | Fixable |
|
|
134
134
|
| ---------------------------------------------------------------------------- | --------------------------------------------------------------- | ---------------- | ------------ |
|
|
@@ -173,7 +173,32 @@ installations requiring long-term consistency.
|
|
|
173
173
|
| [valid-expect-in-promise](docs/rules/valid-expect-in-promise.md) | Enforce having return statement when testing with promises | ![recommended][] | |
|
|
174
174
|
| [valid-title](docs/rules/valid-title.md) | Enforce valid titles | ![recommended][] | ![fixable][] |
|
|
175
175
|
|
|
176
|
-
<!-- end rules list -->
|
|
176
|
+
<!-- end base rules list -->
|
|
177
|
+
|
|
178
|
+
## TypeScript Rules
|
|
179
|
+
|
|
180
|
+
In addition to the above rules, this plugin also includes a few advanced rules
|
|
181
|
+
that are powered by type-checking information provided by TypeScript.
|
|
182
|
+
|
|
183
|
+
In order to use these rules, you must be using `@typescript-eslint/parser` &
|
|
184
|
+
adjust your eslint config as outlined
|
|
185
|
+
[here](https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/TYPED_LINTING.md)
|
|
186
|
+
|
|
187
|
+
Note that unlike the type-checking rules in `@typescript-eslint/eslint-plugin`,
|
|
188
|
+
the rules here will fallback to doing nothing if type information is not
|
|
189
|
+
available, meaning its safe to include them in shared configs that could be used
|
|
190
|
+
on JavaScript and TypeScript projects.
|
|
191
|
+
|
|
192
|
+
Also note that `unbound-method` depends on `@typescript-eslint/eslint-plugin`,
|
|
193
|
+
as it extends the original `unbound-method` rule from that plugin.
|
|
194
|
+
|
|
195
|
+
<!-- begin type rules list -->
|
|
196
|
+
|
|
197
|
+
| Rule | Description | Configurations | Fixable |
|
|
198
|
+
| ---------------------------------------------- | ------------------------------------------------------------- | -------------- | ------- |
|
|
199
|
+
| [unbound-method](docs/rules/unbound-method.md) | Enforces unbound methods are called with their expected scope | | |
|
|
200
|
+
|
|
201
|
+
<!-- end type rules list -->
|
|
177
202
|
|
|
178
203
|
## Credit
|
|
179
204
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# Enforces unbound methods are called with their expected scope (`unbound-method`)
|
|
2
|
+
|
|
3
|
+
## Rule Details
|
|
4
|
+
|
|
5
|
+
This rule extends the base [`@typescript-eslint/unbound-method`][original-rule]
|
|
6
|
+
rule, meaning you must depend on `@typescript-eslint/eslint-plugin` for it to
|
|
7
|
+
work. It adds support for understanding when it's ok to pass an unbound method
|
|
8
|
+
to `expect` calls.
|
|
9
|
+
|
|
10
|
+
See the [`@typescript-eslint` documentation][original-rule] for more details on
|
|
11
|
+
the `unbound-method` rule.
|
|
12
|
+
|
|
13
|
+
Note that while this rule requires type information to work, it will fail
|
|
14
|
+
silently when not available allowing you to safely enable it on projects that
|
|
15
|
+
are not using TypeScript.
|
|
16
|
+
|
|
17
|
+
## How to use
|
|
18
|
+
|
|
19
|
+
```json5
|
|
20
|
+
{
|
|
21
|
+
parser: '@typescript-eslint/parser',
|
|
22
|
+
parserOptions: {
|
|
23
|
+
project: 'tsconfig.json',
|
|
24
|
+
ecmaVersion: 2020,
|
|
25
|
+
sourceType: 'module',
|
|
26
|
+
},
|
|
27
|
+
overrides: [
|
|
28
|
+
{
|
|
29
|
+
files: ['test/**'],
|
|
30
|
+
extends: ['jest'],
|
|
31
|
+
rules: {
|
|
32
|
+
// you should turn the original rule off *only* for test files
|
|
33
|
+
'@typescript-eslint/unbound-method': 'off',
|
|
34
|
+
'jest/unbound-method': 'error',
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
],
|
|
38
|
+
rules: {
|
|
39
|
+
'@typescript-eslint/unbound-method': 'error',
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
This rule should be applied to your test files in place of the original rule,
|
|
45
|
+
which should be applied to the rest of your codebase.
|
|
46
|
+
|
|
47
|
+
## Options
|
|
48
|
+
|
|
49
|
+
See [`@typescript-eslint/unbound-method`][original-rule] options.
|
|
50
|
+
|
|
51
|
+
<sup>Taken with ❤️ [from `@typescript-eslint` core][original-rule]</sup>
|
|
52
|
+
|
|
53
|
+
[original-rule]:
|
|
54
|
+
https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/unbound-method.md
|
|
@@ -63,7 +63,7 @@ var _default = (0, _utils.createRule)({
|
|
|
63
63
|
if (calleeObject.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isCallToTestOnlyFunction(calleeObject)) {
|
|
64
64
|
context.report({
|
|
65
65
|
messageId: 'focusedTest',
|
|
66
|
-
node: calleeObject.property,
|
|
66
|
+
node: isConcurrentExpression(calleeObject) ? callee.property : calleeObject.property,
|
|
67
67
|
suggest: [{
|
|
68
68
|
messageId: 'suggestRemoveFocus',
|
|
69
69
|
|
|
@@ -37,14 +37,14 @@ var _default = (0, _utils.createRule)({
|
|
|
37
37
|
CallExpression(node) {
|
|
38
38
|
const currentLayer = contexts[contexts.length - 1];
|
|
39
39
|
|
|
40
|
-
if (node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
41
|
-
return;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
40
|
if ((0, _utils.isDescribe)(node)) {
|
|
45
41
|
contexts.push(newDescribeContext());
|
|
46
42
|
}
|
|
47
43
|
|
|
44
|
+
if (node.callee.type === _experimentalUtils.AST_NODE_TYPES.TaggedTemplateExpression) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
48
|
const [argument] = node.arguments;
|
|
49
49
|
|
|
50
50
|
if (!argument || !(0, _utils.isStringNode)(argument)) {
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
var _utils = require("./utils");
|
|
9
|
+
|
|
10
|
+
const toThrowMatchers = ['toThrow', 'toThrowError', 'toThrowErrorMatchingSnapshot', 'toThrowErrorMatchingInlineSnapshot'];
|
|
11
|
+
|
|
12
|
+
const isJestExpectToThrowCall = node => {
|
|
13
|
+
if (!(0, _utils.isExpectCall)(node)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
matcher
|
|
19
|
+
} = (0, _utils.parseExpectCall)(node);
|
|
20
|
+
|
|
21
|
+
if (!matcher) {
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return !toThrowMatchers.includes(matcher.name);
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const baseRule = (() => {
|
|
29
|
+
try {
|
|
30
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
31
|
+
const TSESLintPlugin = require('@typescript-eslint/eslint-plugin');
|
|
32
|
+
|
|
33
|
+
return TSESLintPlugin.rules['unbound-method'];
|
|
34
|
+
} catch (e) {
|
|
35
|
+
const error = e;
|
|
36
|
+
|
|
37
|
+
if (error.code === 'MODULE_NOT_FOUND') {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
throw error;
|
|
42
|
+
}
|
|
43
|
+
})();
|
|
44
|
+
|
|
45
|
+
const tryCreateBaseRule = context => {
|
|
46
|
+
try {
|
|
47
|
+
return baseRule === null || baseRule === void 0 ? void 0 : baseRule.create(context);
|
|
48
|
+
} catch {
|
|
49
|
+
return null;
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
var _default = (0, _utils.createRule)({
|
|
54
|
+
defaultOptions: [{
|
|
55
|
+
ignoreStatic: false
|
|
56
|
+
}],
|
|
57
|
+
...baseRule,
|
|
58
|
+
name: __filename,
|
|
59
|
+
meta: {
|
|
60
|
+
messages: {
|
|
61
|
+
unbound: 'This rule requires `@typescript-eslint/eslint-plugin`'
|
|
62
|
+
},
|
|
63
|
+
schema: [],
|
|
64
|
+
type: 'problem',
|
|
65
|
+
...(baseRule === null || baseRule === void 0 ? void 0 : baseRule.meta),
|
|
66
|
+
docs: {
|
|
67
|
+
category: 'Best Practices',
|
|
68
|
+
description: 'Enforces unbound methods are called with their expected scope',
|
|
69
|
+
requiresTypeChecking: true,
|
|
70
|
+
...(baseRule === null || baseRule === void 0 ? void 0 : baseRule.meta.docs),
|
|
71
|
+
recommended: false
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
|
|
75
|
+
create(context) {
|
|
76
|
+
const baseSelectors = tryCreateBaseRule(context);
|
|
77
|
+
|
|
78
|
+
if (!baseSelectors) {
|
|
79
|
+
return {};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
let inExpectToThrowCall = false;
|
|
83
|
+
return { ...baseSelectors,
|
|
84
|
+
|
|
85
|
+
CallExpression(node) {
|
|
86
|
+
inExpectToThrowCall = isJestExpectToThrowCall(node);
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
'CallExpression:exit'(node) {
|
|
90
|
+
if (inExpectToThrowCall && isJestExpectToThrowCall(node)) {
|
|
91
|
+
inExpectToThrowCall = false;
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
|
|
95
|
+
MemberExpression(node) {
|
|
96
|
+
var _baseSelectors$Member;
|
|
97
|
+
|
|
98
|
+
if (inExpectToThrowCall) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
(_baseSelectors$Member = baseSelectors.MemberExpression) === null || _baseSelectors$Member === void 0 ? void 0 : _baseSelectors$Member.call(baseSelectors, node);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
exports.default = _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "24.2
|
|
3
|
+
"version": "24.3.2",
|
|
4
4
|
"description": "Eslint rules for Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -62,7 +62,8 @@
|
|
|
62
62
|
"displayName": "test",
|
|
63
63
|
"testEnvironment": "node",
|
|
64
64
|
"testPathIgnorePatterns": [
|
|
65
|
-
"<rootDir>/lib/.*"
|
|
65
|
+
"<rootDir>/lib/.*",
|
|
66
|
+
"<rootDir>/src/rules/__tests__/fixtures/*"
|
|
66
67
|
]
|
|
67
68
|
},
|
|
68
69
|
{
|
|
@@ -121,8 +122,14 @@
|
|
|
121
122
|
"typescript": "^4.0.0"
|
|
122
123
|
},
|
|
123
124
|
"peerDependencies": {
|
|
125
|
+
"@typescript-eslint/eslint-plugin": ">= 4",
|
|
124
126
|
"eslint": ">=5"
|
|
125
127
|
},
|
|
128
|
+
"peerDependenciesMeta": {
|
|
129
|
+
"@typescript-eslint/eslint-plugin": {
|
|
130
|
+
"optional": true
|
|
131
|
+
}
|
|
132
|
+
},
|
|
126
133
|
"engines": {
|
|
127
134
|
"node": ">=10"
|
|
128
135
|
},
|