eslint-plugin-jest 27.1.6 → 27.1.7
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 +1 -1
- package/docs/rules/no-if.md +1 -1
- package/lib/rules/prefer-spy-on.js +12 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -273,7 +273,7 @@ set to warn in.\
|
|
|
273
273
|
|
|
274
274
|
In order to use the rules powered by TypeScript type-checking, you must be using
|
|
275
275
|
`@typescript-eslint/parser` & adjust your eslint config as outlined
|
|
276
|
-
[here](https://
|
|
276
|
+
[here](https://typescript-eslint.io/docs/linting/typed-linting).
|
|
277
277
|
|
|
278
278
|
Note that unlike the type-checking rules in `@typescript-eslint/eslint-plugin`,
|
|
279
279
|
the rules here will fallback to doing nothing if type information is not
|
package/docs/rules/no-if.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Disallow conditional logic (`no-if`)
|
|
2
2
|
|
|
3
3
|
❌ This rule is deprecated. It was replaced by
|
|
4
|
-
[`no-conditional-in-test`](no-conditional-in-test.md).
|
|
4
|
+
[`jest/no-conditional-in-test`](../../docs/rules/no-conditional-in-test.md).
|
|
5
5
|
|
|
6
6
|
<!-- end auto-generated rule header -->
|
|
7
7
|
|
|
@@ -28,6 +28,16 @@ const getJestFnCall = node => {
|
|
|
28
28
|
}
|
|
29
29
|
return getJestFnCall(obj);
|
|
30
30
|
};
|
|
31
|
+
const getAutoFixMockImplementation = (jestFnCall, context) => {
|
|
32
|
+
var _jestFnCall$parent;
|
|
33
|
+
const hasMockImplementationAlready = ((_jestFnCall$parent = jestFnCall.parent) === null || _jestFnCall$parent === void 0 ? void 0 : _jestFnCall$parent.type) === _utils.AST_NODE_TYPES.MemberExpression && jestFnCall.parent.property.type === _utils.AST_NODE_TYPES.Identifier && jestFnCall.parent.property.name === 'mockImplementation';
|
|
34
|
+
if (hasMockImplementationAlready) {
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
const [arg] = jestFnCall.arguments;
|
|
38
|
+
const argSource = arg && context.getSourceCode().getText(arg);
|
|
39
|
+
return argSource ? `.mockImplementation(${argSource})` : '.mockImplementation()';
|
|
40
|
+
};
|
|
31
41
|
var _default = (0, _utils2.createRule)({
|
|
32
42
|
name: __filename,
|
|
33
43
|
meta: {
|
|
@@ -58,10 +68,8 @@ var _default = (0, _utils2.createRule)({
|
|
|
58
68
|
node,
|
|
59
69
|
messageId: 'useJestSpyOn',
|
|
60
70
|
fix(fixer) {
|
|
61
|
-
const leftPropQuote = left.property.type === _utils.AST_NODE_TYPES.Identifier ? "'" : '';
|
|
62
|
-
const
|
|
63
|
-
const argSource = arg && context.getSourceCode().getText(arg);
|
|
64
|
-
const mockImplementation = argSource ? `.mockImplementation(${argSource})` : '.mockImplementation()';
|
|
71
|
+
const leftPropQuote = left.property.type === _utils.AST_NODE_TYPES.Identifier && !left.computed ? "'" : '';
|
|
72
|
+
const mockImplementation = getAutoFixMockImplementation(jestFnCall, context);
|
|
65
73
|
return [fixer.insertTextBefore(left, `jest.spyOn(`), fixer.replaceTextRange([left.object.range[1], left.property.range[0]], `, ${leftPropQuote}`), fixer.replaceTextRange([left.property.range[1], jestFnCall.range[1]], `${leftPropQuote})${mockImplementation}`)];
|
|
66
74
|
}
|
|
67
75
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "27.1.
|
|
3
|
+
"version": "27.1.7",
|
|
4
4
|
"description": "ESLint rules for Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"prettier:write": "prettier --write 'docs/**/*.md' README.md '.github/**' package.json tsconfig.json src/globals.json .yarnrc.yml",
|
|
30
30
|
"postpublish": "pinst --enable",
|
|
31
31
|
"test": "jest",
|
|
32
|
-
"tools:regenerate-docs": "yarn prepack && eslint-doc-generator
|
|
32
|
+
"tools:regenerate-docs": "yarn prepack && eslint-doc-generator",
|
|
33
33
|
"typecheck": "tsc -p ."
|
|
34
34
|
},
|
|
35
35
|
"commitlint": {
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"dedent": "^0.7.0",
|
|
122
122
|
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
123
123
|
"eslint-config-prettier": "^8.3.0",
|
|
124
|
-
"eslint-doc-generator": "^0.
|
|
124
|
+
"eslint-doc-generator": "^1.0.0",
|
|
125
125
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
126
126
|
"eslint-plugin-eslint-plugin": "^5.0.6",
|
|
127
127
|
"eslint-plugin-import": "^2.25.1",
|