eslint-plugin-jest 27.1.3 → 27.1.5
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 +81 -80
- package/docs/rules/consistent-test-it.md +4 -11
- package/docs/rules/expect-expect.md +3 -4
- package/docs/rules/max-expects.md +1 -5
- package/docs/rules/max-nested-describe.md +1 -5
- package/docs/rules/no-alias-methods.md +8 -10
- package/docs/rules/no-commented-out-tests.md +3 -4
- package/docs/rules/no-conditional-expect.md +4 -5
- package/docs/rules/no-conditional-in-test.md +1 -5
- package/docs/rules/no-deprecated-functions.md +5 -7
- package/docs/rules/no-disabled-tests.md +3 -4
- package/docs/rules/no-done-callback.md +6 -8
- package/docs/rules/no-duplicate-hooks.md +1 -5
- package/docs/rules/no-export.md +3 -4
- package/docs/rules/no-focused-tests.md +5 -7
- package/docs/rules/no-hooks.md +1 -5
- package/docs/rules/no-identical-title.md +3 -4
- package/docs/rules/no-if.md +2 -2
- package/docs/rules/no-interpolation-in-snapshots.md +3 -4
- package/docs/rules/no-jasmine-globals.md +6 -8
- package/docs/rules/no-large-snapshots.md +2 -6
- package/docs/rules/no-mocks-import.md +3 -4
- package/docs/rules/no-restricted-jest-methods.md +1 -5
- package/docs/rules/no-restricted-matchers.md +1 -5
- package/docs/rules/no-standalone-expect.md +3 -4
- package/docs/rules/no-test-prefixes.md +6 -8
- package/docs/rules/no-test-return-statement.md +1 -5
- package/docs/rules/prefer-called-with.md +1 -5
- package/docs/rules/prefer-comparison-matcher.md +3 -8
- package/docs/rules/prefer-each.md +1 -5
- package/docs/rules/prefer-equality-matcher.md +3 -8
- package/docs/rules/prefer-expect-assertions.md +3 -10
- package/docs/rules/prefer-expect-resolves.md +3 -8
- package/docs/rules/prefer-hooks-in-order.md +1 -5
- package/docs/rules/prefer-hooks-on-top.md +1 -5
- package/docs/rules/prefer-lowercase-title.md +3 -8
- package/docs/rules/prefer-mock-promise-shorthand.md +3 -8
- package/docs/rules/prefer-snapshot-hint.md +1 -5
- package/docs/rules/prefer-spy-on.md +3 -10
- package/docs/rules/prefer-strict-equal.md +3 -10
- package/docs/rules/prefer-to-be.md +5 -7
- package/docs/rules/prefer-to-contain.md +5 -9
- package/docs/rules/prefer-to-have-length.md +5 -9
- package/docs/rules/prefer-todo.md +3 -10
- package/docs/rules/require-hook.md +1 -5
- package/docs/rules/require-to-throw-message.md +1 -7
- package/docs/rules/require-top-level-describe.md +1 -5
- package/docs/rules/unbound-method.md +2 -4
- package/docs/rules/valid-describe-callback.md +3 -4
- package/docs/rules/valid-expect-in-promise.md +4 -5
- package/docs/rules/valid-expect.md +3 -6
- package/docs/rules/valid-title.md +5 -7
- package/lib/rules/consistent-test-it.js +1 -1
- package/lib/rules/no-conditional-expect.js +1 -1
- package/lib/rules/no-disabled-tests.js +1 -1
- package/lib/rules/no-done-callback.js +1 -1
- package/lib/rules/no-jasmine-globals.js +1 -1
- package/lib/rules/no-large-snapshots.js +1 -1
- package/lib/rules/no-test-prefixes.js +1 -1
- package/lib/rules/utils/parseJestFnCall.js +17 -43
- package/lib/rules/valid-expect-in-promise.js +1 -1
- package/lib/rules/valid-title.js +1 -1
- package/package.json +3 -2
|
@@ -11,7 +11,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
11
11
|
meta: {
|
|
12
12
|
docs: {
|
|
13
13
|
category: 'Best Practices',
|
|
14
|
-
description: '
|
|
14
|
+
description: 'Require using `.only` and `.skip` over `f` and `x`',
|
|
15
15
|
recommended: 'error'
|
|
16
16
|
},
|
|
17
17
|
messages: {
|
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.getNodeChain = getNodeChain;
|
|
7
|
-
exports.
|
|
7
|
+
exports.resolveScope = exports.parseJestFnCallWithReason = exports.parseJestFnCall = exports.isTypeOfJestFnCall = void 0;
|
|
8
8
|
var _utils = require("@typescript-eslint/utils");
|
|
9
9
|
var _utils2 = require("../utils");
|
|
10
10
|
const isTypeOfJestFnCall = (node, context, types) => {
|
|
@@ -286,38 +286,31 @@ const describePossibleImportDef = def => {
|
|
|
286
286
|
}
|
|
287
287
|
return null;
|
|
288
288
|
};
|
|
289
|
-
const
|
|
290
|
-
const locals = new Set();
|
|
291
|
-
const imports = new Map();
|
|
292
|
-
const unresolved = new Set();
|
|
289
|
+
const resolveScope = (scope, identifier) => {
|
|
293
290
|
let currentScope = scope;
|
|
294
291
|
while (currentScope !== null) {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
continue;
|
|
298
|
-
}
|
|
292
|
+
const ref = currentScope.set.get(identifier);
|
|
293
|
+
if (ref && ref.defs.length > 0) {
|
|
299
294
|
const def = ref.defs[ref.defs.length - 1];
|
|
300
295
|
const importDetails = describePossibleImportDef(def);
|
|
301
|
-
if (importDetails) {
|
|
302
|
-
|
|
303
|
-
continue;
|
|
296
|
+
if ((importDetails === null || importDetails === void 0 ? void 0 : importDetails.local) === identifier) {
|
|
297
|
+
return importDetails;
|
|
304
298
|
}
|
|
305
|
-
|
|
306
|
-
}
|
|
307
|
-
for (const ref of currentScope.through) {
|
|
308
|
-
unresolved.add(ref.identifier.name);
|
|
299
|
+
return 'local';
|
|
309
300
|
}
|
|
310
301
|
currentScope = currentScope.upper;
|
|
311
302
|
}
|
|
312
|
-
return
|
|
313
|
-
locals,
|
|
314
|
-
imports,
|
|
315
|
-
unresolved
|
|
316
|
-
};
|
|
303
|
+
return null;
|
|
317
304
|
};
|
|
305
|
+
exports.resolveScope = resolveScope;
|
|
318
306
|
const resolveToJestFn = (context, identifier) => {
|
|
319
|
-
const
|
|
320
|
-
|
|
307
|
+
const maybeImport = resolveScope(context.getScope(), identifier);
|
|
308
|
+
|
|
309
|
+
// the identifier was found as a local variable or function declaration
|
|
310
|
+
// meaning it's not a function from jest
|
|
311
|
+
if (maybeImport === 'local') {
|
|
312
|
+
return null;
|
|
313
|
+
}
|
|
321
314
|
if (maybeImport) {
|
|
322
315
|
// the identifier is imported from @jest/globals,
|
|
323
316
|
// so return the original import name
|
|
@@ -330,28 +323,9 @@ const resolveToJestFn = (context, identifier) => {
|
|
|
330
323
|
}
|
|
331
324
|
return null;
|
|
332
325
|
}
|
|
333
|
-
|
|
334
|
-
// the identifier was found as a local variable or function declaration
|
|
335
|
-
// meaning it's not a function from jest
|
|
336
|
-
if (references.locals.has(identifier)) {
|
|
337
|
-
return null;
|
|
338
|
-
}
|
|
339
326
|
return {
|
|
340
327
|
original: resolvePossibleAliasedGlobal(identifier, context),
|
|
341
328
|
local: identifier,
|
|
342
329
|
type: 'global'
|
|
343
330
|
};
|
|
344
|
-
};
|
|
345
|
-
const scopeHasLocalReference = (scope, referenceName) => {
|
|
346
|
-
const references = collectReferences(scope);
|
|
347
|
-
return (
|
|
348
|
-
// referenceName was found as a local variable or function declaration.
|
|
349
|
-
references.locals.has(referenceName) ||
|
|
350
|
-
// referenceName was found as an imported identifier
|
|
351
|
-
references.imports.has(referenceName) ||
|
|
352
|
-
// referenceName was not found as an unresolved reference,
|
|
353
|
-
// meaning it is likely not an implicit global reference.
|
|
354
|
-
!references.unresolved.has(referenceName)
|
|
355
|
-
);
|
|
356
|
-
};
|
|
357
|
-
exports.scopeHasLocalReference = scopeHasLocalReference;
|
|
331
|
+
};
|
|
@@ -208,7 +208,7 @@ var _default = (0, _utils2.createRule)({
|
|
|
208
208
|
meta: {
|
|
209
209
|
docs: {
|
|
210
210
|
category: 'Best Practices',
|
|
211
|
-
description: '
|
|
211
|
+
description: 'Require promises that have expectations in their chain to be valid',
|
|
212
212
|
recommended: 'error'
|
|
213
213
|
},
|
|
214
214
|
messages: {
|
package/lib/rules/valid-title.js
CHANGED
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _utils = require("@typescript-eslint/utils");
|
|
8
8
|
var _utils2 = require("./utils");
|
|
9
|
-
const trimFXprefix = word => ['f', 'x'].includes(word.charAt(0)) ? word.
|
|
9
|
+
const trimFXprefix = word => ['f', 'x'].includes(word.charAt(0)) ? word.substring(1) : word;
|
|
10
10
|
const doesBinaryExpressionContainStringNode = binaryExp => {
|
|
11
11
|
if ((0, _utils2.isStringNode)(binaryExp.right)) {
|
|
12
12
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "27.1.
|
|
3
|
+
"version": "27.1.5",
|
|
4
4
|
"description": "ESLint rules for Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
"prettier:write": "prettier --write 'docs/**/*.md' README.md '.github/**' package.json tsconfig.json src/globals.json .yarnrc.yml",
|
|
30
30
|
"postpublish": "pinst --enable",
|
|
31
31
|
"test": "jest",
|
|
32
|
-
"tools:regenerate-docs": "
|
|
32
|
+
"tools:regenerate-docs": "yarn prepack && eslint-doc-generator --ignore-config all --rule-doc-title-format desc-parens-name --rule-doc-section-include \"Rule details\" --rule-list-columns name,description,configsError,configsWarn,configsOff,fixable,hasSuggestions,deprecated --split-by meta.docs.requiresTypeChecking --url-configs \"https://github.com/jest-community/eslint-plugin-jest/blob/main/README.md#shareable-configurations\" && yarn prettier:write",
|
|
33
33
|
"typecheck": "tsc -p ."
|
|
34
34
|
},
|
|
35
35
|
"commitlint": {
|
|
@@ -121,6 +121,7 @@
|
|
|
121
121
|
"dedent": "^0.7.0",
|
|
122
122
|
"eslint": "^6.0.0 || ^7.0.0 || ^8.0.0",
|
|
123
123
|
"eslint-config-prettier": "^8.3.0",
|
|
124
|
+
"eslint-doc-generator": "^0.19.0",
|
|
124
125
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
125
126
|
"eslint-plugin-eslint-plugin": "^5.0.6",
|
|
126
127
|
"eslint-plugin-import": "^2.25.1",
|