eslint-plugin-jest 27.1.2 → 27.1.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 +8 -16
- package/lib/processors/snapshot-processor.js +3 -5
- package/lib/rules/consistent-test-it.js +0 -18
- package/lib/rules/expect-expect.js +0 -15
- package/lib/rules/max-expects.js +0 -16
- package/lib/rules/max-nested-describe.js +0 -13
- package/lib/rules/no-alias-methods.js +0 -9
- package/lib/rules/no-commented-out-tests.js +0 -10
- package/lib/rules/no-conditional-expect.js +0 -19
- package/lib/rules/no-conditional-in-test.js +0 -9
- package/lib/rules/no-deprecated-functions.js +2 -18
- package/lib/rules/no-disabled-tests.js +2 -18
- package/lib/rules/no-done-callback.js +1 -30
- package/lib/rules/no-duplicate-hooks.js +0 -12
- package/lib/rules/no-export.js +0 -12
- package/lib/rules/no-focused-tests.js +0 -15
- package/lib/rules/no-hooks.js +0 -7
- package/lib/rules/no-identical-title.js +0 -19
- package/lib/rules/no-if.js +0 -24
- package/lib/rules/no-interpolation-in-snapshots.js +0 -9
- package/lib/rules/no-jasmine-globals.js +0 -22
- package/lib/rules/no-large-snapshots.js +2 -20
- package/lib/rules/no-mocks-import.js +0 -12
- package/lib/rules/no-restricted-jest-methods.js +1 -11
- package/lib/rules/no-restricted-matchers.js +0 -11
- package/lib/rules/no-standalone-expect.js +7 -33
- package/lib/rules/no-test-prefixes.js +0 -12
- package/lib/rules/no-test-return-statement.js +0 -12
- package/lib/rules/prefer-called-with.js +0 -10
- package/lib/rules/prefer-comparison-matcher.js +8 -33
- package/lib/rules/prefer-each.js +0 -18
- package/lib/rules/prefer-equality-matcher.js +11 -23
- package/lib/rules/prefer-expect-assertions.js +4 -51
- package/lib/rules/prefer-expect-resolves.js +0 -12
- package/lib/rules/prefer-hooks-in-order.js +2 -16
- package/lib/rules/prefer-hooks-on-top.js +0 -9
- package/lib/rules/prefer-lowercase-title.js +0 -23
- package/lib/rules/prefer-mock-promise-shorthand.js +5 -26
- package/lib/rules/prefer-snapshot-hint.js +7 -31
- package/lib/rules/prefer-spy-on.js +0 -17
- package/lib/rules/prefer-strict-equal.js +0 -9
- package/lib/rules/prefer-to-be.js +1 -30
- package/lib/rules/prefer-to-contain.js +11 -21
- package/lib/rules/prefer-to-have-length.js +4 -16
- package/lib/rules/prefer-todo.js +2 -18
- package/lib/rules/require-hook.js +0 -22
- package/lib/rules/require-to-throw-message.js +0 -9
- package/lib/rules/require-top-level-describe.js +0 -15
- package/lib/rules/unbound-method.js +2 -21
- package/lib/rules/utils/accessors.js +6 -18
- package/lib/rules/utils/detectJestVersion.js +2 -7
- package/lib/rules/utils/followTypeAssertionChain.js +0 -4
- package/lib/rules/utils/index.js +0 -10
- package/lib/rules/utils/misc.js +2 -46
- package/lib/rules/utils/parseJestFnCall.js +39 -114
- package/lib/rules/valid-describe-callback.js +0 -17
- package/lib/rules/valid-expect-in-promise.js +26 -93
- package/lib/rules/valid-expect.js +5 -48
- package/lib/rules/valid-title.js +0 -33
- package/package.json +1 -1
package/lib/rules/valid-title.js
CHANGED
|
@@ -4,32 +4,23 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
|
-
|
|
8
7
|
var _utils = require("@typescript-eslint/utils");
|
|
9
|
-
|
|
10
8
|
var _utils2 = require("./utils");
|
|
11
|
-
|
|
12
9
|
const trimFXprefix = word => ['f', 'x'].includes(word.charAt(0)) ? word.substr(1) : word;
|
|
13
|
-
|
|
14
10
|
const doesBinaryExpressionContainStringNode = binaryExp => {
|
|
15
11
|
if ((0, _utils2.isStringNode)(binaryExp.right)) {
|
|
16
12
|
return true;
|
|
17
13
|
}
|
|
18
|
-
|
|
19
14
|
if (binaryExp.left.type === _utils.AST_NODE_TYPES.BinaryExpression) {
|
|
20
15
|
return doesBinaryExpressionContainStringNode(binaryExp.left);
|
|
21
16
|
}
|
|
22
|
-
|
|
23
17
|
return (0, _utils2.isStringNode)(binaryExp.left);
|
|
24
18
|
};
|
|
25
|
-
|
|
26
19
|
const quoteStringValue = node => node.type === _utils.AST_NODE_TYPES.TemplateLiteral ? `\`${node.quasis[0].value.raw}\`` : node.raw;
|
|
27
|
-
|
|
28
20
|
const compileMatcherPattern = matcherMaybeWithMessage => {
|
|
29
21
|
const [matcher, message] = Array.isArray(matcherMaybeWithMessage) ? matcherMaybeWithMessage : [matcherMaybeWithMessage];
|
|
30
22
|
return [new RegExp(matcher, 'u'), message];
|
|
31
23
|
};
|
|
32
|
-
|
|
33
24
|
const compileMatcherPatterns = matchers => {
|
|
34
25
|
if (typeof matchers === 'string' || Array.isArray(matchers)) {
|
|
35
26
|
const compiledMatcher = compileMatcherPattern(matchers);
|
|
@@ -39,14 +30,12 @@ const compileMatcherPatterns = matchers => {
|
|
|
39
30
|
it: compiledMatcher
|
|
40
31
|
};
|
|
41
32
|
}
|
|
42
|
-
|
|
43
33
|
return {
|
|
44
34
|
describe: matchers.describe ? compileMatcherPattern(matchers.describe) : null,
|
|
45
35
|
test: matchers.test ? compileMatcherPattern(matchers.test) : null,
|
|
46
36
|
it: matchers.it ? compileMatcherPattern(matchers.it) : null
|
|
47
37
|
};
|
|
48
38
|
};
|
|
49
|
-
|
|
50
39
|
const MatcherAndMessageSchema = {
|
|
51
40
|
type: 'array',
|
|
52
41
|
items: {
|
|
@@ -56,7 +45,6 @@ const MatcherAndMessageSchema = {
|
|
|
56
45
|
maxItems: 2,
|
|
57
46
|
additionalItems: false
|
|
58
47
|
};
|
|
59
|
-
|
|
60
48
|
var _default = (0, _utils2.createRule)({
|
|
61
49
|
name: __filename,
|
|
62
50
|
meta: {
|
|
@@ -116,7 +104,6 @@ var _default = (0, _utils2.createRule)({
|
|
|
116
104
|
ignoreTypeOfDescribeName: false,
|
|
117
105
|
disallowedWords: []
|
|
118
106
|
}],
|
|
119
|
-
|
|
120
107
|
create(context, [{
|
|
121
108
|
ignoreTypeOfDescribeName,
|
|
122
109
|
disallowedWords = [],
|
|
@@ -129,34 +116,26 @@ var _default = (0, _utils2.createRule)({
|
|
|
129
116
|
return {
|
|
130
117
|
CallExpression(node) {
|
|
131
118
|
const jestFnCall = (0, _utils2.parseJestFnCall)(node, context);
|
|
132
|
-
|
|
133
119
|
if ((jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'describe' && (jestFnCall === null || jestFnCall === void 0 ? void 0 : jestFnCall.type) !== 'test') {
|
|
134
120
|
return;
|
|
135
121
|
}
|
|
136
|
-
|
|
137
122
|
const [argument] = node.arguments;
|
|
138
|
-
|
|
139
123
|
if (!argument) {
|
|
140
124
|
return;
|
|
141
125
|
}
|
|
142
|
-
|
|
143
126
|
if (!(0, _utils2.isStringNode)(argument)) {
|
|
144
127
|
if (argument.type === _utils.AST_NODE_TYPES.BinaryExpression && doesBinaryExpressionContainStringNode(argument)) {
|
|
145
128
|
return;
|
|
146
129
|
}
|
|
147
|
-
|
|
148
130
|
if (argument.type !== _utils.AST_NODE_TYPES.TemplateLiteral && !(ignoreTypeOfDescribeName && jestFnCall.type === 'describe')) {
|
|
149
131
|
context.report({
|
|
150
132
|
messageId: 'titleMustBeString',
|
|
151
133
|
loc: argument.loc
|
|
152
134
|
});
|
|
153
135
|
}
|
|
154
|
-
|
|
155
136
|
return;
|
|
156
137
|
}
|
|
157
|
-
|
|
158
138
|
const title = (0, _utils2.getStringValue)(argument);
|
|
159
|
-
|
|
160
139
|
if (!title) {
|
|
161
140
|
context.report({
|
|
162
141
|
messageId: 'emptyTitle',
|
|
@@ -167,10 +146,8 @@ var _default = (0, _utils2.createRule)({
|
|
|
167
146
|
});
|
|
168
147
|
return;
|
|
169
148
|
}
|
|
170
|
-
|
|
171
149
|
if (disallowedWords.length > 0) {
|
|
172
150
|
const disallowedMatch = disallowedWordsRegexp.exec(title);
|
|
173
|
-
|
|
174
151
|
if (disallowedMatch) {
|
|
175
152
|
context.report({
|
|
176
153
|
data: {
|
|
@@ -182,7 +159,6 @@ var _default = (0, _utils2.createRule)({
|
|
|
182
159
|
return;
|
|
183
160
|
}
|
|
184
161
|
}
|
|
185
|
-
|
|
186
162
|
if (title.trim().length !== title.length) {
|
|
187
163
|
context.report({
|
|
188
164
|
messageId: 'accidentalSpace',
|
|
@@ -190,10 +166,8 @@ var _default = (0, _utils2.createRule)({
|
|
|
190
166
|
fix: fixer => [fixer.replaceTextRange(argument.range, quoteStringValue(argument).replace(/^([`'"]) +?/u, '$1').replace(/ +?([`'"])$/u, '$1'))]
|
|
191
167
|
});
|
|
192
168
|
}
|
|
193
|
-
|
|
194
169
|
const unprefixedName = trimFXprefix(jestFnCall.name);
|
|
195
170
|
const [firstWord] = title.split(' ');
|
|
196
|
-
|
|
197
171
|
if (firstWord.toLowerCase() === unprefixedName) {
|
|
198
172
|
context.report({
|
|
199
173
|
messageId: 'duplicatePrefix',
|
|
@@ -201,10 +175,8 @@ var _default = (0, _utils2.createRule)({
|
|
|
201
175
|
fix: fixer => [fixer.replaceTextRange(argument.range, quoteStringValue(argument).replace(/^([`'"]).+? /u, '$1'))]
|
|
202
176
|
});
|
|
203
177
|
}
|
|
204
|
-
|
|
205
178
|
const jestFunctionName = unprefixedName;
|
|
206
179
|
const [mustNotMatchPattern, mustNotMatchMessage] = mustNotMatchPatterns[jestFunctionName] ?? [];
|
|
207
|
-
|
|
208
180
|
if (mustNotMatchPattern) {
|
|
209
181
|
if (mustNotMatchPattern.test(title)) {
|
|
210
182
|
context.report({
|
|
@@ -219,9 +191,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
219
191
|
return;
|
|
220
192
|
}
|
|
221
193
|
}
|
|
222
|
-
|
|
223
194
|
const [mustMatchPattern, mustMatchMessage] = mustMatchPatterns[jestFunctionName] ?? [];
|
|
224
|
-
|
|
225
195
|
if (mustMatchPattern) {
|
|
226
196
|
if (!mustMatchPattern.test(title)) {
|
|
227
197
|
context.report({
|
|
@@ -237,10 +207,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
237
207
|
}
|
|
238
208
|
}
|
|
239
209
|
}
|
|
240
|
-
|
|
241
210
|
};
|
|
242
211
|
}
|
|
243
|
-
|
|
244
212
|
});
|
|
245
|
-
|
|
246
213
|
exports.default = _default;
|