eslint-plugin-jest
Advanced tools
Comparing version 28.2.0 to 28.3.0
@@ -45,4 +45,40 @@ # Prefer importing Jest globals (`prefer-importing-jest-globals`) | ||
## Options | ||
This rule can be configured as follows | ||
```json | ||
{ | ||
"type": "object", | ||
"properties": { | ||
"types": { | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
"enum": ["hook", "describe", "test", "expect", "jest", "unknown"] | ||
} | ||
} | ||
}, | ||
"additionalProperties": false | ||
} | ||
``` | ||
#### types | ||
A list of Jest global types to enforce explicit imports for. By default, all | ||
Jest globals are enforced. | ||
This option is useful when you only want to enforce explicit imports for a | ||
subset of Jest globals. For instance, when migrating to ESM, you might want to | ||
enforce explicit imports only for the `jest` global, as of | ||
[Jest's ESM documentation](https://jestjs.io/docs/ecmascript-modules#differences-between-esm-and-commonjs). | ||
```json5 | ||
{ | ||
'jest/prefer-importing-jest-globals': ['error', { types: ['jest'] }], | ||
} | ||
``` | ||
## Further Reading | ||
- [Documentation](https://jestjs.io/docs/api) |
@@ -43,5 +43,5 @@ "use strict"; | ||
type: 'array', | ||
items: [{ | ||
items: { | ||
type: 'string' | ||
}] | ||
} | ||
}, | ||
@@ -48,0 +48,0 @@ additionalTestBlockFunctions: { |
@@ -13,2 +13,3 @@ "use strict"; | ||
}; | ||
const allJestFnTypes = ['hook', 'describe', 'test', 'expect', 'jest', 'unknown']; | ||
var _default = exports.default = (0, _utils2.createRule)({ | ||
@@ -25,6 +26,23 @@ name: __filename, | ||
type: 'problem', | ||
schema: [] | ||
schema: [{ | ||
type: 'object', | ||
properties: { | ||
types: { | ||
type: 'array', | ||
items: { | ||
type: 'string', | ||
enum: allJestFnTypes | ||
} | ||
} | ||
}, | ||
additionalProperties: false | ||
}] | ||
}, | ||
defaultOptions: [], | ||
defaultOptions: [{ | ||
types: allJestFnTypes | ||
}], | ||
create(context) { | ||
const { | ||
types = allJestFnTypes | ||
} = context.options[0] || {}; | ||
const importedFunctionsWithSource = {}; | ||
@@ -46,3 +64,3 @@ const functionsToImport = new Set(); | ||
} | ||
if (jestFnCall.head.type !== 'import') { | ||
if (jestFnCall.head.type !== 'import' && types.includes(jestFnCall.type)) { | ||
functionsToImport.add(jestFnCall.name); | ||
@@ -49,0 +67,0 @@ reportingNode ||= jestFnCall.head.node; |
{ | ||
"name": "eslint-plugin-jest", | ||
"version": "28.2.0", | ||
"version": "28.3.0", | ||
"description": "ESLint rules for Jest", | ||
@@ -32,3 +32,3 @@ "keywords": [ | ||
"test": "jest", | ||
"tools:regenerate-docs": "yarn prepack && eslint-doc-generator", | ||
"regenerate-docs": "yarn prepack && eslint-doc-generator", | ||
"typecheck": "tsc -p ." | ||
@@ -90,9 +90,9 @@ }, | ||
"dedent": "^1.5.0", | ||
"eslint": "^7.0.0 || ^8.0.0 || ^9.0.0", | ||
"eslint": "^7.0.0 || ^8.0.0", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-doc-generator": "^1.0.0", | ||
"eslint-plugin-eslint-comments": "^3.1.2", | ||
"eslint-plugin-eslint-plugin": "^5.0.6", | ||
"eslint-plugin-eslint-plugin": "^6.0.0", | ||
"eslint-plugin-import": "^2.25.1", | ||
"eslint-plugin-n": "^15.0.0", | ||
"eslint-plugin-n": "^17.0.0", | ||
"eslint-plugin-prettier": "^5.0.0", | ||
@@ -99,0 +99,0 @@ "eslint-remote-tester": "^3.0.0", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
315446
5325