eslint-plugin-de-morgan
Version:
ESLint plugin for transforming negated boolean expressions via De Morgan’s laws
16 lines (15 loc) • 444 B
JavaScript
import { hasNegationOperator } from './has-negation-operator.js'
/**
* Checks whether the given AST node is a negated expression.
*
* @param node - The AST node to check.
* @returns True if the node is a UnaryExpression with operator `!`.
*/
function isNegated(node) {
return (
hasNegationOperator(node) &&
!hasNegationOperator(node.argument) &&
(!node.parent || !hasNegationOperator(node.parent))
)
}
export { isNegated }