eslint-plugin-jest 27.1.3 → 27.1.4
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-done-callback.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 +27 -8
- package/lib/rules/valid-expect-in-promise.js +1 -1
- package/package.json +3 -2
|
@@ -315,9 +315,34 @@ const collectReferences = scope => {
|
|
|
315
315
|
unresolved
|
|
316
316
|
};
|
|
317
317
|
};
|
|
318
|
+
const resolveScope = (scope, identifier) => {
|
|
319
|
+
let currentScope = scope;
|
|
320
|
+
while (currentScope !== null) {
|
|
321
|
+
for (const ref of currentScope.variables) {
|
|
322
|
+
if (ref.defs.length === 0) {
|
|
323
|
+
continue;
|
|
324
|
+
}
|
|
325
|
+
const def = ref.defs[ref.defs.length - 1];
|
|
326
|
+
const importDetails = describePossibleImportDef(def);
|
|
327
|
+
if ((importDetails === null || importDetails === void 0 ? void 0 : importDetails.local) === identifier) {
|
|
328
|
+
return importDetails;
|
|
329
|
+
}
|
|
330
|
+
if (ref.name === identifier) {
|
|
331
|
+
return 'local';
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
currentScope = currentScope.upper;
|
|
335
|
+
}
|
|
336
|
+
return null;
|
|
337
|
+
};
|
|
318
338
|
const resolveToJestFn = (context, identifier) => {
|
|
319
|
-
const
|
|
320
|
-
|
|
339
|
+
const maybeImport = resolveScope(context.getScope(), identifier);
|
|
340
|
+
|
|
341
|
+
// the identifier was found as a local variable or function declaration
|
|
342
|
+
// meaning it's not a function from jest
|
|
343
|
+
if (maybeImport === 'local') {
|
|
344
|
+
return null;
|
|
345
|
+
}
|
|
321
346
|
if (maybeImport) {
|
|
322
347
|
// the identifier is imported from @jest/globals,
|
|
323
348
|
// so return the original import name
|
|
@@ -330,12 +355,6 @@ const resolveToJestFn = (context, identifier) => {
|
|
|
330
355
|
}
|
|
331
356
|
return null;
|
|
332
357
|
}
|
|
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
358
|
return {
|
|
340
359
|
original: resolvePossibleAliasedGlobal(identifier, context),
|
|
341
360
|
local: identifier,
|
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "27.1.
|
|
3
|
+
"version": "27.1.4",
|
|
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",
|