eslint-plugin-jest 25.4.0 → 26.0.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.
- package/README.md +2 -0
- package/docs/rules/prefer-comparison-matcher.md +55 -0
- package/docs/rules/prefer-equality-matcher.md +29 -0
- package/docs/rules/prefer-expect-assertions.md +66 -0
- package/docs/rules/valid-expect.md +13 -0
- package/lib/rules/consistent-test-it.js +20 -20
- package/lib/rules/expect-expect.js +9 -9
- package/lib/rules/max-nested-describe.js +5 -5
- package/lib/rules/no-conditional-expect.js +9 -9
- package/lib/rules/no-deprecated-functions.js +6 -6
- package/lib/rules/no-done-callback.js +10 -10
- package/lib/rules/no-export.js +6 -6
- package/lib/rules/no-focused-tests.js +11 -11
- package/lib/rules/no-if.js +11 -11
- package/lib/rules/no-interpolation-in-snapshots.js +6 -6
- package/lib/rules/no-jasmine-globals.js +10 -10
- package/lib/rules/no-large-snapshots.js +8 -8
- package/lib/rules/no-standalone-expect.js +14 -14
- package/lib/rules/no-test-prefixes.js +6 -6
- package/lib/rules/no-test-return-statement.js +8 -8
- package/lib/rules/prefer-comparison-matcher.js +139 -0
- package/lib/rules/prefer-equality-matcher.js +98 -0
- package/lib/rules/prefer-expect-assertions.js +42 -15
- package/lib/rules/prefer-expect-resolves.js +4 -4
- package/lib/rules/prefer-spy-on.js +9 -9
- package/lib/rules/prefer-to-be.js +15 -15
- package/lib/rules/prefer-to-contain.js +11 -11
- package/lib/rules/prefer-to-have-length.js +6 -6
- package/lib/rules/prefer-todo.js +9 -9
- package/lib/rules/require-hook.js +12 -12
- package/lib/rules/utils.js +27 -27
- package/lib/rules/valid-describe-callback.js +9 -9
- package/lib/rules/valid-expect-in-promise.js +44 -44
- package/lib/rules/valid-expect.js +29 -18
- package/lib/rules/valid-title.js +14 -14
- package/package.json +3 -3
- package/CHANGELOG.md +0 -824
|
@@ -5,13 +5,13 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _utils = require("@typescript-eslint/utils");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _utils2 = require("./utils");
|
|
11
11
|
|
|
12
|
-
const isExpectAssertionsOrHasAssertionsCall = expression => expression.type ===
|
|
12
|
+
const isExpectAssertionsOrHasAssertionsCall = expression => expression.type === _utils.AST_NODE_TYPES.CallExpression && expression.callee.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(expression.callee.object, 'expect') && (0, _utils2.isSupportedAccessor)(expression.callee.property) && ['assertions', 'hasAssertions'].includes((0, _utils2.getAccessorValue)(expression.callee.property));
|
|
13
13
|
|
|
14
|
-
const isFirstLineExprStmt = functionBody => functionBody[0] && functionBody[0].type ===
|
|
14
|
+
const isFirstLineExprStmt = functionBody => functionBody[0] && functionBody[0].type === _utils.AST_NODE_TYPES.ExpressionStatement;
|
|
15
15
|
|
|
16
16
|
const suggestRemovingExtraArguments = (args, extraArgsStartAt) => ({
|
|
17
17
|
messageId: 'suggestRemovingExtraArguments',
|
|
@@ -20,7 +20,7 @@ const suggestRemovingExtraArguments = (args, extraArgsStartAt) => ({
|
|
|
20
20
|
|
|
21
21
|
const suggestions = [['suggestAddingHasAssertions', 'expect.hasAssertions();'], ['suggestAddingAssertions', 'expect.assertions();']];
|
|
22
22
|
|
|
23
|
-
var _default = (0,
|
|
23
|
+
var _default = (0, _utils2.createRule)({
|
|
24
24
|
name: __filename,
|
|
25
25
|
meta: {
|
|
26
26
|
docs: {
|
|
@@ -48,6 +48,9 @@ var _default = (0, _utils.createRule)({
|
|
|
48
48
|
},
|
|
49
49
|
onlyFunctionsWithExpectInLoop: {
|
|
50
50
|
type: 'boolean'
|
|
51
|
+
},
|
|
52
|
+
onlyFunctionsWithExpectInCallback: {
|
|
53
|
+
type: 'boolean'
|
|
51
54
|
}
|
|
52
55
|
},
|
|
53
56
|
additionalProperties: false
|
|
@@ -55,16 +58,19 @@ var _default = (0, _utils.createRule)({
|
|
|
55
58
|
},
|
|
56
59
|
defaultOptions: [{
|
|
57
60
|
onlyFunctionsWithAsyncKeyword: false,
|
|
58
|
-
onlyFunctionsWithExpectInLoop: false
|
|
61
|
+
onlyFunctionsWithExpectInLoop: false,
|
|
62
|
+
onlyFunctionsWithExpectInCallback: false
|
|
59
63
|
}],
|
|
60
64
|
|
|
61
65
|
create(context, [options]) {
|
|
66
|
+
let expressionDepth = 0;
|
|
67
|
+
let hasExpectInCallback = false;
|
|
62
68
|
let hasExpectInLoop = false;
|
|
63
69
|
let inTestCaseCall = false;
|
|
64
70
|
let inForLoop = false;
|
|
65
71
|
|
|
66
72
|
const shouldCheckFunction = testFunction => {
|
|
67
|
-
if (!options.onlyFunctionsWithAsyncKeyword && !options.onlyFunctionsWithExpectInLoop) {
|
|
73
|
+
if (!options.onlyFunctionsWithAsyncKeyword && !options.onlyFunctionsWithExpectInLoop && !options.onlyFunctionsWithExpectInCallback) {
|
|
68
74
|
return true;
|
|
69
75
|
}
|
|
70
76
|
|
|
@@ -80,14 +86,28 @@ var _default = (0, _utils.createRule)({
|
|
|
80
86
|
}
|
|
81
87
|
}
|
|
82
88
|
|
|
89
|
+
if (options.onlyFunctionsWithExpectInCallback) {
|
|
90
|
+
if (hasExpectInCallback) {
|
|
91
|
+
return true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
83
95
|
return false;
|
|
84
96
|
};
|
|
85
97
|
|
|
98
|
+
const enterExpression = () => inTestCaseCall && expressionDepth++;
|
|
99
|
+
|
|
100
|
+
const exitExpression = () => inTestCaseCall && expressionDepth--;
|
|
101
|
+
|
|
86
102
|
const enterForLoop = () => inForLoop = true;
|
|
87
103
|
|
|
88
104
|
const exitForLoop = () => inForLoop = false;
|
|
89
105
|
|
|
90
106
|
return {
|
|
107
|
+
FunctionExpression: enterExpression,
|
|
108
|
+
'FunctionExpression:exit': exitExpression,
|
|
109
|
+
ArrowFunctionExpression: enterExpression,
|
|
110
|
+
'ArrowFunctionExpression:exit': exitExpression,
|
|
91
111
|
ForStatement: enterForLoop,
|
|
92
112
|
'ForStatement:exit': exitForLoop,
|
|
93
113
|
ForInStatement: enterForLoop,
|
|
@@ -96,18 +116,24 @@ var _default = (0, _utils.createRule)({
|
|
|
96
116
|
'ForOfStatement:exit': exitForLoop,
|
|
97
117
|
|
|
98
118
|
CallExpression(node) {
|
|
99
|
-
if ((0,
|
|
119
|
+
if ((0, _utils2.isTestCaseCall)(node)) {
|
|
100
120
|
inTestCaseCall = true;
|
|
101
121
|
return;
|
|
102
122
|
}
|
|
103
123
|
|
|
104
|
-
if ((0,
|
|
105
|
-
|
|
124
|
+
if ((0, _utils2.isExpectCall)(node) && inTestCaseCall) {
|
|
125
|
+
if (inForLoop) {
|
|
126
|
+
hasExpectInLoop = true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (expressionDepth > 1) {
|
|
130
|
+
hasExpectInCallback = true;
|
|
131
|
+
}
|
|
106
132
|
}
|
|
107
133
|
},
|
|
108
134
|
|
|
109
135
|
'CallExpression:exit'(node) {
|
|
110
|
-
if (!(0,
|
|
136
|
+
if (!(0, _utils2.isTestCaseCall)(node)) {
|
|
111
137
|
return;
|
|
112
138
|
}
|
|
113
139
|
|
|
@@ -117,7 +143,7 @@ var _default = (0, _utils.createRule)({
|
|
|
117
143
|
|
|
118
144
|
const [, testFn] = node.arguments;
|
|
119
145
|
|
|
120
|
-
if (!(0,
|
|
146
|
+
if (!(0, _utils2.isFunction)(testFn) || testFn.body.type !== _utils.AST_NODE_TYPES.BlockStatement) {
|
|
121
147
|
return;
|
|
122
148
|
}
|
|
123
149
|
|
|
@@ -126,6 +152,7 @@ var _default = (0, _utils.createRule)({
|
|
|
126
152
|
}
|
|
127
153
|
|
|
128
154
|
hasExpectInLoop = false;
|
|
155
|
+
hasExpectInCallback = false;
|
|
129
156
|
const testFuncBody = testFn.body.body;
|
|
130
157
|
|
|
131
158
|
if (!isFirstLineExprStmt(testFuncBody)) {
|
|
@@ -154,7 +181,7 @@ var _default = (0, _utils.createRule)({
|
|
|
154
181
|
return;
|
|
155
182
|
}
|
|
156
183
|
|
|
157
|
-
if ((0,
|
|
184
|
+
if ((0, _utils2.isSupportedAccessor)(testFuncFirstLine.callee.property, 'hasAssertions')) {
|
|
158
185
|
if (testFuncFirstLine.arguments.length) {
|
|
159
186
|
context.report({
|
|
160
187
|
messageId: 'hasAssertionsTakesNoArguments',
|
|
@@ -166,7 +193,7 @@ var _default = (0, _utils.createRule)({
|
|
|
166
193
|
return;
|
|
167
194
|
}
|
|
168
195
|
|
|
169
|
-
if (!(0,
|
|
196
|
+
if (!(0, _utils2.hasOnlyOneArgument)(testFuncFirstLine)) {
|
|
170
197
|
let {
|
|
171
198
|
loc
|
|
172
199
|
} = testFuncFirstLine.callee.property;
|
|
@@ -187,7 +214,7 @@ var _default = (0, _utils.createRule)({
|
|
|
187
214
|
|
|
188
215
|
const [arg] = testFuncFirstLine.arguments;
|
|
189
216
|
|
|
190
|
-
if (arg.type ===
|
|
217
|
+
if (arg.type === _utils.AST_NODE_TYPES.Literal && typeof arg.value === 'number' && Number.isInteger(arg.value)) {
|
|
191
218
|
return;
|
|
192
219
|
}
|
|
193
220
|
|
|
@@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _utils = require("@typescript-eslint/utils");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _utils2 = require("./utils");
|
|
11
11
|
|
|
12
|
-
var _default = (0,
|
|
12
|
+
var _default = (0, _utils2.createRule)({
|
|
13
13
|
name: __filename,
|
|
14
14
|
meta: {
|
|
15
15
|
docs: {
|
|
@@ -29,7 +29,7 @@ var _default = (0, _utils.createRule)({
|
|
|
29
29
|
CallExpression(node) {
|
|
30
30
|
const [awaitNode] = node.arguments;
|
|
31
31
|
|
|
32
|
-
if ((0,
|
|
32
|
+
if ((0, _utils2.isExpectCall)(node) && (awaitNode === null || awaitNode === void 0 ? void 0 : awaitNode.type) === _utils.AST_NODE_TYPES.AwaitExpression) {
|
|
33
33
|
context.report({
|
|
34
34
|
node: node.arguments[0],
|
|
35
35
|
messageId: 'expectResolves',
|
|
@@ -5,16 +5,16 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _utils = require("@typescript-eslint/utils");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _utils2 = require("./utils");
|
|
11
11
|
|
|
12
12
|
const findNodeObject = node => {
|
|
13
13
|
if ('object' in node) {
|
|
14
14
|
return node.object;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
if (node.callee.type ===
|
|
17
|
+
if (node.callee.type === _utils.AST_NODE_TYPES.MemberExpression) {
|
|
18
18
|
return node.callee.object;
|
|
19
19
|
}
|
|
20
20
|
|
|
@@ -22,7 +22,7 @@ const findNodeObject = node => {
|
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
const getJestFnCall = node => {
|
|
25
|
-
if (node.type !==
|
|
25
|
+
if (node.type !== _utils.AST_NODE_TYPES.CallExpression && node.type !== _utils.AST_NODE_TYPES.MemberExpression) {
|
|
26
26
|
return null;
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -32,14 +32,14 @@ const getJestFnCall = node => {
|
|
|
32
32
|
return null;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
if (obj.type ===
|
|
36
|
-
return node.type ===
|
|
35
|
+
if (obj.type === _utils.AST_NODE_TYPES.Identifier) {
|
|
36
|
+
return node.type === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.getNodeName)(node.callee) === 'jest.fn' ? node : null;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
return getJestFnCall(obj);
|
|
40
40
|
};
|
|
41
41
|
|
|
42
|
-
var _default = (0,
|
|
42
|
+
var _default = (0, _utils2.createRule)({
|
|
43
43
|
name: __filename,
|
|
44
44
|
meta: {
|
|
45
45
|
docs: {
|
|
@@ -63,7 +63,7 @@ var _default = (0, _utils.createRule)({
|
|
|
63
63
|
left,
|
|
64
64
|
right
|
|
65
65
|
} = node;
|
|
66
|
-
if (left.type !==
|
|
66
|
+
if (left.type !== _utils.AST_NODE_TYPES.MemberExpression) return;
|
|
67
67
|
const jestFnCall = getJestFnCall(right);
|
|
68
68
|
if (!jestFnCall) return;
|
|
69
69
|
context.report({
|
|
@@ -71,7 +71,7 @@ var _default = (0, _utils.createRule)({
|
|
|
71
71
|
messageId: 'useJestSpyOn',
|
|
72
72
|
|
|
73
73
|
fix(fixer) {
|
|
74
|
-
const leftPropQuote = left.property.type ===
|
|
74
|
+
const leftPropQuote = left.property.type === _utils.AST_NODE_TYPES.Identifier ? "'" : '';
|
|
75
75
|
const [arg] = jestFnCall.arguments;
|
|
76
76
|
const argSource = arg && context.getSourceCode().getText(arg);
|
|
77
77
|
const mockImplementation = argSource ? `.mockImplementation(${argSource})` : '.mockImplementation()';
|
|
@@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _utils = require("@typescript-eslint/utils");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _utils2 = require("./utils");
|
|
11
11
|
|
|
12
|
-
const isNullLiteral = node => node.type ===
|
|
12
|
+
const isNullLiteral = node => node.type === _utils.AST_NODE_TYPES.Literal && node.value === null;
|
|
13
13
|
/**
|
|
14
14
|
* Checks if the given `ParsedEqualityMatcherCall` is a call to one of the equality matchers,
|
|
15
15
|
* with a `null` literal as the sole argument.
|
|
@@ -18,26 +18,26 @@ const isNullLiteral = node => node.type === _experimentalUtils.AST_NODE_TYPES.Li
|
|
|
18
18
|
|
|
19
19
|
const isNullEqualityMatcher = matcher => isNullLiteral(getFirstArgument(matcher));
|
|
20
20
|
|
|
21
|
-
const isFirstArgumentIdentifier = (matcher, name) => (0,
|
|
21
|
+
const isFirstArgumentIdentifier = (matcher, name) => (0, _utils2.isIdentifier)(getFirstArgument(matcher), name);
|
|
22
22
|
|
|
23
23
|
const shouldUseToBe = matcher => {
|
|
24
24
|
const firstArg = getFirstArgument(matcher);
|
|
25
25
|
|
|
26
|
-
if (firstArg.type ===
|
|
26
|
+
if (firstArg.type === _utils.AST_NODE_TYPES.Literal) {
|
|
27
27
|
// regex literals are classed as literals, but they're actually objects
|
|
28
28
|
// which means "toBe" will give different results than other matchers
|
|
29
29
|
return !('regex' in firstArg);
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
-
return firstArg.type ===
|
|
32
|
+
return firstArg.type === _utils.AST_NODE_TYPES.TemplateLiteral;
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
const getFirstArgument = matcher => {
|
|
36
|
-
return (0,
|
|
36
|
+
return (0, _utils2.followTypeAssertionChain)(matcher.arguments[0]);
|
|
37
37
|
};
|
|
38
38
|
|
|
39
39
|
const reportPreferToBe = (context, whatToBe, matcher, modifier) => {
|
|
40
|
-
const modifierNode = (modifier === null || modifier === void 0 ? void 0 : modifier.negation) || (modifier === null || modifier === void 0 ? void 0 : modifier.name) ===
|
|
40
|
+
const modifierNode = (modifier === null || modifier === void 0 ? void 0 : modifier.negation) || (modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils2.ModifierName.not && (modifier === null || modifier === void 0 ? void 0 : modifier.node);
|
|
41
41
|
context.report({
|
|
42
42
|
messageId: `useToBe${whatToBe}`,
|
|
43
43
|
|
|
@@ -61,7 +61,7 @@ const reportPreferToBe = (context, whatToBe, matcher, modifier) => {
|
|
|
61
61
|
});
|
|
62
62
|
};
|
|
63
63
|
|
|
64
|
-
var _default = (0,
|
|
64
|
+
var _default = (0, _utils2.createRule)({
|
|
65
65
|
name: __filename,
|
|
66
66
|
meta: {
|
|
67
67
|
docs: {
|
|
@@ -85,25 +85,25 @@ var _default = (0, _utils.createRule)({
|
|
|
85
85
|
create(context) {
|
|
86
86
|
return {
|
|
87
87
|
CallExpression(node) {
|
|
88
|
-
if (!(0,
|
|
88
|
+
if (!(0, _utils2.isExpectCall)(node)) {
|
|
89
89
|
return;
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
const {
|
|
93
93
|
matcher,
|
|
94
94
|
modifier
|
|
95
|
-
} = (0,
|
|
95
|
+
} = (0, _utils2.parseExpectCall)(node);
|
|
96
96
|
|
|
97
97
|
if (!matcher) {
|
|
98
98
|
return;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
if (((modifier === null || modifier === void 0 ? void 0 : modifier.name) ===
|
|
101
|
+
if (((modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils2.ModifierName.not || modifier !== null && modifier !== void 0 && modifier.negation) && ['toBeUndefined', 'toBeDefined'].includes(matcher.name)) {
|
|
102
102
|
reportPreferToBe(context, matcher.name === 'toBeDefined' ? 'Undefined' : 'Defined', matcher, modifier);
|
|
103
103
|
return;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
if (!(0,
|
|
106
|
+
if (!(0, _utils2.isParsedEqualityMatcherCall)(matcher)) {
|
|
107
107
|
return;
|
|
108
108
|
}
|
|
109
109
|
|
|
@@ -113,7 +113,7 @@ var _default = (0, _utils.createRule)({
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
if (isFirstArgumentIdentifier(matcher, 'undefined')) {
|
|
116
|
-
const name = (modifier === null || modifier === void 0 ? void 0 : modifier.name) ===
|
|
116
|
+
const name = (modifier === null || modifier === void 0 ? void 0 : modifier.name) === _utils2.ModifierName.not || modifier !== null && modifier !== void 0 && modifier.negation ? 'Defined' : 'Undefined';
|
|
117
117
|
reportPreferToBe(context, name, matcher, modifier);
|
|
118
118
|
return;
|
|
119
119
|
}
|
|
@@ -123,7 +123,7 @@ var _default = (0, _utils.createRule)({
|
|
|
123
123
|
return;
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
-
if (shouldUseToBe(matcher) && matcher.name !==
|
|
126
|
+
if (shouldUseToBe(matcher) && matcher.name !== _utils2.EqualityMatcher.toBe) {
|
|
127
127
|
reportPreferToBe(context, '', matcher);
|
|
128
128
|
}
|
|
129
129
|
}
|
|
@@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _utils = require("@typescript-eslint/utils");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _utils2 = require("./utils");
|
|
11
11
|
|
|
12
|
-
const isBooleanLiteral = node => node.type ===
|
|
12
|
+
const isBooleanLiteral = node => node.type === _utils.AST_NODE_TYPES.Literal && typeof node.value === 'boolean';
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Checks if the given `ParsedExpectMatcher` is a call to one of the equality matchers,
|
|
@@ -23,7 +23,7 @@ const isBooleanLiteral = node => node.type === _experimentalUtils.AST_NODE_TYPES
|
|
|
23
23
|
*
|
|
24
24
|
* @return {matcher is ParsedBooleanEqualityMatcher}
|
|
25
25
|
*/
|
|
26
|
-
const isBooleanEqualityMatcher = matcher => (0,
|
|
26
|
+
const isBooleanEqualityMatcher = matcher => (0, _utils2.isParsedEqualityMatcherCall)(matcher) && isBooleanLiteral((0, _utils2.followTypeAssertionChain)(matcher.arguments[0]));
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* Checks if the given `node` is a `CallExpression` representing the calling
|
|
@@ -33,10 +33,10 @@ const isBooleanEqualityMatcher = matcher => (0, _utils.isParsedEqualityMatcherCa
|
|
|
33
33
|
*
|
|
34
34
|
* @return {node is FixableIncludesCallExpression}
|
|
35
35
|
*/
|
|
36
|
-
const isFixableIncludesCallExpression = node => node.type ===
|
|
36
|
+
const isFixableIncludesCallExpression = node => node.type === _utils.AST_NODE_TYPES.CallExpression && node.callee.type === _utils.AST_NODE_TYPES.MemberExpression && (0, _utils2.isSupportedAccessor)(node.callee.property, 'includes') && (0, _utils2.hasOnlyOneArgument)(node); // expect(array.includes(<value>)[not.]{toBe,toEqual}(<boolean>)
|
|
37
37
|
|
|
38
38
|
|
|
39
|
-
var _default = (0,
|
|
39
|
+
var _default = (0, _utils2.createRule)({
|
|
40
40
|
name: __filename,
|
|
41
41
|
meta: {
|
|
42
42
|
docs: {
|
|
@@ -56,7 +56,7 @@ var _default = (0, _utils.createRule)({
|
|
|
56
56
|
create(context) {
|
|
57
57
|
return {
|
|
58
58
|
CallExpression(node) {
|
|
59
|
-
if (!(0,
|
|
59
|
+
if (!(0, _utils2.isExpectCall)(node)) {
|
|
60
60
|
return;
|
|
61
61
|
}
|
|
62
62
|
|
|
@@ -67,9 +67,9 @@ var _default = (0, _utils.createRule)({
|
|
|
67
67
|
},
|
|
68
68
|
matcher,
|
|
69
69
|
modifier
|
|
70
|
-
} = (0,
|
|
70
|
+
} = (0, _utils2.parseExpectCall)(node);
|
|
71
71
|
|
|
72
|
-
if (!matcher || !includesCall || modifier && modifier.name !==
|
|
72
|
+
if (!matcher || !includesCall || modifier && modifier.name !== _utils2.ModifierName.not || !isBooleanEqualityMatcher(matcher) || !isFixableIncludesCallExpression(includesCall)) {
|
|
73
73
|
return;
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -78,10 +78,10 @@ var _default = (0, _utils.createRule)({
|
|
|
78
78
|
const sourceCode = context.getSourceCode(); // we need to negate the expectation if the current expected
|
|
79
79
|
// value is itself negated by the "not" modifier
|
|
80
80
|
|
|
81
|
-
const addNotModifier = (0,
|
|
81
|
+
const addNotModifier = (0, _utils2.followTypeAssertionChain)(matcher.arguments[0]).value === !!modifier;
|
|
82
82
|
return [// remove the "includes" call entirely
|
|
83
83
|
fixer.removeRange([includesCall.callee.property.range[0] - 1, includesCall.range[1]]), // replace the current matcher with "toContain", adding "not" if needed
|
|
84
|
-
fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], addNotModifier ? `.${
|
|
84
|
+
fixer.replaceTextRange([expectCallEnd, matcher.node.range[1]], addNotModifier ? `.${_utils2.ModifierName.not}.toContain` : '.toContain'), // replace the matcher argument with the value from the "includes"
|
|
85
85
|
fixer.replaceText(matcher.arguments[0], sourceCode.getText(includesCall.arguments[0]))];
|
|
86
86
|
},
|
|
87
87
|
|
|
@@ -5,11 +5,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _utils = require("@typescript-eslint/utils");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _utils2 = require("./utils");
|
|
11
11
|
|
|
12
|
-
var _default = (0,
|
|
12
|
+
var _default = (0, _utils2.createRule)({
|
|
13
13
|
name: __filename,
|
|
14
14
|
meta: {
|
|
15
15
|
docs: {
|
|
@@ -29,7 +29,7 @@ var _default = (0, _utils.createRule)({
|
|
|
29
29
|
create(context) {
|
|
30
30
|
return {
|
|
31
31
|
CallExpression(node) {
|
|
32
|
-
if (!(0,
|
|
32
|
+
if (!(0, _utils2.isExpectCall)(node)) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
35
|
|
|
@@ -38,9 +38,9 @@ var _default = (0, _utils.createRule)({
|
|
|
38
38
|
arguments: [argument]
|
|
39
39
|
},
|
|
40
40
|
matcher
|
|
41
|
-
} = (0,
|
|
41
|
+
} = (0, _utils2.parseExpectCall)(node);
|
|
42
42
|
|
|
43
|
-
if (!matcher || !(0,
|
|
43
|
+
if (!matcher || !(0, _utils2.isParsedEqualityMatcherCall)(matcher) || (argument === null || argument === void 0 ? void 0 : argument.type) !== _utils.AST_NODE_TYPES.MemberExpression || !(0, _utils2.isSupportedAccessor)(argument.property, 'length')) {
|
|
44
44
|
return;
|
|
45
45
|
}
|
|
46
46
|
|
package/lib/rules/prefer-todo.js
CHANGED
|
@@ -5,26 +5,26 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _utils = require("@typescript-eslint/utils");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _utils2 = require("./utils");
|
|
11
11
|
|
|
12
12
|
function isEmptyFunction(node) {
|
|
13
|
-
if (!(0,
|
|
13
|
+
if (!(0, _utils2.isFunction)(node)) {
|
|
14
14
|
return false;
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
return node.body.type ===
|
|
17
|
+
return node.body.type === _utils.AST_NODE_TYPES.BlockStatement && !node.body.body.length;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
function createTodoFixer(node, fixer) {
|
|
21
|
-
const testName = (0,
|
|
21
|
+
const testName = (0, _utils2.getNodeName)(node).split('.').shift();
|
|
22
22
|
return fixer.replaceText(node.callee, `${testName}.todo`);
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const isTargetedTestCase = node => (0,
|
|
25
|
+
const isTargetedTestCase = node => (0, _utils2.isTestCaseCall)(node) && [_utils2.TestCaseName.it, _utils2.TestCaseName.test, 'it.skip', 'test.skip'].includes((0, _utils2.getNodeName)(node));
|
|
26
26
|
|
|
27
|
-
var _default = (0,
|
|
27
|
+
var _default = (0, _utils2.createRule)({
|
|
28
28
|
name: __filename,
|
|
29
29
|
meta: {
|
|
30
30
|
docs: {
|
|
@@ -47,7 +47,7 @@ var _default = (0, _utils.createRule)({
|
|
|
47
47
|
CallExpression(node) {
|
|
48
48
|
const [title, callback] = node.arguments;
|
|
49
49
|
|
|
50
|
-
if (!title || !isTargetedTestCase(node) || !(0,
|
|
50
|
+
if (!title || !isTargetedTestCase(node) || !(0, _utils2.isStringNode)(title)) {
|
|
51
51
|
return;
|
|
52
52
|
}
|
|
53
53
|
|
|
@@ -59,7 +59,7 @@ var _default = (0, _utils.createRule)({
|
|
|
59
59
|
});
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
-
if ((0,
|
|
62
|
+
if ((0, _utils2.hasOnlyOneArgument)(node)) {
|
|
63
63
|
context.report({
|
|
64
64
|
messageId: 'unimplementedTest',
|
|
65
65
|
node,
|
|
@@ -5,33 +5,33 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
-
var
|
|
8
|
+
var _utils = require("@typescript-eslint/utils");
|
|
9
9
|
|
|
10
|
-
var
|
|
10
|
+
var _utils2 = require("./utils");
|
|
11
11
|
|
|
12
12
|
const isJestFnCall = node => {
|
|
13
13
|
var _getNodeName;
|
|
14
14
|
|
|
15
|
-
if ((0,
|
|
15
|
+
if ((0, _utils2.isDescribeCall)(node) || (0, _utils2.isTestCaseCall)(node) || (0, _utils2.isHook)(node)) {
|
|
16
16
|
return true;
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
return !!((_getNodeName = (0,
|
|
19
|
+
return !!((_getNodeName = (0, _utils2.getNodeName)(node)) !== null && _getNodeName !== void 0 && _getNodeName.startsWith('jest.'));
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
const isNullOrUndefined = node => {
|
|
23
|
-
return node.type ===
|
|
23
|
+
return node.type === _utils.AST_NODE_TYPES.Literal && node.value === null || (0, _utils2.isIdentifier)(node, 'undefined');
|
|
24
24
|
};
|
|
25
25
|
|
|
26
26
|
const shouldBeInHook = (node, allowedFunctionCalls = []) => {
|
|
27
27
|
switch (node.type) {
|
|
28
|
-
case
|
|
28
|
+
case _utils.AST_NODE_TYPES.ExpressionStatement:
|
|
29
29
|
return shouldBeInHook(node.expression, allowedFunctionCalls);
|
|
30
30
|
|
|
31
|
-
case
|
|
32
|
-
return !(isJestFnCall(node) || allowedFunctionCalls.includes((0,
|
|
31
|
+
case _utils.AST_NODE_TYPES.CallExpression:
|
|
32
|
+
return !(isJestFnCall(node) || allowedFunctionCalls.includes((0, _utils2.getNodeName)(node)));
|
|
33
33
|
|
|
34
|
-
case
|
|
34
|
+
case _utils.AST_NODE_TYPES.VariableDeclaration:
|
|
35
35
|
{
|
|
36
36
|
if (node.kind === 'const') {
|
|
37
37
|
return false;
|
|
@@ -47,7 +47,7 @@ const shouldBeInHook = (node, allowedFunctionCalls = []) => {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
|
|
50
|
-
var _default = (0,
|
|
50
|
+
var _default = (0, _utils2.createRule)({
|
|
51
51
|
name: __filename,
|
|
52
52
|
meta: {
|
|
53
53
|
docs: {
|
|
@@ -100,13 +100,13 @@ var _default = (0, _utils.createRule)({
|
|
|
100
100
|
},
|
|
101
101
|
|
|
102
102
|
CallExpression(node) {
|
|
103
|
-
if (!(0,
|
|
103
|
+
if (!(0, _utils2.isDescribeCall)(node) || node.arguments.length < 2) {
|
|
104
104
|
return;
|
|
105
105
|
}
|
|
106
106
|
|
|
107
107
|
const [, testFn] = node.arguments;
|
|
108
108
|
|
|
109
|
-
if (!(0,
|
|
109
|
+
if (!(0, _utils2.isFunction)(testFn) || testFn.body.type !== _utils.AST_NODE_TYPES.BlockStatement) {
|
|
110
110
|
return;
|
|
111
111
|
}
|
|
112
112
|
|