eslint-plugin-jest 23.0.2 → 23.0.3
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 +9 -0
- package/lib/rules/no-test-callback.js +12 -2
- package/lib/rules/utils.js +13 -2
- package/lib/rules/valid-describe.js +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
## [23.0.3](https://github.com/jest-community/eslint-plugin-jest/compare/v23.0.2...v23.0.3) (2019-11-08)
|
|
2
|
+
|
|
3
|
+
### Bug Fixes
|
|
4
|
+
|
|
5
|
+
- **no-test-callback:** don't provide fix for `async` functions
|
|
6
|
+
([#469](https://github.com/jest-community/eslint-plugin-jest/issues/469))
|
|
7
|
+
([09111e0](https://github.com/jest-community/eslint-plugin-jest/commit/09111e0c951aaa930c9a2c8e0ca84251b3196e94)),
|
|
8
|
+
closes [#466](https://github.com/jest-community/eslint-plugin-jest/issues/466)
|
|
9
|
+
|
|
1
10
|
## [23.0.2](https://github.com/jest-community/eslint-plugin-jest/compare/v23.0.1...v23.0.2) (2019-10-28)
|
|
2
11
|
|
|
3
12
|
### Bug Fixes
|
|
@@ -16,7 +16,8 @@ var _default = (0, _utils.createRule)({
|
|
|
16
16
|
recommended: false
|
|
17
17
|
},
|
|
18
18
|
messages: {
|
|
19
|
-
illegalTestCallback: 'Illegal usage of test callback'
|
|
19
|
+
illegalTestCallback: 'Illegal usage of test callback',
|
|
20
|
+
useAwaitInsteadOfCallback: 'Use await instead of callback in async functions'
|
|
20
21
|
},
|
|
21
22
|
fixable: 'code',
|
|
22
23
|
schema: [],
|
|
@@ -38,6 +39,15 @@ var _default = (0, _utils.createRule)({
|
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
const [argument] = callback.params;
|
|
42
|
+
|
|
43
|
+
if (callback.async) {
|
|
44
|
+
context.report({
|
|
45
|
+
node: argument,
|
|
46
|
+
messageId: 'useAwaitInsteadOfCallback'
|
|
47
|
+
});
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
|
|
41
51
|
context.report({
|
|
42
52
|
node: argument,
|
|
43
53
|
messageId: 'illegalTestCallback',
|
|
@@ -81,7 +91,7 @@ var _default = (0, _utils.createRule)({
|
|
|
81
91
|
let replaceBefore = true;
|
|
82
92
|
|
|
83
93
|
if (body.type === 'BlockStatement') {
|
|
84
|
-
const keyword =
|
|
94
|
+
const keyword = 'return';
|
|
85
95
|
beforeReplacement = `${keyword} ${beforeReplacement}{`;
|
|
86
96
|
afterReplacement += '}';
|
|
87
97
|
replaceBefore = false;
|
package/lib/rules/utils.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getNodeName = getNodeName;
|
|
7
|
-
exports.scopeHasLocalReference = exports.getJestFunctionArguments = exports.isDescribe = exports.isTestCase = exports.isHook = exports.isFunction = exports.TestCaseProperty = exports.DescribeProperty = exports.HookName = exports.TestCaseName = exports.DescribeAlias = exports.parseExpectCall = exports.isParsedEqualityMatcherCall = exports.EqualityMatcher = exports.ModifierName = exports.isExpectMember = exports.isExpectCall = exports.getAccessorValue = exports.isSupportedAccessor = exports.hasOnlyOneArgument = exports.getStringValue = exports.isStringNode = exports.followTypeAssertionChain = exports.createRule = void 0;
|
|
7
|
+
exports.scopeHasLocalReference = exports.getJestFunctionArguments = exports.isDescribeEach = exports.isDescribe = exports.isTestCase = exports.isHook = exports.isFunction = exports.TestCaseProperty = exports.DescribeProperty = exports.HookName = exports.TestCaseName = exports.DescribeAlias = exports.parseExpectCall = exports.isParsedEqualityMatcherCall = exports.EqualityMatcher = exports.ModifierName = exports.isExpectMember = exports.isExpectCall = exports.getAccessorValue = exports.isSupportedAccessor = exports.hasOnlyOneArgument = exports.getStringValue = exports.isStringNode = exports.followTypeAssertionChain = exports.createRule = void 0;
|
|
8
8
|
|
|
9
9
|
var _path = require("path");
|
|
10
10
|
|
|
@@ -401,6 +401,17 @@ exports.isTestCase = isTestCase;
|
|
|
401
401
|
const isDescribe = node => {
|
|
402
402
|
return node.callee.type === _experimentalUtils.AST_NODE_TYPES.Identifier && DescribeAlias.hasOwnProperty(node.callee.name) || node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && node.callee.object.type === _experimentalUtils.AST_NODE_TYPES.Identifier && DescribeAlias.hasOwnProperty(node.callee.object.name) && node.callee.property.type === _experimentalUtils.AST_NODE_TYPES.Identifier && DescribeProperty.hasOwnProperty(node.callee.property.name);
|
|
403
403
|
};
|
|
404
|
+
/**
|
|
405
|
+
* Checks if the given `describe` is a call to `describe.each`.
|
|
406
|
+
*
|
|
407
|
+
* @param {JestFunctionCallExpression<DescribeAlias>} node
|
|
408
|
+
* @return {node is JestFunctionCallExpression<DescribeAlias, DescribeProperty.each>}
|
|
409
|
+
*/
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
exports.isDescribe = isDescribe;
|
|
413
|
+
|
|
414
|
+
const isDescribeEach = node => node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.property, DescribeProperty.each);
|
|
404
415
|
/**
|
|
405
416
|
* Gets the arguments of the given `JestFunctionCallExpression`.
|
|
406
417
|
*
|
|
@@ -413,7 +424,7 @@ const isDescribe = node => {
|
|
|
413
424
|
*/
|
|
414
425
|
|
|
415
426
|
|
|
416
|
-
exports.
|
|
427
|
+
exports.isDescribeEach = isDescribeEach;
|
|
417
428
|
|
|
418
429
|
const getJestFunctionArguments = node => node.callee.type === _experimentalUtils.AST_NODE_TYPES.MemberExpression && isSupportedAccessor(node.callee.property, DescribeProperty.each) && node.parent && node.parent.type === _experimentalUtils.AST_NODE_TYPES.CallExpression ? node.parent.arguments : node.arguments;
|
|
419
430
|
|
|
@@ -79,7 +79,7 @@ var _default = (0, _utils.createRule)({
|
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
if (callback.params.length) {
|
|
82
|
+
if (!(0, _utils.isDescribeEach)(node) && callback.params.length) {
|
|
83
83
|
context.report({
|
|
84
84
|
messageId: 'unexpectedDescribeArgument',
|
|
85
85
|
loc: paramsLocation(callback.params)
|