eslint-plugin-jest 28.2.0 → 28.3.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.
|
@@ -42,6 +42,42 @@ describe('foo', () => {
|
|
|
42
42
|
});
|
|
43
43
|
```
|
|
44
44
|
|
|
45
|
+
## Options
|
|
46
|
+
|
|
47
|
+
This rule can be configured as follows
|
|
48
|
+
|
|
49
|
+
```json
|
|
50
|
+
{
|
|
51
|
+
"type": "object",
|
|
52
|
+
"properties": {
|
|
53
|
+
"types": {
|
|
54
|
+
"type": "array",
|
|
55
|
+
"items": {
|
|
56
|
+
"type": "string",
|
|
57
|
+
"enum": ["hook", "describe", "test", "expect", "jest", "unknown"]
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"additionalProperties": false
|
|
62
|
+
}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
#### types
|
|
66
|
+
|
|
67
|
+
A list of Jest global types to enforce explicit imports for. By default, all
|
|
68
|
+
Jest globals are enforced.
|
|
69
|
+
|
|
70
|
+
This option is useful when you only want to enforce explicit imports for a
|
|
71
|
+
subset of Jest globals. For instance, when migrating to ESM, you might want to
|
|
72
|
+
enforce explicit imports only for the `jest` global, as of
|
|
73
|
+
[Jest's ESM documentation](https://jestjs.io/docs/ecmascript-modules#differences-between-esm-and-commonjs).
|
|
74
|
+
|
|
75
|
+
```json5
|
|
76
|
+
{
|
|
77
|
+
'jest/prefer-importing-jest-globals': ['error', { types: ['jest'] }],
|
|
78
|
+
}
|
|
79
|
+
```
|
|
80
|
+
|
|
45
81
|
## Further Reading
|
|
46
82
|
|
|
47
83
|
- [Documentation](https://jestjs.io/docs/api)
|
|
@@ -10,6 +10,7 @@ const createFixerImports = (isModule, functionsToImport) => {
|
|
|
10
10
|
const allImportsFormatted = Array.from(functionsToImport).sort().join(', ');
|
|
11
11
|
return isModule ? `import { ${allImportsFormatted} } from '@jest/globals';` : `const { ${allImportsFormatted} } = require('@jest/globals');`;
|
|
12
12
|
};
|
|
13
|
+
const allJestFnTypes = ['hook', 'describe', 'test', 'expect', 'jest', 'unknown'];
|
|
13
14
|
var _default = exports.default = (0, _utils2.createRule)({
|
|
14
15
|
name: __filename,
|
|
15
16
|
meta: {
|
|
@@ -21,10 +22,27 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
21
22
|
},
|
|
22
23
|
fixable: 'code',
|
|
23
24
|
type: 'problem',
|
|
24
|
-
schema: [
|
|
25
|
+
schema: [{
|
|
26
|
+
type: 'object',
|
|
27
|
+
properties: {
|
|
28
|
+
types: {
|
|
29
|
+
type: 'array',
|
|
30
|
+
items: {
|
|
31
|
+
type: 'string',
|
|
32
|
+
enum: allJestFnTypes
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
},
|
|
36
|
+
additionalProperties: false
|
|
37
|
+
}]
|
|
25
38
|
},
|
|
26
|
-
defaultOptions: [
|
|
39
|
+
defaultOptions: [{
|
|
40
|
+
types: allJestFnTypes
|
|
41
|
+
}],
|
|
27
42
|
create(context) {
|
|
43
|
+
const {
|
|
44
|
+
types = allJestFnTypes
|
|
45
|
+
} = context.options[0] || {};
|
|
28
46
|
const importedFunctionsWithSource = {};
|
|
29
47
|
const functionsToImport = new Set();
|
|
30
48
|
let reportingNode;
|
|
@@ -41,7 +59,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
41
59
|
if (!jestFnCall) {
|
|
42
60
|
return;
|
|
43
61
|
}
|
|
44
|
-
if (jestFnCall.head.type !== 'import') {
|
|
62
|
+
if (jestFnCall.head.type !== 'import' && types.includes(jestFnCall.type)) {
|
|
45
63
|
functionsToImport.add(jestFnCall.name);
|
|
46
64
|
reportingNode ||= jestFnCall.head.node;
|
|
47
65
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "28.
|
|
3
|
+
"version": "28.3.0",
|
|
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
|
-
"
|
|
32
|
+
"regenerate-docs": "yarn prepack && eslint-doc-generator",
|
|
33
33
|
"typecheck": "tsc -p ."
|
|
34
34
|
},
|
|
35
35
|
"commitlint": {
|
|
@@ -86,13 +86,13 @@
|
|
|
86
86
|
"babel-jest": "^29.0.0",
|
|
87
87
|
"babel-plugin-replace-ts-export-assignment": "^0.0.2",
|
|
88
88
|
"dedent": "^1.5.0",
|
|
89
|
-
"eslint": "^7.0.0 || ^8.0.0
|
|
89
|
+
"eslint": "^7.0.0 || ^8.0.0",
|
|
90
90
|
"eslint-config-prettier": "^9.0.0",
|
|
91
91
|
"eslint-doc-generator": "^1.0.0",
|
|
92
92
|
"eslint-plugin-eslint-comments": "^3.1.2",
|
|
93
|
-
"eslint-plugin-eslint-plugin": "^
|
|
93
|
+
"eslint-plugin-eslint-plugin": "^6.0.0",
|
|
94
94
|
"eslint-plugin-import": "^2.25.1",
|
|
95
|
-
"eslint-plugin-n": "^
|
|
95
|
+
"eslint-plugin-n": "^17.0.0",
|
|
96
96
|
"eslint-plugin-prettier": "^5.0.0",
|
|
97
97
|
"eslint-remote-tester": "^3.0.0",
|
|
98
98
|
"eslint-remote-tester-repositories": "~1.0.0",
|