eslint-plugin-jest 28.0.0-next.1 → 28.0.0-next.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/lib/index.js +0 -2
- package/lib/rules/consistent-test-it.js +3 -3
- package/lib/rules/expect-expect.js +1 -3
- package/lib/rules/max-expects.js +3 -7
- package/lib/rules/max-nested-describe.js +1 -3
- package/lib/rules/no-alias-methods.js +2 -4
- package/lib/rules/no-commented-out-tests.js +1 -3
- package/lib/rules/no-conditional-expect.js +1 -3
- package/lib/rules/no-conditional-in-test.js +1 -3
- package/lib/rules/no-confusing-set-timeout.js +1 -3
- package/lib/rules/no-deprecated-functions.js +2 -5
- package/lib/rules/no-disabled-tests.js +1 -3
- package/lib/rules/no-done-callback.js +5 -9
- package/lib/rules/no-duplicate-hooks.js +4 -7
- package/lib/rules/no-export.js +1 -3
- package/lib/rules/no-focused-tests.js +2 -4
- package/lib/rules/no-hooks.js +3 -4
- package/lib/rules/no-identical-title.js +1 -3
- package/lib/rules/no-interpolation-in-snapshots.js +2 -4
- package/lib/rules/no-jasmine-globals.js +1 -3
- package/lib/rules/no-large-snapshots.js +2 -4
- package/lib/rules/no-mocks-import.js +1 -3
- package/lib/rules/no-restricted-jest-methods.js +2 -4
- package/lib/rules/no-restricted-matchers.js +2 -4
- package/lib/rules/no-standalone-expect.js +6 -9
- package/lib/rules/no-test-prefixes.js +2 -4
- package/lib/rules/no-test-return-statement.js +1 -3
- package/lib/rules/no-untyped-mock-factory.js +10 -7
- package/lib/rules/prefer-called-with.js +2 -4
- package/lib/rules/prefer-comparison-matcher.js +4 -6
- package/lib/rules/prefer-each.js +1 -3
- package/lib/rules/prefer-equality-matcher.js +4 -6
- package/lib/rules/prefer-expect-assertions.js +6 -10
- package/lib/rules/prefer-expect-resolves.js +4 -6
- package/lib/rules/prefer-hooks-in-order.js +2 -4
- package/lib/rules/prefer-hooks-on-top.js +1 -3
- package/lib/rules/prefer-lowercase-title.js +4 -3
- package/lib/rules/prefer-mock-promise-shorthand.js +3 -6
- package/lib/rules/prefer-snapshot-hint.js +3 -5
- package/lib/rules/prefer-spy-on.js +2 -5
- package/lib/rules/prefer-strict-equal.js +2 -4
- package/lib/rules/prefer-to-be.js +3 -6
- package/lib/rules/prefer-to-contain.js +3 -5
- package/lib/rules/prefer-to-have-length.js +4 -6
- package/lib/rules/prefer-todo.js +2 -4
- package/lib/rules/require-hook.js +2 -5
- package/lib/rules/require-to-throw-message.js +2 -4
- package/lib/rules/require-top-level-describe.js +1 -3
- package/lib/rules/unbound-method.js +8 -9
- package/lib/rules/utils/misc.js +6 -18
- package/lib/rules/utils/parseJestFnCall.js +12 -16
- package/lib/rules/valid-describe-callback.js +2 -4
- package/lib/rules/valid-expect-in-promise.js +7 -11
- package/lib/rules/valid-expect.js +7 -14
- package/lib/rules/valid-title.js +3 -4
- package/package.json +4 -4
|
@@ -43,9 +43,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
43
43
|
name: __filename,
|
|
44
44
|
meta: {
|
|
45
45
|
docs: {
|
|
46
|
-
|
|
47
|
-
description: 'Suggest using the built-in comparison matchers',
|
|
48
|
-
recommended: false
|
|
46
|
+
description: 'Suggest using the built-in comparison matchers'
|
|
49
47
|
},
|
|
50
48
|
messages: {
|
|
51
49
|
useToBeComparison: 'Prefer using `{{ preferredMatcher }}` instead'
|
|
@@ -59,13 +57,13 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
59
57
|
return {
|
|
60
58
|
CallExpression(node) {
|
|
61
59
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
62
|
-
if (
|
|
60
|
+
if (jestFnCall?.type !== 'expect' || jestFnCall.args.length === 0) {
|
|
63
61
|
return;
|
|
64
62
|
}
|
|
65
63
|
const {
|
|
66
64
|
parent: expect
|
|
67
65
|
} = jestFnCall.head.node;
|
|
68
|
-
if (
|
|
66
|
+
if (expect?.type !== _utils.AST_NODE_TYPES.CallExpression) {
|
|
69
67
|
return;
|
|
70
68
|
}
|
|
71
69
|
const {
|
|
@@ -76,7 +74,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
76
74
|
matcher
|
|
77
75
|
} = jestFnCall;
|
|
78
76
|
const matcherArg = (0, _utils2.getFirstMatcherArg)(jestFnCall);
|
|
79
|
-
if (
|
|
77
|
+
if (comparison?.type !== _utils.AST_NODE_TYPES.BinaryExpression || isComparingToString(comparison) || !_utils2.EqualityMatcher.hasOwnProperty((0, _utils2.getAccessorValue)(matcher)) || !(0, _utils2.isBooleanLiteral)(matcherArg)) {
|
|
80
78
|
return;
|
|
81
79
|
}
|
|
82
80
|
const [modifier] = jestFnCall.modifiers;
|
package/lib/rules/prefer-each.js
CHANGED
|
@@ -9,9 +9,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
9
9
|
name: __filename,
|
|
10
10
|
meta: {
|
|
11
11
|
docs: {
|
|
12
|
-
|
|
13
|
-
description: 'Prefer using `.each` rather than manual loops',
|
|
14
|
-
recommended: false
|
|
12
|
+
description: 'Prefer using `.each` rather than manual loops'
|
|
15
13
|
},
|
|
16
14
|
messages: {
|
|
17
15
|
preferEach: 'prefer using `{{ fn }}.each` rather than a manual loop'
|
|
@@ -10,9 +10,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
10
10
|
name: __filename,
|
|
11
11
|
meta: {
|
|
12
12
|
docs: {
|
|
13
|
-
|
|
14
|
-
description: 'Suggest using the built-in equality matchers',
|
|
15
|
-
recommended: false
|
|
13
|
+
description: 'Suggest using the built-in equality matchers'
|
|
16
14
|
},
|
|
17
15
|
messages: {
|
|
18
16
|
useEqualityMatcher: 'Prefer using one of the equality matchers instead',
|
|
@@ -27,13 +25,13 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
27
25
|
return {
|
|
28
26
|
CallExpression(node) {
|
|
29
27
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
30
|
-
if (
|
|
28
|
+
if (jestFnCall?.type !== 'expect' || jestFnCall.args.length === 0) {
|
|
31
29
|
return;
|
|
32
30
|
}
|
|
33
31
|
const {
|
|
34
32
|
parent: expect
|
|
35
33
|
} = jestFnCall.head.node;
|
|
36
|
-
if (
|
|
34
|
+
if (expect?.type !== _utils.AST_NODE_TYPES.CallExpression) {
|
|
37
35
|
return;
|
|
38
36
|
}
|
|
39
37
|
const {
|
|
@@ -44,7 +42,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
44
42
|
matcher
|
|
45
43
|
} = jestFnCall;
|
|
46
44
|
const matcherArg = (0, _utils2.getFirstMatcherArg)(jestFnCall);
|
|
47
|
-
if (
|
|
45
|
+
if (comparison?.type !== _utils.AST_NODE_TYPES.BinaryExpression || comparison.operator !== '===' && comparison.operator !== '!==' || !_utils2.EqualityMatcher.hasOwnProperty((0, _utils2.getAccessorValue)(matcher)) || !(0, _utils2.isBooleanLiteral)(matcherArg)) {
|
|
48
46
|
return;
|
|
49
47
|
}
|
|
50
48
|
const matcherValue = matcherArg.value;
|
|
@@ -9,14 +9,13 @@ var _utils2 = require("./utils");
|
|
|
9
9
|
const isFirstStatement = node => {
|
|
10
10
|
let parent = node;
|
|
11
11
|
while (parent) {
|
|
12
|
-
|
|
13
|
-
if (((_parent$parent = parent.parent) === null || _parent$parent === void 0 ? void 0 : _parent$parent.type) === _utils.AST_NODE_TYPES.BlockStatement) {
|
|
12
|
+
if (parent.parent?.type === _utils.AST_NODE_TYPES.BlockStatement) {
|
|
14
13
|
return parent.parent.body[0] === parent;
|
|
15
14
|
}
|
|
16
15
|
|
|
17
16
|
// if we've hit an arrow function, then it must have a single expression
|
|
18
17
|
// as its body, as otherwise we would have hit the block statement already
|
|
19
|
-
if (
|
|
18
|
+
if (parent.parent?.type === _utils.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
20
19
|
return true;
|
|
21
20
|
}
|
|
22
21
|
parent = parent.parent;
|
|
@@ -33,9 +32,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
33
32
|
name: __filename,
|
|
34
33
|
meta: {
|
|
35
34
|
docs: {
|
|
36
|
-
|
|
37
|
-
description: 'Suggest using `expect.assertions()` OR `expect.hasAssertions()`',
|
|
38
|
-
recommended: false
|
|
35
|
+
description: 'Suggest using `expect.assertions()` OR `expect.hasAssertions()`'
|
|
39
36
|
},
|
|
40
37
|
messages: {
|
|
41
38
|
hasAssertionsTakesNoArguments: '`expect.hasAssertions` expects no arguments',
|
|
@@ -150,13 +147,12 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
150
147
|
'ForOfStatement:exit': exitForLoop,
|
|
151
148
|
CallExpression(node) {
|
|
152
149
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
153
|
-
if (
|
|
150
|
+
if (jestFnCall?.type === 'test') {
|
|
154
151
|
inTestCaseCall = true;
|
|
155
152
|
return;
|
|
156
153
|
}
|
|
157
|
-
if (
|
|
158
|
-
|
|
159
|
-
if (expressionDepth === 1 && isFirstStatement(node) && ((_jestFnCall$head$node = jestFnCall.head.node.parent) === null || _jestFnCall$head$node === void 0 ? void 0 : _jestFnCall$head$node.type) === _utils.AST_NODE_TYPES.MemberExpression && jestFnCall.members.length === 1 && ['assertions', 'hasAssertions'].includes((0, _utils2.getAccessorValue)(jestFnCall.members[0]))) {
|
|
154
|
+
if (jestFnCall?.type === 'expect' && inTestCaseCall) {
|
|
155
|
+
if (expressionDepth === 1 && isFirstStatement(node) && jestFnCall.head.node.parent?.type === _utils.AST_NODE_TYPES.MemberExpression && jestFnCall.members.length === 1 && ['assertions', 'hasAssertions'].includes((0, _utils2.getAccessorValue)(jestFnCall.members[0]))) {
|
|
160
156
|
checkExpectHasAssertions(jestFnCall, node);
|
|
161
157
|
hasExpectAssertionsAsFirstStatement = true;
|
|
162
158
|
}
|
|
@@ -10,9 +10,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
10
10
|
name: __filename,
|
|
11
11
|
meta: {
|
|
12
12
|
docs: {
|
|
13
|
-
|
|
14
|
-
description: 'Prefer `await expect(...).resolves` over `expect(await ...)` syntax',
|
|
15
|
-
recommended: false
|
|
13
|
+
description: 'Prefer `await expect(...).resolves` over `expect(await ...)` syntax'
|
|
16
14
|
},
|
|
17
15
|
fixable: 'code',
|
|
18
16
|
messages: {
|
|
@@ -25,17 +23,17 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
25
23
|
create: context => ({
|
|
26
24
|
CallExpression(node) {
|
|
27
25
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
28
|
-
if (
|
|
26
|
+
if (jestFnCall?.type !== 'expect') {
|
|
29
27
|
return;
|
|
30
28
|
}
|
|
31
29
|
const {
|
|
32
30
|
parent
|
|
33
31
|
} = jestFnCall.head.node;
|
|
34
|
-
if (
|
|
32
|
+
if (parent?.type !== _utils.AST_NODE_TYPES.CallExpression) {
|
|
35
33
|
return;
|
|
36
34
|
}
|
|
37
35
|
const [awaitNode] = parent.arguments;
|
|
38
|
-
if (
|
|
36
|
+
if (awaitNode?.type === _utils.AST_NODE_TYPES.AwaitExpression) {
|
|
39
37
|
context.report({
|
|
40
38
|
node: awaitNode,
|
|
41
39
|
messageId: 'expectResolves',
|
|
@@ -10,9 +10,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
10
10
|
name: __filename,
|
|
11
11
|
meta: {
|
|
12
12
|
docs: {
|
|
13
|
-
|
|
14
|
-
description: 'Prefer having hooks in a consistent order',
|
|
15
|
-
recommended: false
|
|
13
|
+
description: 'Prefer having hooks in a consistent order'
|
|
16
14
|
},
|
|
17
15
|
messages: {
|
|
18
16
|
reorderHooks: `\`{{ currentHook }}\` hooks should be before any \`{{ previousHook }}\` hooks`
|
|
@@ -31,7 +29,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
31
29
|
return;
|
|
32
30
|
}
|
|
33
31
|
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
34
|
-
if (
|
|
32
|
+
if (jestFnCall?.type !== 'hook') {
|
|
35
33
|
// Reset the previousHookIndex when encountering something different from a hook
|
|
36
34
|
previousHookIndex = -1;
|
|
37
35
|
return;
|
|
@@ -9,9 +9,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
9
9
|
name: __filename,
|
|
10
10
|
meta: {
|
|
11
11
|
docs: {
|
|
12
|
-
|
|
13
|
-
description: 'Suggest having hooks before any test cases',
|
|
14
|
-
recommended: false
|
|
12
|
+
description: 'Suggest having hooks before any test cases'
|
|
15
13
|
},
|
|
16
14
|
messages: {
|
|
17
15
|
noHookOnTop: 'Hooks should come before test cases'
|
|
@@ -24,9 +24,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
24
24
|
meta: {
|
|
25
25
|
type: 'suggestion',
|
|
26
26
|
docs: {
|
|
27
|
-
description: 'Enforce lowercase test names'
|
|
28
|
-
category: 'Best Practices',
|
|
29
|
-
recommended: false
|
|
27
|
+
description: 'Enforce lowercase test names'
|
|
30
28
|
},
|
|
31
29
|
fixable: 'code',
|
|
32
30
|
messages: {
|
|
@@ -38,6 +36,9 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
38
36
|
ignore: {
|
|
39
37
|
type: 'array',
|
|
40
38
|
items: {
|
|
39
|
+
type: 'string',
|
|
40
|
+
// for some reason TypeScript thinks this _must_ be a read-only
|
|
41
|
+
// array, so we have to explicitly cast it as a mutable array
|
|
41
42
|
enum: [_utils.DescribeAlias.describe, _utils.TestCaseName.test, _utils.TestCaseName.it]
|
|
42
43
|
},
|
|
43
44
|
additionalItems: false
|
|
@@ -10,11 +10,10 @@ const withOnce = (name, addOnce) => {
|
|
|
10
10
|
return `${name}${addOnce ? 'Once' : ''}`;
|
|
11
11
|
};
|
|
12
12
|
const findSingleReturnArgumentNode = fnNode => {
|
|
13
|
-
var _fnNode$body$body$;
|
|
14
13
|
if (fnNode.body.type !== _utils.AST_NODE_TYPES.BlockStatement) {
|
|
15
14
|
return fnNode.body;
|
|
16
15
|
}
|
|
17
|
-
if (
|
|
16
|
+
if (fnNode.body.body[0]?.type === _utils.AST_NODE_TYPES.ReturnStatement) {
|
|
18
17
|
return fnNode.body.body[0].argument;
|
|
19
18
|
}
|
|
20
19
|
return null;
|
|
@@ -23,9 +22,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
23
22
|
name: __filename,
|
|
24
23
|
meta: {
|
|
25
24
|
docs: {
|
|
26
|
-
|
|
27
|
-
description: 'Prefer mock resolved/rejected shorthands for promises',
|
|
28
|
-
recommended: false
|
|
25
|
+
description: 'Prefer mock resolved/rejected shorthands for promises'
|
|
29
26
|
},
|
|
30
27
|
messages: {
|
|
31
28
|
useMockShorthand: 'Prefer {{ replacement }}'
|
|
@@ -37,7 +34,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
37
34
|
defaultOptions: [],
|
|
38
35
|
create(context) {
|
|
39
36
|
const report = (property, isOnce, outerArgNode, innerArgNode = outerArgNode) => {
|
|
40
|
-
if (
|
|
37
|
+
if (innerArgNode?.type !== _utils.AST_NODE_TYPES.CallExpression) {
|
|
41
38
|
return;
|
|
42
39
|
}
|
|
43
40
|
const argName = (0, _utils2.getNodeName)(innerArgNode);
|
|
@@ -36,9 +36,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
36
36
|
name: __filename,
|
|
37
37
|
meta: {
|
|
38
38
|
docs: {
|
|
39
|
-
|
|
40
|
-
description: 'Prefer including a hint with external snapshots',
|
|
41
|
-
recommended: false
|
|
39
|
+
description: 'Prefer including a hint with external snapshots'
|
|
42
40
|
},
|
|
43
41
|
messages,
|
|
44
42
|
type: 'suggestion',
|
|
@@ -95,8 +93,8 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
95
93
|
},
|
|
96
94
|
CallExpression(node) {
|
|
97
95
|
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
98
|
-
if (
|
|
99
|
-
if (
|
|
96
|
+
if (jestFnCall?.type !== 'expect') {
|
|
97
|
+
if (jestFnCall?.type === 'describe' || jestFnCall?.type === 'test') {
|
|
100
98
|
depths.push(expressionDepth);
|
|
101
99
|
expressionDepth = 0;
|
|
102
100
|
}
|
|
@@ -29,8 +29,7 @@ const getJestFnCall = node => {
|
|
|
29
29
|
return getJestFnCall(obj);
|
|
30
30
|
};
|
|
31
31
|
const getAutoFixMockImplementation = (jestFnCall, context) => {
|
|
32
|
-
|
|
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';
|
|
32
|
+
const hasMockImplementationAlready = jestFnCall.parent?.type === _utils.AST_NODE_TYPES.MemberExpression && jestFnCall.parent.property.type === _utils.AST_NODE_TYPES.Identifier && jestFnCall.parent.property.name === 'mockImplementation';
|
|
34
33
|
if (hasMockImplementationAlready) {
|
|
35
34
|
return '';
|
|
36
35
|
}
|
|
@@ -42,9 +41,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
42
41
|
name: __filename,
|
|
43
42
|
meta: {
|
|
44
43
|
docs: {
|
|
45
|
-
|
|
46
|
-
description: 'Suggest using `jest.spyOn()`',
|
|
47
|
-
recommended: false
|
|
44
|
+
description: 'Suggest using `jest.spyOn()`'
|
|
48
45
|
},
|
|
49
46
|
messages: {
|
|
50
47
|
useJestSpyOn: 'Use jest.spyOn() instead'
|
|
@@ -9,9 +9,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
9
9
|
name: __filename,
|
|
10
10
|
meta: {
|
|
11
11
|
docs: {
|
|
12
|
-
|
|
13
|
-
description: 'Suggest using `toStrictEqual()`',
|
|
14
|
-
recommended: false
|
|
12
|
+
description: 'Suggest using `toStrictEqual()`'
|
|
15
13
|
},
|
|
16
14
|
messages: {
|
|
17
15
|
useToStrictEqual: 'Use `toStrictEqual()` instead',
|
|
@@ -26,7 +24,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
26
24
|
return {
|
|
27
25
|
CallExpression(node) {
|
|
28
26
|
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
29
|
-
if (
|
|
27
|
+
if (jestFnCall?.type !== 'expect') {
|
|
30
28
|
return;
|
|
31
29
|
}
|
|
32
30
|
const {
|
|
@@ -30,9 +30,8 @@ const reportPreferToBe = (context, whatToBe, expectFnCall, func, modifierNode) =
|
|
|
30
30
|
context.report({
|
|
31
31
|
messageId: `useToBe${whatToBe}`,
|
|
32
32
|
fix(fixer) {
|
|
33
|
-
var _expectFnCall$args;
|
|
34
33
|
const fixes = [(0, _utils2.replaceAccessorFixer)(fixer, expectFnCall.matcher, `toBe${whatToBe}`)];
|
|
35
|
-
if (
|
|
34
|
+
if (expectFnCall.args?.length && whatToBe !== '') {
|
|
36
35
|
fixes.push((0, _utils2.removeExtraArgumentsFixer)(fixer, context, func, 0));
|
|
37
36
|
}
|
|
38
37
|
if (modifierNode) {
|
|
@@ -47,9 +46,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
47
46
|
name: __filename,
|
|
48
47
|
meta: {
|
|
49
48
|
docs: {
|
|
50
|
-
|
|
51
|
-
description: 'Suggest using `toBe()` for primitive literals',
|
|
52
|
-
recommended: false
|
|
49
|
+
description: 'Suggest using `toBe()` for primitive literals'
|
|
53
50
|
},
|
|
54
51
|
messages: {
|
|
55
52
|
useToBe: 'Use `toBe` when expecting primitive literals',
|
|
@@ -67,7 +64,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
67
64
|
return {
|
|
68
65
|
CallExpression(node) {
|
|
69
66
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
70
|
-
if (
|
|
67
|
+
if (jestFnCall?.type !== 'expect') {
|
|
71
68
|
return;
|
|
72
69
|
}
|
|
73
70
|
const matcherName = (0, _utils2.getAccessorValue)(jestFnCall.matcher);
|
|
@@ -21,9 +21,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
21
21
|
name: __filename,
|
|
22
22
|
meta: {
|
|
23
23
|
docs: {
|
|
24
|
-
|
|
25
|
-
description: 'Suggest using `toContain()`',
|
|
26
|
-
recommended: false
|
|
24
|
+
description: 'Suggest using `toContain()`'
|
|
27
25
|
},
|
|
28
26
|
messages: {
|
|
29
27
|
useToContain: 'Use toContain() instead'
|
|
@@ -37,13 +35,13 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
37
35
|
return {
|
|
38
36
|
CallExpression(node) {
|
|
39
37
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
40
|
-
if (
|
|
38
|
+
if (jestFnCall?.type !== 'expect' || jestFnCall.args.length === 0) {
|
|
41
39
|
return;
|
|
42
40
|
}
|
|
43
41
|
const {
|
|
44
42
|
parent: expect
|
|
45
43
|
} = jestFnCall.head.node;
|
|
46
|
-
if (
|
|
44
|
+
if (expect?.type !== _utils.AST_NODE_TYPES.CallExpression) {
|
|
47
45
|
return;
|
|
48
46
|
}
|
|
49
47
|
const {
|
|
@@ -10,9 +10,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
10
10
|
name: __filename,
|
|
11
11
|
meta: {
|
|
12
12
|
docs: {
|
|
13
|
-
|
|
14
|
-
description: 'Suggest using `toHaveLength()`',
|
|
15
|
-
recommended: false
|
|
13
|
+
description: 'Suggest using `toHaveLength()`'
|
|
16
14
|
},
|
|
17
15
|
messages: {
|
|
18
16
|
useToHaveLength: 'Use toHaveLength() instead'
|
|
@@ -26,20 +24,20 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
26
24
|
return {
|
|
27
25
|
CallExpression(node) {
|
|
28
26
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
29
|
-
if (
|
|
27
|
+
if (jestFnCall?.type !== 'expect') {
|
|
30
28
|
return;
|
|
31
29
|
}
|
|
32
30
|
const {
|
|
33
31
|
parent: expect
|
|
34
32
|
} = jestFnCall.head.node;
|
|
35
|
-
if (
|
|
33
|
+
if (expect?.type !== _utils.AST_NODE_TYPES.CallExpression) {
|
|
36
34
|
return;
|
|
37
35
|
}
|
|
38
36
|
const [argument] = expect.arguments;
|
|
39
37
|
const {
|
|
40
38
|
matcher
|
|
41
39
|
} = jestFnCall;
|
|
42
|
-
if (!_utils2.EqualityMatcher.hasOwnProperty((0, _utils2.getAccessorValue)(matcher)) ||
|
|
40
|
+
if (!_utils2.EqualityMatcher.hasOwnProperty((0, _utils2.getAccessorValue)(matcher)) || argument?.type !== _utils.AST_NODE_TYPES.MemberExpression || !(0, _utils2.isSupportedAccessor)(argument.property, 'length')) {
|
|
43
41
|
return;
|
|
44
42
|
}
|
|
45
43
|
context.report({
|
package/lib/rules/prefer-todo.js
CHANGED
|
@@ -33,9 +33,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
33
33
|
name: __filename,
|
|
34
34
|
meta: {
|
|
35
35
|
docs: {
|
|
36
|
-
|
|
37
|
-
description: 'Suggest using `test.todo`',
|
|
38
|
-
recommended: false
|
|
36
|
+
description: 'Suggest using `test.todo`'
|
|
39
37
|
},
|
|
40
38
|
messages: {
|
|
41
39
|
emptyTest: 'Prefer todo test case over empty test case',
|
|
@@ -51,7 +49,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
51
49
|
CallExpression(node) {
|
|
52
50
|
const [title, callback] = node.arguments;
|
|
53
51
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
54
|
-
if (!title ||
|
|
52
|
+
if (!title || jestFnCall?.type !== 'test' || !isTargetedTestCase(jestFnCall) || !(0, _utils2.isStringNode)(title)) {
|
|
55
53
|
return;
|
|
56
54
|
}
|
|
57
55
|
if (callback && isEmptyFunction(callback)) {
|
|
@@ -7,11 +7,10 @@ exports.default = void 0;
|
|
|
7
7
|
var _utils = require("@typescript-eslint/utils");
|
|
8
8
|
var _utils2 = require("./utils");
|
|
9
9
|
const isJestFnCall = (node, context) => {
|
|
10
|
-
var _getNodeName;
|
|
11
10
|
if ((0, _utils2.parseJestFnCall)(node, context)) {
|
|
12
11
|
return true;
|
|
13
12
|
}
|
|
14
|
-
return !!(
|
|
13
|
+
return !!(0, _utils2.getNodeName)(node)?.startsWith('jest.');
|
|
15
14
|
};
|
|
16
15
|
const isNullOrUndefined = node => {
|
|
17
16
|
return node.type === _utils.AST_NODE_TYPES.Literal && node.value === null || (0, _utils2.isIdentifier)(node, 'undefined');
|
|
@@ -39,9 +38,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
39
38
|
name: __filename,
|
|
40
39
|
meta: {
|
|
41
40
|
docs: {
|
|
42
|
-
|
|
43
|
-
description: 'Require setup and teardown code to be within a hook',
|
|
44
|
-
recommended: false
|
|
41
|
+
description: 'Require setup and teardown code to be within a hook'
|
|
45
42
|
},
|
|
46
43
|
messages: {
|
|
47
44
|
useHook: 'This should be done within a hook'
|
|
@@ -9,9 +9,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
9
9
|
name: __filename,
|
|
10
10
|
meta: {
|
|
11
11
|
docs: {
|
|
12
|
-
|
|
13
|
-
description: 'Require a message for `toThrow()`',
|
|
14
|
-
recommended: false
|
|
12
|
+
description: 'Require a message for `toThrow()`'
|
|
15
13
|
},
|
|
16
14
|
messages: {
|
|
17
15
|
addErrorMessage: 'Add an error message to {{ matcherName }}()'
|
|
@@ -24,7 +22,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
24
22
|
return {
|
|
25
23
|
CallExpression(node) {
|
|
26
24
|
const jestFnCall = (0, _utils.parseJestFnCall)(node, context);
|
|
27
|
-
if (
|
|
25
|
+
if (jestFnCall?.type !== 'expect') {
|
|
28
26
|
return;
|
|
29
27
|
}
|
|
30
28
|
const {
|
|
@@ -14,9 +14,7 @@ var _default = exports.default = (0, _utils.createRule)({
|
|
|
14
14
|
name: __filename,
|
|
15
15
|
meta: {
|
|
16
16
|
docs: {
|
|
17
|
-
|
|
18
|
-
description: 'Require test cases and hooks to be inside a `describe` block',
|
|
19
|
-
recommended: false
|
|
17
|
+
description: 'Require test cases and hooks to be inside a `describe` block'
|
|
20
18
|
},
|
|
21
19
|
messages,
|
|
22
20
|
type: 'suggestion',
|
|
@@ -34,27 +34,26 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
34
34
|
},
|
|
35
35
|
schema: [],
|
|
36
36
|
type: 'problem',
|
|
37
|
-
...
|
|
37
|
+
...baseRule?.meta,
|
|
38
38
|
docs: {
|
|
39
|
-
category: 'Best Practices',
|
|
40
39
|
description: 'Enforce unbound methods are called with their expected scope',
|
|
41
40
|
requiresTypeChecking: true,
|
|
42
|
-
...
|
|
43
|
-
recommended
|
|
41
|
+
...baseRule?.meta.docs,
|
|
42
|
+
// mark this as not recommended
|
|
43
|
+
recommended: undefined
|
|
44
44
|
}
|
|
45
45
|
},
|
|
46
46
|
create(context) {
|
|
47
|
-
const baseSelectors = baseRule
|
|
47
|
+
const baseSelectors = baseRule?.create(context);
|
|
48
48
|
if (!baseSelectors) {
|
|
49
49
|
return {};
|
|
50
50
|
}
|
|
51
51
|
return {
|
|
52
52
|
...baseSelectors,
|
|
53
53
|
MemberExpression(node) {
|
|
54
|
-
|
|
55
|
-
if (((_node$parent = node.parent) === null || _node$parent === void 0 ? void 0 : _node$parent.type) === _utils.AST_NODE_TYPES.CallExpression) {
|
|
54
|
+
if (node.parent?.type === _utils.AST_NODE_TYPES.CallExpression) {
|
|
56
55
|
const jestFnCall = (0, _utils2.parseJestFnCall)((0, _utils2.findTopMostCallExpression)(node.parent), context);
|
|
57
|
-
if (
|
|
56
|
+
if (jestFnCall?.type === 'expect') {
|
|
58
57
|
const {
|
|
59
58
|
matcher
|
|
60
59
|
} = jestFnCall;
|
|
@@ -63,7 +62,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
64
|
}
|
|
66
|
-
|
|
65
|
+
baseSelectors.MemberExpression?.(node);
|
|
67
66
|
}
|
|
68
67
|
};
|
|
69
68
|
}
|
package/lib/rules/utils/misc.js
CHANGED
|
@@ -103,7 +103,7 @@ const getTestCallExpressionsFromDeclaredVariables = (declaredVariables, context)
|
|
|
103
103
|
references
|
|
104
104
|
}) => acc.concat(references.map(({
|
|
105
105
|
identifier
|
|
106
|
-
}) => identifier.parent).filter(node =>
|
|
106
|
+
}) => identifier.parent).filter(node => node?.type === _utils.AST_NODE_TYPES.CallExpression && (0, _parseJestFnCall.isTypeOfJestFnCall)(node, context, ['test']))), []);
|
|
107
107
|
};
|
|
108
108
|
|
|
109
109
|
/**
|
|
@@ -160,42 +160,30 @@ const getFirstMatcherArg = expectFnCall => {
|
|
|
160
160
|
/* istanbul ignore next */
|
|
161
161
|
exports.getFirstMatcherArg = getFirstMatcherArg;
|
|
162
162
|
const getFilename = context => {
|
|
163
|
-
return
|
|
163
|
+
return context.filename ?? context.getFilename();
|
|
164
164
|
};
|
|
165
165
|
|
|
166
166
|
/* istanbul ignore next */
|
|
167
167
|
exports.getFilename = getFilename;
|
|
168
168
|
const getSourceCode = context => {
|
|
169
|
-
return
|
|
169
|
+
return context.sourceCode ?? context.getSourceCode();
|
|
170
170
|
};
|
|
171
171
|
|
|
172
172
|
/* istanbul ignore next */
|
|
173
173
|
exports.getSourceCode = getSourceCode;
|
|
174
174
|
const getScope = (context, node) => {
|
|
175
|
-
|
|
176
|
-
if ('getScope' in sourceCode) {
|
|
177
|
-
return sourceCode.getScope(node);
|
|
178
|
-
}
|
|
179
|
-
return context.getScope();
|
|
175
|
+
return getSourceCode(context).getScope?.(node) ?? context.getScope();
|
|
180
176
|
};
|
|
181
177
|
|
|
182
178
|
/* istanbul ignore next */
|
|
183
179
|
exports.getScope = getScope;
|
|
184
180
|
const getAncestors = (context, node) => {
|
|
185
|
-
|
|
186
|
-
if ('getAncestors' in sourceCode) {
|
|
187
|
-
return sourceCode.getAncestors(node);
|
|
188
|
-
}
|
|
189
|
-
return context.getAncestors();
|
|
181
|
+
return getSourceCode(context).getAncestors?.(node) ?? context.getAncestors();
|
|
190
182
|
};
|
|
191
183
|
|
|
192
184
|
/* istanbul ignore next */
|
|
193
185
|
exports.getAncestors = getAncestors;
|
|
194
186
|
const getDeclaredVariables = (context, node) => {
|
|
195
|
-
|
|
196
|
-
if ('getDeclaredVariables' in sourceCode) {
|
|
197
|
-
return sourceCode.getDeclaredVariables(node);
|
|
198
|
-
}
|
|
199
|
-
return context.getDeclaredVariables(node);
|
|
187
|
+
return getSourceCode(context).getDeclaredVariables?.(node) ?? context.getDeclaredVariables(node);
|
|
200
188
|
};
|
|
201
189
|
exports.getDeclaredVariables = getDeclaredVariables;
|