eslint-plugin-jest
Advanced tools
Comparing version 27.1.6 to 27.1.7
# Disallow conditional logic (`no-if`) | ||
β This rule is deprecated. It was replaced by | ||
[`no-conditional-in-test`](no-conditional-in-test.md). | ||
[`jest/no-conditional-in-test`](../../docs/rules/no-conditional-in-test.md). | ||
@@ -6,0 +6,0 @@ <!-- end auto-generated rule header --> |
@@ -31,2 +31,12 @@ "use strict"; | ||
}; | ||
const getAutoFixMockImplementation = (jestFnCall, context) => { | ||
var _jestFnCall$parent; | ||
const hasMockImplementationAlready = ((_jestFnCall$parent = jestFnCall.parent) === null || _jestFnCall$parent === void 0 ? void 0 : _jestFnCall$parent.type) === _utils.AST_NODE_TYPES.MemberExpression && jestFnCall.parent.property.type === _utils.AST_NODE_TYPES.Identifier && jestFnCall.parent.property.name === 'mockImplementation'; | ||
if (hasMockImplementationAlready) { | ||
return ''; | ||
} | ||
const [arg] = jestFnCall.arguments; | ||
const argSource = arg && context.getSourceCode().getText(arg); | ||
return argSource ? `.mockImplementation(${argSource})` : '.mockImplementation()'; | ||
}; | ||
var _default = (0, _utils2.createRule)({ | ||
@@ -62,6 +72,4 @@ name: __filename, | ||
fix(fixer) { | ||
const leftPropQuote = left.property.type === _utils.AST_NODE_TYPES.Identifier ? "'" : ''; | ||
const [arg] = jestFnCall.arguments; | ||
const argSource = arg && context.getSourceCode().getText(arg); | ||
const mockImplementation = argSource ? `.mockImplementation(${argSource})` : '.mockImplementation()'; | ||
const leftPropQuote = left.property.type === _utils.AST_NODE_TYPES.Identifier && !left.computed ? "'" : ''; | ||
const mockImplementation = getAutoFixMockImplementation(jestFnCall, context); | ||
return [fixer.insertTextBefore(left, `jest.spyOn(`), fixer.replaceTextRange([left.object.range[1], left.property.range[0]], `, ${leftPropQuote}`), fixer.replaceTextRange([left.property.range[1], jestFnCall.range[1]], `${leftPropQuote})${mockImplementation}`)]; | ||
@@ -68,0 +76,0 @@ } |
{ | ||
"name": "eslint-plugin-jest", | ||
"version": "27.1.6", | ||
"version": "27.1.7", | ||
"description": "ESLint rules for Jest", | ||
@@ -32,3 +32,3 @@ "keywords": [ | ||
"test": "jest", | ||
"tools:regenerate-docs": "yarn prepack && eslint-doc-generator && yarn prettier:write", | ||
"tools:regenerate-docs": "yarn prepack && eslint-doc-generator", | ||
"typecheck": "tsc -p ." | ||
@@ -125,3 +125,3 @@ }, | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-doc-generator": "^0.26.0", | ||
"eslint-doc-generator": "^1.0.0", | ||
"eslint-plugin-eslint-comments": "^3.1.2", | ||
@@ -128,0 +128,0 @@ "eslint-plugin-eslint-plugin": "^5.0.6", |
@@ -276,3 +276,3 @@ <div align="center"> | ||
`@typescript-eslint/parser` & adjust your eslint config as outlined | ||
[here](https://github.com/typescript-eslint/typescript-eslint/blob/main/docs/linting/TYPED_LINTING.md). | ||
[here](https://typescript-eslint.io/docs/linting/typed-linting). | ||
@@ -279,0 +279,0 @@ Note that unlike the type-checking rules in `@typescript-eslint/eslint-plugin`, |
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
311567
5282