eslint-plugin-jest 25.7.0 → 26.1.0

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.
Files changed (38) hide show
  1. package/README.md +2 -1
  2. package/docs/rules/no-conditional-in-test.md +79 -0
  3. package/docs/rules/no-if.md +5 -0
  4. package/docs/rules/prefer-snapshot-hint.md +188 -0
  5. package/lib/rules/consistent-test-it.js +20 -20
  6. package/lib/rules/expect-expect.js +9 -9
  7. package/lib/rules/max-nested-describe.js +5 -5
  8. package/lib/rules/no-conditional-expect.js +9 -9
  9. package/lib/rules/no-conditional-in-test.js +60 -0
  10. package/lib/rules/no-deprecated-functions.js +6 -6
  11. package/lib/rules/no-done-callback.js +10 -10
  12. package/lib/rules/no-export.js +6 -6
  13. package/lib/rules/no-focused-tests.js +11 -11
  14. package/lib/rules/no-if.js +13 -11
  15. package/lib/rules/no-interpolation-in-snapshots.js +6 -6
  16. package/lib/rules/no-jasmine-globals.js +10 -10
  17. package/lib/rules/no-large-snapshots.js +8 -8
  18. package/lib/rules/no-standalone-expect.js +14 -14
  19. package/lib/rules/no-test-prefixes.js +6 -6
  20. package/lib/rules/no-test-return-statement.js +8 -8
  21. package/lib/rules/prefer-comparison-matcher.js +10 -10
  22. package/lib/rules/prefer-equality-matcher.js +10 -10
  23. package/lib/rules/prefer-expect-assertions.js +12 -12
  24. package/lib/rules/prefer-expect-resolves.js +4 -4
  25. package/lib/rules/prefer-snapshot-hint.js +112 -0
  26. package/lib/rules/prefer-spy-on.js +9 -9
  27. package/lib/rules/prefer-to-be.js +15 -15
  28. package/lib/rules/prefer-to-contain.js +11 -11
  29. package/lib/rules/prefer-to-have-length.js +6 -6
  30. package/lib/rules/prefer-todo.js +9 -9
  31. package/lib/rules/require-hook.js +12 -12
  32. package/lib/rules/utils.js +27 -27
  33. package/lib/rules/valid-describe-callback.js +9 -9
  34. package/lib/rules/valid-expect-in-promise.js +44 -44
  35. package/lib/rules/valid-expect.js +18 -18
  36. package/lib/rules/valid-title.js +14 -14
  37. package/package.json +9 -7
  38. package/CHANGELOG.md +0 -846
@@ -5,9 +5,9 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _experimentalUtils = require("@typescript-eslint/experimental-utils");
8
+ var _utils = require("@typescript-eslint/utils");
9
9
 
10
- var _utils = require("./utils");
10
+ var _utils2 = require("./utils");
11
11
 
12
12
  /*
13
13
  * This implementation is ported from from eslint-plugin-jasmine.
@@ -22,11 +22,11 @@ var _utils = require("./utils");
22
22
  * @Returns CallExpressionNode
23
23
  */
24
24
  const getPromiseCallExpressionNode = node => {
25
- if (node.type === _experimentalUtils.AST_NODE_TYPES.ArrayExpression && node.parent && node.parent.type === _experimentalUtils.AST_NODE_TYPES.CallExpression) {
25
+ if (node.type === _utils.AST_NODE_TYPES.ArrayExpression && node.parent && node.parent.type === _utils.AST_NODE_TYPES.CallExpression) {
26
26
  node = node.parent;
27
27
  }
28
28
 
29
- if (node.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && (0, _utils.isSupportedAccessor)(node.callee.object) && (0, _utils.getAccessorValue)(node.callee.object) === 'Promise' && node.parent) {
29
+ if (node.type === _utils.AST_NODE_TYPES.CallExpression && node.callee.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(node.callee.object) && (0, _utils2.getAccessorValue)(node.callee.object) === 'Promise' && node.parent) {
30
30
  return node;
31
31
  }
32
32
 
@@ -36,7 +36,7 @@ const getPromiseCallExpressionNode = node => {
36
36
  const findPromiseCallExpressionNode = node => {
37
37
  var _node$parent;
38
38
 
39
- return (_node$parent = node.parent) !== null && _node$parent !== void 0 && _node$parent.parent && [_experimentalUtils.AST_NODE_TYPES.CallExpression, _experimentalUtils.AST_NODE_TYPES.ArrayExpression].includes(node.parent.type) ? getPromiseCallExpressionNode(node.parent) : null;
39
+ return (_node$parent = node.parent) !== null && _node$parent !== void 0 && _node$parent.parent && [_utils.AST_NODE_TYPES.CallExpression, _utils.AST_NODE_TYPES.ArrayExpression].includes(node.parent.type) ? getPromiseCallExpressionNode(node.parent) : null;
40
40
  };
41
41
 
42
42
  const getParentIfThenified = node => {
@@ -44,7 +44,7 @@ const getParentIfThenified = node => {
44
44
 
45
45
  const grandParentNode = (_node$parent2 = node.parent) === null || _node$parent2 === void 0 ? void 0 : _node$parent2.parent;
46
46
 
47
- if (grandParentNode && grandParentNode.type === _experimentalUtils.AST_NODE_TYPES.CallExpression && (0, _utils.isExpectMember)(grandParentNode.callee) && ['then', 'catch'].includes((0, _utils.getAccessorValue)(grandParentNode.callee.property)) && grandParentNode.parent) {
47
+ if (grandParentNode && grandParentNode.type === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isExpectMember)(grandParentNode.callee) && ['then', 'catch'].includes((0, _utils2.getAccessorValue)(grandParentNode.callee.property)) && grandParentNode.parent) {
48
48
  // Just in case `then`s are chained look one above.
49
49
  return getParentIfThenified(grandParentNode);
50
50
  }
@@ -53,18 +53,18 @@ const getParentIfThenified = node => {
53
53
  };
54
54
 
55
55
  const isAcceptableReturnNode = (node, allowReturn) => {
56
- if (allowReturn && node.type === _experimentalUtils.AST_NODE_TYPES.ReturnStatement) {
56
+ if (allowReturn && node.type === _utils.AST_NODE_TYPES.ReturnStatement) {
57
57
  return true;
58
58
  }
59
59
 
60
- if (node.type === _experimentalUtils.AST_NODE_TYPES.ConditionalExpression && node.parent) {
60
+ if (node.type === _utils.AST_NODE_TYPES.ConditionalExpression && node.parent) {
61
61
  return isAcceptableReturnNode(node.parent, allowReturn);
62
62
  }
63
63
 
64
- return [_experimentalUtils.AST_NODE_TYPES.ArrowFunctionExpression, _experimentalUtils.AST_NODE_TYPES.AwaitExpression].includes(node.type);
64
+ return [_utils.AST_NODE_TYPES.ArrowFunctionExpression, _utils.AST_NODE_TYPES.AwaitExpression].includes(node.type);
65
65
  };
66
66
 
67
- const isNoAssertionsParentNode = node => node.type === _experimentalUtils.AST_NODE_TYPES.ExpressionStatement || node.type === _experimentalUtils.AST_NODE_TYPES.AwaitExpression && node.parent !== undefined && node.parent.type === _experimentalUtils.AST_NODE_TYPES.ExpressionStatement;
67
+ const isNoAssertionsParentNode = node => node.type === _utils.AST_NODE_TYPES.ExpressionStatement || node.type === _utils.AST_NODE_TYPES.AwaitExpression && node.parent !== undefined && node.parent.type === _utils.AST_NODE_TYPES.ExpressionStatement;
68
68
 
69
69
  const promiseArrayExceptionKey = ({
70
70
  start,
@@ -73,7 +73,7 @@ const promiseArrayExceptionKey = ({
73
73
 
74
74
  const defaultAsyncMatchers = ['toReject', 'toResolve'];
75
75
 
76
- var _default = (0, _utils.createRule)({
76
+ var _default = (0, _utils2.createRule)({
77
77
  name: __filename,
78
78
  meta: {
79
79
  docs: {
@@ -146,7 +146,7 @@ var _default = (0, _utils.createRule)({
146
146
 
147
147
  return {
148
148
  CallExpression(node) {
149
- if (!(0, _utils.isExpectCall)(node)) {
149
+ if (!(0, _utils2.isExpectCall)(node)) {
150
150
  return;
151
151
  }
152
152
 
@@ -154,10 +154,10 @@ var _default = (0, _utils.createRule)({
154
154
  expect,
155
155
  modifier,
156
156
  matcher
157
- } = (0, _utils.parseExpectCall)(node);
157
+ } = (0, _utils2.parseExpectCall)(node);
158
158
 
159
159
  if (expect.arguments.length < minArgs) {
160
- const expectLength = (0, _utils.getAccessorValue)(expect.callee).length;
160
+ const expectLength = (0, _utils2.getAccessorValue)(expect.callee).length;
161
161
  const loc = {
162
162
  start: {
163
163
  column: node.loc.start.column + expectLength,
@@ -216,7 +216,7 @@ var _default = (0, _utils.createRule)({
216
216
  return;
217
217
  }
218
218
 
219
- if ((0, _utils.isExpectMember)(matcher.node.parent)) {
219
+ if ((0, _utils2.isExpectMember)(matcher.node.parent)) {
220
220
  context.report({
221
221
  messageId: 'modifierUnknown',
222
222
  data: {
@@ -235,7 +235,7 @@ var _default = (0, _utils.createRule)({
235
235
  }
236
236
 
237
237
  const parentNode = matcher.node.parent;
238
- const shouldBeAwaited = modifier && modifier.name !== _utils.ModifierName.not || asyncMatchers.includes(matcher.name);
238
+ const shouldBeAwaited = modifier && modifier.name !== _utils2.ModifierName.not || asyncMatchers.includes(matcher.name);
239
239
 
240
240
  if (!parentNode.parent || !shouldBeAwaited) {
241
241
  return;
@@ -246,7 +246,7 @@ var _default = (0, _utils.createRule)({
246
246
  */
247
247
 
248
248
 
249
- const isParentArrayExpression = parentNode.parent.type === _experimentalUtils.AST_NODE_TYPES.ArrayExpression;
249
+ const isParentArrayExpression = parentNode.parent.type === _utils.AST_NODE_TYPES.ArrayExpression;
250
250
  const orReturned = alwaysAwait ? '' : ' or returned';
251
251
  /**
252
252
  * An async assertion can be chained with `then` or `catch` statements.
@@ -277,7 +277,7 @@ var _default = (0, _utils.createRule)({
277
277
 
278
278
  // nothing called on "expect()"
279
279
  'CallExpression:exit'(node) {
280
- if ((0, _utils.isExpectCall)(node) && isNoAssertionsParentNode(node.parent)) {
280
+ if ((0, _utils2.isExpectCall)(node) && isNoAssertionsParentNode(node.parent)) {
281
281
  context.report({
282
282
  messageId: 'matcherNotFound',
283
283
  node
@@ -5,25 +5,25 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
 
8
- var _experimentalUtils = require("@typescript-eslint/experimental-utils");
8
+ var _utils = require("@typescript-eslint/utils");
9
9
 
10
- var _utils = require("./utils");
10
+ var _utils2 = require("./utils");
11
11
 
12
12
  const trimFXprefix = word => ['f', 'x'].includes(word.charAt(0)) ? word.substr(1) : word;
13
13
 
14
14
  const doesBinaryExpressionContainStringNode = binaryExp => {
15
- if ((0, _utils.isStringNode)(binaryExp.right)) {
15
+ if ((0, _utils2.isStringNode)(binaryExp.right)) {
16
16
  return true;
17
17
  }
18
18
 
19
- if (binaryExp.left.type === _experimentalUtils.AST_NODE_TYPES.BinaryExpression) {
19
+ if (binaryExp.left.type === _utils.AST_NODE_TYPES.BinaryExpression) {
20
20
  return doesBinaryExpressionContainStringNode(binaryExp.left);
21
21
  }
22
22
 
23
- return (0, _utils.isStringNode)(binaryExp.left);
23
+ return (0, _utils2.isStringNode)(binaryExp.left);
24
24
  };
25
25
 
26
- const quoteStringValue = node => node.type === _experimentalUtils.AST_NODE_TYPES.TemplateLiteral ? `\`${node.quasis[0].value.raw}\`` : node.raw;
26
+ const quoteStringValue = node => node.type === _utils.AST_NODE_TYPES.TemplateLiteral ? `\`${node.quasis[0].value.raw}\`` : node.raw;
27
27
 
28
28
  const compileMatcherPattern = matcherMaybeWithMessage => {
29
29
  const [matcher, message] = Array.isArray(matcherMaybeWithMessage) ? matcherMaybeWithMessage : [matcherMaybeWithMessage];
@@ -57,7 +57,7 @@ const MatcherAndMessageSchema = {
57
57
  additionalItems: false
58
58
  };
59
59
 
60
- var _default = (0, _utils.createRule)({
60
+ var _default = (0, _utils2.createRule)({
61
61
  name: __filename,
62
62
  meta: {
63
63
  docs: {
@@ -130,7 +130,7 @@ var _default = (0, _utils.createRule)({
130
130
  CallExpression(node) {
131
131
  var _mustNotMatchPatterns, _mustMatchPatterns$je;
132
132
 
133
- if (!(0, _utils.isDescribeCall)(node) && !(0, _utils.isTestCaseCall)(node)) {
133
+ if (!(0, _utils2.isDescribeCall)(node) && !(0, _utils2.isTestCaseCall)(node)) {
134
134
  return;
135
135
  }
136
136
 
@@ -140,12 +140,12 @@ var _default = (0, _utils.createRule)({
140
140
  return;
141
141
  }
142
142
 
143
- if (!(0, _utils.isStringNode)(argument)) {
144
- if (argument.type === _experimentalUtils.AST_NODE_TYPES.BinaryExpression && doesBinaryExpressionContainStringNode(argument)) {
143
+ if (!(0, _utils2.isStringNode)(argument)) {
144
+ if (argument.type === _utils.AST_NODE_TYPES.BinaryExpression && doesBinaryExpressionContainStringNode(argument)) {
145
145
  return;
146
146
  }
147
147
 
148
- if (argument.type !== _experimentalUtils.AST_NODE_TYPES.TemplateLiteral && !(ignoreTypeOfDescribeName && (0, _utils.isDescribeCall)(node))) {
148
+ if (argument.type !== _utils.AST_NODE_TYPES.TemplateLiteral && !(ignoreTypeOfDescribeName && (0, _utils2.isDescribeCall)(node))) {
149
149
  context.report({
150
150
  messageId: 'titleMustBeString',
151
151
  loc: argument.loc
@@ -155,13 +155,13 @@ var _default = (0, _utils.createRule)({
155
155
  return;
156
156
  }
157
157
 
158
- const title = (0, _utils.getStringValue)(argument);
158
+ const title = (0, _utils2.getStringValue)(argument);
159
159
 
160
160
  if (!title) {
161
161
  context.report({
162
162
  messageId: 'emptyTitle',
163
163
  data: {
164
- jestFunctionName: (0, _utils.isDescribeCall)(node) ? _utils.DescribeAlias.describe : _utils.TestCaseName.test
164
+ jestFunctionName: (0, _utils2.isDescribeCall)(node) ? _utils2.DescribeAlias.describe : _utils2.TestCaseName.test
165
165
  },
166
166
  node
167
167
  });
@@ -191,7 +191,7 @@ var _default = (0, _utils.createRule)({
191
191
  });
192
192
  }
193
193
 
194
- const nodeName = trimFXprefix((0, _utils.getNodeName)(node));
194
+ const nodeName = trimFXprefix((0, _utils2.getNodeName)(node));
195
195
  const [firstWord] = title.split(' ');
196
196
 
197
197
  if (firstWord.toLowerCase() === nodeName) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-jest",
3
- "version": "25.7.0",
4
- "description": "Eslint rules for Jest",
3
+ "version": "26.1.0",
4
+ "description": "ESLint rules for Jest",
5
5
  "keywords": [
6
6
  "eslint",
7
7
  "eslintplugin",
@@ -82,7 +82,7 @@
82
82
  ]
83
83
  },
84
84
  "dependencies": {
85
- "@typescript-eslint/experimental-utils": "^5.0.0"
85
+ "@typescript-eslint/utils": "^5.10.0"
86
86
  },
87
87
  "devDependencies": {
88
88
  "@babel/cli": "^7.4.4",
@@ -112,7 +112,7 @@
112
112
  "eslint-plugin-node": "^11.0.0",
113
113
  "eslint-plugin-prettier": "^3.4.1",
114
114
  "eslint-remote-tester": "^2.1.0",
115
- "eslint-remote-tester-repositories": "^0.0.3",
115
+ "eslint-remote-tester-repositories": "^0.0.4",
116
116
  "husky": "^7.0.2",
117
117
  "is-ci": "^3.0.0",
118
118
  "jest": "^27.0.0",
@@ -121,13 +121,13 @@
121
121
  "pinst": "^2.0.0",
122
122
  "prettier": "^2.0.5",
123
123
  "rimraf": "^3.0.0",
124
- "semantic-release": "^18.0.0",
124
+ "semantic-release": "^19.0.0",
125
125
  "semver": "^7.3.5",
126
126
  "ts-node": "^10.2.1",
127
127
  "typescript": "^4.4.0"
128
128
  },
129
129
  "peerDependencies": {
130
- "@typescript-eslint/eslint-plugin": "^4.0.0 || ^5.0.0",
130
+ "@typescript-eslint/eslint-plugin": "^5.0.0",
131
131
  "eslint": "^6.0.0 || ^7.0.0 || ^8.0.0"
132
132
  },
133
133
  "peerDependenciesMeta": {
@@ -159,7 +159,9 @@
159
159
  ]
160
160
  },
161
161
  "resolutions": {
162
- "@typescript-eslint/experimental-utils": "^5.0.0"
162
+ "@semantic-release/npm/npm": "7.20.6",
163
+ "@typescript-eslint/experimental-utils": "^5.0.0",
164
+ "fsevents/node-gyp": "^7.0.0"
163
165
  },
164
166
  "packageManager": "yarn@3.1.1"
165
167
  }