eslint-plugin-jest 28.8.2 → 28.9.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 +34 -28
- package/index.d.ts +28 -0
- package/lib/rules/prefer-importing-jest-globals.js +1 -1
- package/package.json +6 -4
package/README.md
CHANGED
|
@@ -22,28 +22,43 @@ yarn add --dev eslint eslint-plugin-jest
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
>
|
|
27
|
-
> `eslint.config.js` is supported, though most of the plugin documentation still
|
|
28
|
-
> currently uses `.eslintrc` syntax.
|
|
29
|
-
>
|
|
30
|
-
> Refer to the
|
|
31
|
-
> [ESLint documentation on the new configuration file format](https://eslint.org/docs/latest/use/configure/configuration-files-new)
|
|
32
|
-
> for more.
|
|
25
|
+
If you're using flat configuration:
|
|
33
26
|
|
|
34
|
-
|
|
35
|
-
|
|
27
|
+
With
|
|
28
|
+
[flat configuration](https://eslint.org/docs/latest/use/configure/configuration-files),
|
|
29
|
+
just import the plugin and away you go:
|
|
36
30
|
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
31
|
+
```js
|
|
32
|
+
const pluginJest = require('eslint-plugin-jest');
|
|
33
|
+
|
|
34
|
+
module.exports = [
|
|
35
|
+
{
|
|
36
|
+
// update this to match your test files
|
|
37
|
+
files: ['**/*.spec.js', '**/*.test.js'],
|
|
38
|
+
plugins: { jest: pluginJest },
|
|
39
|
+
languageOptions: {
|
|
40
|
+
globals: pluginJest.environments.globals.globals,
|
|
41
|
+
},
|
|
42
|
+
rules: {
|
|
43
|
+
'jest/no-disabled-tests': 'warn',
|
|
44
|
+
'jest/no-focused-tests': 'error',
|
|
45
|
+
'jest/no-identical-title': 'error',
|
|
46
|
+
'jest/prefer-to-have-length': 'warn',
|
|
47
|
+
'jest/valid-expect': 'error',
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
];
|
|
41
51
|
```
|
|
42
52
|
|
|
43
|
-
|
|
53
|
+
With legacy configuration, add `jest` to the plugins section of your `.eslintrc`
|
|
54
|
+
configuration file. You can omit the `eslint-plugin-` prefix:
|
|
44
55
|
|
|
45
56
|
```json
|
|
46
57
|
{
|
|
58
|
+
"plugins": ["jest"],
|
|
59
|
+
"env": {
|
|
60
|
+
"jest/globals": true
|
|
61
|
+
},
|
|
47
62
|
"rules": {
|
|
48
63
|
"jest/no-disabled-tests": "warn",
|
|
49
64
|
"jest/no-focused-tests": "error",
|
|
@@ -54,19 +69,10 @@ Then configure the rules you want to use under the rules section.
|
|
|
54
69
|
}
|
|
55
70
|
```
|
|
56
71
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
{
|
|
62
|
-
"env": {
|
|
63
|
-
"jest/globals": true
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
This is included in all configs shared by this plugin, so can be omitted if
|
|
69
|
-
extending them.
|
|
72
|
+
> [!NOTE]
|
|
73
|
+
>
|
|
74
|
+
> You only need to explicitly include our globals if you're not using one of our
|
|
75
|
+
> shared configs
|
|
70
76
|
|
|
71
77
|
#### Aliased Jest globals
|
|
72
78
|
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Linter, Rule } from 'eslint';
|
|
2
|
+
|
|
3
|
+
declare const plugin: {
|
|
4
|
+
meta: {
|
|
5
|
+
name: string;
|
|
6
|
+
version: string;
|
|
7
|
+
};
|
|
8
|
+
environments: {
|
|
9
|
+
globals: {
|
|
10
|
+
globals: {
|
|
11
|
+
[key: string]: boolean;
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
configs: {
|
|
16
|
+
all: Linter.LegacyConfig;
|
|
17
|
+
recommended: Linter.LegacyConfig;
|
|
18
|
+
style: Linter.LegacyConfig;
|
|
19
|
+
'flat/all': Linter.FlatConfig;
|
|
20
|
+
'flat/recommended': Linter.FlatConfig;
|
|
21
|
+
'flat/style': Linter.FlatConfig;
|
|
22
|
+
};
|
|
23
|
+
rules: {
|
|
24
|
+
[key: string]: Rule.RuleModule;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
export = plugin;
|
|
@@ -90,7 +90,7 @@ var _default = exports.default = (0, _utils2.createRule)({
|
|
|
90
90
|
}
|
|
91
91
|
const requireNode = sourceCode.ast.body.find(node => node.type === _utils.AST_NODE_TYPES.VariableDeclaration && node.declarations.some(declaration => declaration.init?.type === _utils.AST_NODE_TYPES.CallExpression && (0, _utils2.isIdentifier)(declaration.init.callee, 'require') && (0, _utils2.isStringNode)(declaration.init.arguments[0], '@jest/globals') && (declaration.id.type === _utils.AST_NODE_TYPES.Identifier || declaration.id.type === _utils.AST_NODE_TYPES.ObjectPattern)));
|
|
92
92
|
if (requireNode?.type !== _utils.AST_NODE_TYPES.VariableDeclaration) {
|
|
93
|
-
return fixer.insertTextBefore(
|
|
93
|
+
return fixer.insertTextBefore(firstNode, `${createFixerImports(isModule, functionsToImport)}\n`);
|
|
94
94
|
}
|
|
95
95
|
if (requireNode.declarations[0]?.id.type === _utils.AST_NODE_TYPES.ObjectPattern) {
|
|
96
96
|
for (const property of requireNode.declarations[0].id.properties) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-jest",
|
|
3
|
-
"version": "28.
|
|
3
|
+
"version": "28.9.0",
|
|
4
4
|
"description": "ESLint rules for Jest",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -15,9 +15,11 @@
|
|
|
15
15
|
"url": "jkimbo.com"
|
|
16
16
|
},
|
|
17
17
|
"main": "lib/index.js",
|
|
18
|
+
"types": "index.d.ts",
|
|
18
19
|
"files": [
|
|
19
20
|
"docs/",
|
|
20
|
-
"lib/"
|
|
21
|
+
"lib/",
|
|
22
|
+
"index.d.ts"
|
|
21
23
|
],
|
|
22
24
|
"scripts": {
|
|
23
25
|
"build": "babel --extensions .js,.ts src --out-dir lib --copy-files && rimraf --glob lib/__tests__ 'lib/**/__tests__'",
|
|
@@ -74,7 +76,7 @@
|
|
|
74
76
|
"@tsconfig/node16": "^16.0.0",
|
|
75
77
|
"@types/eslint": "^8.4.6",
|
|
76
78
|
"@types/jest": "^29.0.0",
|
|
77
|
-
"@types/node": "^
|
|
79
|
+
"@types/node": "^16.0.0",
|
|
78
80
|
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
79
81
|
"@typescript-eslint/parser": "^6.0.0",
|
|
80
82
|
"@typescript-eslint/utils": "^6.0.0",
|
|
@@ -118,7 +120,7 @@
|
|
|
118
120
|
"optional": true
|
|
119
121
|
}
|
|
120
122
|
},
|
|
121
|
-
"packageManager": "yarn@3.8.
|
|
123
|
+
"packageManager": "yarn@3.8.6",
|
|
122
124
|
"engines": {
|
|
123
125
|
"node": "^16.10.0 || ^18.12.0 || >=20.0.0"
|
|
124
126
|
},
|