eslint-plugin-de-morgan
Version:
ESLint plugin for transforming negated boolean expressions via De Morgan’s laws
29 lines (28 loc) • 1.09 kB
JavaScript
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' })
const findOutermostParenthesizedNode = require('./find-outermost-parenthesized-node.js')
const isLogicalExpression = require('./is-logical-expression.js')
const isUnaryExpression = require('./is-unary-expression.js')
const getSourceCode = require('./get-source-code.js')
let hasNegationInside = node => {
if (isUnaryExpression.isUnaryExpression(node) && node.operator === '!') {
return true
}
if (isLogicalExpression.isLogicalExpression(node)) {
return hasNegationInside(node.left) || hasNegationInside(node.right)
}
return false
}
let hasNegationInsideParentheses = (node, context) => {
let sourceCode = getSourceCode.getSourceCode(context).getText(node)
let outermostNode =
findOutermostParenthesizedNode.findOutermostParenthesizedNode(
node,
sourceCode,
)
if (!isUnaryExpression.isUnaryExpression(outermostNode)) {
return false
}
return hasNegationInside(outermostNode.argument)
}
exports.hasNegationInsideParentheses = hasNegationInsideParentheses