eslint-plugin-jest-dom
Advanced tools
Comparing version 3.1.1 to 3.1.2
@@ -13,3 +13,3 @@ "use strict"; | ||
}) => context => { | ||
const getCorrectFunctionFor = (node, negated = false) => (node.arguments.length === 1 || node.arguments[1].value === true || typeof node.arguments[1].value === "string" && node.arguments[1].value.toLowerCase() === "true" || node.arguments[1].value === "") && !negated ? preferred : negatedPreferred; | ||
const getCorrectFunctionFor = (node, negated = false) => (node.arguments.length === 1 || node.arguments[1].value === true || node.arguments[1].type !== "Literal" || typeof node.arguments[1].value === "string" && node.arguments[1].value.toLowerCase() === "true" || node.arguments[1].value === "") && !negated ? preferred : negatedPreferred; | ||
@@ -33,3 +33,3 @@ const isBannedArg = node => attributes.some(attr => attr === node.arguments[0].value); | ||
[`CallExpression[callee.property.name=/toBe(Truthy|Falsy)?|toEqual/][callee.object.callee.name='expect']`](node) { | ||
"CallExpression[callee.property.name=/toBe(Truthy|Falsy)?|toEqual/][callee.object.callee.name='expect']"(node) { | ||
const { | ||
@@ -59,3 +59,3 @@ arguments: [{ | ||
[`CallExpression[callee.property.name=/toHaveProperty|toHaveAttribute/][callee.object.property.name='not'][callee.object.object.callee.name='expect']`](node) { | ||
"CallExpression[callee.property.name=/toHaveProperty|toHaveAttribute/][callee.object.property.name='not'][callee.object.object.callee.name='expect']"(node) { | ||
const arg = node.arguments[0].value; | ||
@@ -76,3 +76,3 @@ | ||
[`CallExpression[callee.object.callee.name='expect'][callee.property.name=/toHaveProperty|toHaveAttribute/]`](node) { | ||
"CallExpression[callee.object.callee.name='expect'][callee.property.name=/toHaveProperty|toHaveAttribute/]"(node) { | ||
if (!isBannedArg(node)) { | ||
@@ -85,8 +85,16 @@ return; | ||
const message = `Use ${correctFunction}() instead of ${incorrectFunction}(${node.arguments.map(({ | ||
raw | ||
}) => raw).join(", ")})`; | ||
raw, | ||
name | ||
}) => raw || name).join(", ")})`; | ||
const secondArgIsLiteral = node.arguments.length === 2 && node.arguments[1].type === "Literal"; | ||
context.report({ | ||
node: node.callee.property, | ||
message, | ||
fix: fixer => [fixer.replaceTextRange([node.callee.property.range[0], node.range[1]], `${correctFunction}()`)] | ||
fix: fixer => { | ||
if (node.arguments.length === 1 || secondArgIsLiteral) { | ||
return [fixer.replaceTextRange([node.callee.property.range[0], node.range[1]], `${correctFunction}()`)]; | ||
} | ||
return null; | ||
} | ||
}); | ||
@@ -93,0 +101,0 @@ } |
{ | ||
"name": "eslint-plugin-jest-dom", | ||
"version": "3.1.1", | ||
"version": "3.1.2", | ||
"description": "ESLint plugin to follow best practices and anticipate common mistakes when writing tests with jest-dom", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
@@ -154,2 +154,3 @@ <div align="center"> | ||
<!-- prettier-ignore-end --> | ||
<!-- ALL-CONTRIBUTORS-LIST:END --> | ||
@@ -156,0 +157,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
36684
489
187