eslint-plugin-jest 25.2.1 → 25.2.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 +7 -0
- package/docs/rules/require-hook.md +2 -1
- package/lib/rules/require-hook.js +15 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [25.2.2](https://github.com/jest-community/eslint-plugin-jest/compare/v25.2.1...v25.2.2) (2021-10-17)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **require-hook:** check variables are either `const` or declarations ([#959](https://github.com/jest-community/eslint-plugin-jest/issues/959)) ([ce8cd61](https://github.com/jest-community/eslint-plugin-jest/commit/ce8cd612b7c4c16dc29934118b191d3fbe1ffc07))
|
|
7
|
+
|
|
1
8
|
## [25.2.1](https://github.com/jest-community/eslint-plugin-jest/compare/v25.2.0...v25.2.1) (2021-10-15)
|
|
2
9
|
|
|
3
10
|
|
|
@@ -19,7 +19,8 @@ directly within the body of a `describe`, _except_ for the following:
|
|
|
19
19
|
|
|
20
20
|
- `import` statements
|
|
21
21
|
- `const` variables
|
|
22
|
-
- `let` _declarations_
|
|
22
|
+
- `let` _declarations_, and initializations to `null` or `undefined`
|
|
23
|
+
- Classes
|
|
23
24
|
- Types
|
|
24
25
|
- Calls to the standard Jest globals
|
|
25
26
|
|
|
@@ -19,6 +19,10 @@ const isJestFnCall = node => {
|
|
|
19
19
|
return !!((_getNodeName = (0, _utils.getNodeName)(node)) !== null && _getNodeName !== void 0 && _getNodeName.startsWith('jest.'));
|
|
20
20
|
};
|
|
21
21
|
|
|
22
|
+
const isNullOrUndefined = node => {
|
|
23
|
+
return node.type === _experimentalUtils.AST_NODE_TYPES.Literal && node.value === null || (0, _utils.isIdentifier)(node, 'undefined');
|
|
24
|
+
};
|
|
25
|
+
|
|
22
26
|
const shouldBeInHook = node => {
|
|
23
27
|
switch (node.type) {
|
|
24
28
|
case _experimentalUtils.AST_NODE_TYPES.ExpressionStatement:
|
|
@@ -27,6 +31,17 @@ const shouldBeInHook = node => {
|
|
|
27
31
|
case _experimentalUtils.AST_NODE_TYPES.CallExpression:
|
|
28
32
|
return !isJestFnCall(node);
|
|
29
33
|
|
|
34
|
+
case _experimentalUtils.AST_NODE_TYPES.VariableDeclaration:
|
|
35
|
+
{
|
|
36
|
+
if (node.kind === 'const') {
|
|
37
|
+
return false;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
return node.declarations.some(({
|
|
41
|
+
init
|
|
42
|
+
}) => init !== null && !isNullOrUndefined(init));
|
|
43
|
+
}
|
|
44
|
+
|
|
30
45
|
default:
|
|
31
46
|
return false;
|
|
32
47
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "25.2.
|
|
3
|
+
"version": "25.2.2",
|
|
4
4
|
"description": "Eslint rules for Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -107,7 +107,7 @@
|
|
|
107
107
|
"eslint-config-prettier": "^8.3.0",
|
|
108
108
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
109
109
|
"eslint-plugin-eslint-config": "^2.0.0",
|
|
110
|
-
"eslint-plugin-eslint-plugin": "^
|
|
110
|
+
"eslint-plugin-eslint-plugin": "^4.0.1",
|
|
111
111
|
"eslint-plugin-import": "^2.25.1",
|
|
112
112
|
"eslint-plugin-node": "^11.0.0",
|
|
113
113
|
"eslint-plugin-prettier": "^3.4.1",
|