eslint-plugin-jest-dom
Advanced tools
Comparing version 3.2.1 to 3.2.2
@@ -24,97 +24,97 @@ "use strict"; | ||
const create = context => ({ | ||
[`BinaryExpression[left.property.name='innerHTML'][right.value=''][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](node) { | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.left.object.range[1], node.range[1]]), fixer.replaceText(node.parent.parent.property, Boolean(node.parent.parent.parent.arguments[0].value) === node.operator.startsWith("=") // binary expression XNOR matcher boolean | ||
? "toBeEmptyDOMElement" : "not.toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])] | ||
}); | ||
}, | ||
const create = context => { | ||
function isNonEmptyStringOrTemplateLiteral(node) { | ||
return !['""', "''", "``", "null"].includes(context.getSourceCode().getText(node)); | ||
} | ||
[`BinaryExpression[left.property.name='firstChild'][right.value=null][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](node) { | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.left.object.range[1], node.range[1]]), fixer.replaceText(node.parent.parent.property, Boolean(node.parent.parent.parent.arguments[0].value) === node.operator.startsWith("=") // binary expression XNOR matcher boolean | ||
? "toBeEmptyDOMElement" : "not.toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])] | ||
}); | ||
}, | ||
return { | ||
[`BinaryExpression[left.property.name='innerHTML'][right.value=''][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](node) { | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.left.object.range[1], node.range[1]]), fixer.replaceText(node.parent.parent.property, Boolean(node.parent.parent.parent.arguments[0].value) === node.operator.startsWith("=") // binary expression XNOR matcher boolean | ||
? "toBeEmptyDOMElement" : "not.toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])] | ||
}); | ||
}, | ||
[`MemberExpression[property.name = 'innerHTML'][parent.callee.name = 'expect'][parent.parent.property.name = /toBe$|to(Strict)?Equal/]`](node) { | ||
const args = node.parent.parent.parent.arguments[0]; | ||
[`BinaryExpression[left.property.name='firstChild'][right.value=null][parent.callee.name='expect'][parent.parent.property.name=/toBe$|to(Strict)?Equal/]`](node) { | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.left.object.range[1], node.range[1]]), fixer.replaceText(node.parent.parent.property, Boolean(node.parent.parent.parent.arguments[0].value) === node.operator.startsWith("=") // binary expression XNOR matcher boolean | ||
? "toBeEmptyDOMElement" : "not.toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])] | ||
}); | ||
}, | ||
if (isNonEmptyStringOrTemplateLiteral(args)) { | ||
return; | ||
} | ||
[`MemberExpression[property.name = 'innerHTML'][parent.callee.name = 'expect'][parent.parent.property.name = /toBe$|to(Strict)?Equal/]`](node) { | ||
const args = node.parent.parent.parent.arguments[0]; | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.property, "toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])] | ||
}); | ||
}, | ||
if (isNonEmptyStringOrTemplateLiteral(args)) { | ||
return; | ||
} | ||
[`MemberExpression[property.name='innerHTML'][parent.parent.property.name='not'][parent.parent.parent.property.name=/toBe$|to(Strict)?Equal$/][parent.parent.object.callee.name='expect']`](node) { | ||
const args = node.parent.parent.parent.parent.arguments[0]; | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.property, "toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])] | ||
}); | ||
}, | ||
if (isNonEmptyStringOrTemplateLiteral(args)) { | ||
return; | ||
} | ||
[`MemberExpression[property.name='innerHTML'][parent.parent.property.name='not'][parent.parent.parent.property.name=/toBe$|to(Strict)?Equal$/][parent.parent.object.callee.name='expect']`](node) { | ||
const args = node.parent.parent.parent.parent.arguments[0]; | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.parent.property, "toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.parent.arguments[0])] | ||
}); | ||
}, | ||
if (isNonEmptyStringOrTemplateLiteral(args)) { | ||
return; | ||
} | ||
[`MemberExpression[property.name = 'firstChild'][parent.callee.name = 'expect'][parent.parent.property.name = /toBeNull$/]`](node) { | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.property, "toBeEmptyDOMElement")] | ||
}); | ||
}, | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.parent.property, "toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.parent.arguments[0])] | ||
}); | ||
}, | ||
[`MemberExpression[property.name='firstChild'][parent.parent.property.name='not'][parent.parent.parent.property.name=/toBe$|to(Strict)?Equal$/][parent.parent.object.callee.name='expect']`](node) { | ||
if (node.parent.parent.parent.parent.arguments[0].value !== null) { | ||
return; | ||
} | ||
[`MemberExpression[property.name = 'firstChild'][parent.callee.name = 'expect'][parent.parent.property.name = /toBeNull$/]`](node) { | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.property, "toBeEmptyDOMElement")] | ||
}); | ||
}, | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.parent.property, "toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.parent.arguments[0])] | ||
}); | ||
}, | ||
[`MemberExpression[property.name='firstChild'][parent.parent.property.name='not'][parent.parent.parent.property.name=/toBe$|to(Strict)?Equal$/][parent.parent.object.callee.name='expect']`](node) { | ||
if (node.parent.parent.parent.parent.arguments[0].value !== null) { | ||
return; | ||
} | ||
[`MemberExpression[property.name='firstChild'][parent.parent.property.name='not'][parent.parent.parent.property.name=/toBeNull$/][parent.parent.object.callee.name='expect']`](node) { | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.parent.property, "toBeEmptyDOMElement")] | ||
}); | ||
}, | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.parent.property, "toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.parent.arguments[0])] | ||
}); | ||
}, | ||
[`MemberExpression[property.name = 'firstChild'][parent.callee.name = 'expect'][parent.parent.property.name = /toBe$|to(Strict)?Equal/]`](node) { | ||
if (node.parent.parent.parent.arguments[0].value !== null) { | ||
return; | ||
} | ||
[`MemberExpression[property.name='firstChild'][parent.parent.property.name='not'][parent.parent.parent.property.name=/toBeNull$/][parent.parent.object.callee.name='expect']`](node) { | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.parent.property, "toBeEmptyDOMElement")] | ||
}); | ||
}, | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.property, "toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])] | ||
}); | ||
} | ||
[`MemberExpression[property.name = 'firstChild'][parent.callee.name = 'expect'][parent.parent.property.name = /toBe$|to(Strict)?Equal/]`](node) { | ||
if (node.parent.parent.parent.arguments[0].value !== null) { | ||
return; | ||
} | ||
}); | ||
context.report({ | ||
node, | ||
message: "Use toBeEmptyDOMElement instead of checking inner html.", | ||
fix: fixer => [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(node.parent.parent.property, "toBeEmptyDOMElement"), fixer.remove(node.parent.parent.parent.arguments[0])] | ||
}); | ||
} | ||
exports.create = create; | ||
}; | ||
}; | ||
function isNonEmptyStringOrTemplateLiteral(node) { | ||
var _node$quasis, _node$quasis2, _node$quasis$, _node$quasis$$value; | ||
return !(node.type === "Literal" || node.type === "TemplateLiteral") || node.value || node.name || (node == null ? void 0 : (_node$quasis = node.quasis) == null ? void 0 : _node$quasis.length) > 0 && !((node == null ? void 0 : (_node$quasis2 = node.quasis) == null ? void 0 : _node$quasis2.length) === 1 && (node == null ? void 0 : (_node$quasis$ = node.quasis[0]) == null ? void 0 : (_node$quasis$$value = _node$quasis$.value) == null ? void 0 : _node$quasis$$value.raw) === ""); | ||
} | ||
exports.create = create; |
@@ -39,3 +39,3 @@ "use strict"; | ||
fix(fixer) { | ||
return [fixer.removeRange([node.object.range[1], styleName.range[1]]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceText(styleValue, `{${styleName.name}:${styleValue.raw}}`)]; | ||
return [fixer.removeRange([node.object.range[1], styleName.range[1]]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceText(styleValue, `{${styleName.name}:${context.getSourceCode().getText(styleValue)}}`)]; | ||
} | ||
@@ -56,3 +56,3 @@ | ||
fix(fixer) { | ||
return [fixer.removeRange([node.object.range[1], styleName.range[1]]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceText(styleValue, `{${styleName.name}:${styleValue.raw}}`)]; | ||
return [fixer.removeRange([node.object.range[1], styleName.range[1]]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceText(styleValue, `{${styleName.name}:${context.getSourceCode().getText(styleValue)}}`)]; | ||
} | ||
@@ -118,3 +118,3 @@ | ||
fix(fixer) { | ||
return [fixer.removeRange([startOfStyleMemberExpression, endOfStyleMemberExpression]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceText(styleValue, `{${camelCase(styleName.value)}: ${styleValue.raw}}`)]; | ||
return [fixer.removeRange([startOfStyleMemberExpression, endOfStyleMemberExpression]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceText(styleValue, `{${camelCase(styleName.value)}: ${context.getSourceCode().getText(styleValue)}}`)]; | ||
} | ||
@@ -136,3 +136,3 @@ | ||
fix(fixer) { | ||
return [fixer.removeRange([node.object.range[1], endOfStyleMemberExpression]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceText(styleValue, `{${camelCase(styleName.value)}: ${styleValue.raw}}`)]; | ||
return [fixer.removeRange([node.object.range[1], endOfStyleMemberExpression]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceText(styleValue, `{${camelCase(styleName.value)}: ${context.getSourceCode().getText(styleValue)}}`)]; | ||
} | ||
@@ -152,3 +152,3 @@ | ||
fix(fixer) { | ||
return [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceTextRange([styleName.range[0], styleValue.range[1]], `{${camelCase(styleName.value)}: ${styleValue.raw}}`)]; | ||
return [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceTextRange([styleName.range[0], styleValue.range[1]], `{${camelCase(styleName.value)}: ${context.getSourceCode().getText(styleValue)}}`)]; | ||
} | ||
@@ -168,3 +168,3 @@ | ||
fix(fixer) { | ||
return [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceTextRange([styleName.range[0], styleValue.range[1]], `{${camelCase(styleName.value)}: ${styleValue.raw}}`)]; | ||
return [fixer.removeRange([node.object.range[1], node.property.range[1]]), fixer.replaceText(matcher, "toHaveStyle"), fixer.replaceTextRange([styleName.range[0], styleValue.range[1]], `{${camelCase(styleName.value)}: ${context.getSourceCode().getText(styleValue)}}`)]; | ||
} | ||
@@ -171,0 +171,0 @@ |
{ | ||
"name": "eslint-plugin-jest-dom", | ||
"version": "3.2.1", | ||
"version": "3.2.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", |
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
648
46908