UNPKG

eslint-plugin-de-morgan

Version:

ESLint plugin for transforming negated boolean expressions via De Morgan’s laws

23 lines (22 loc) 1.09 kB
import { LogicalOperator, UnaryExpression } from 'estree' import { Rule } from 'eslint' type ParentedNode = Rule.NodeParentExtension & UnaryExpression /** * Checks whether the transformed expression must be wrapped in parentheses to * bind correctly inside its parent node. The original `!(…)` expression binds * as tightly as any unary operator, but the produced `&&`/`||` chain binds much * looser, so any parent that binds tighter than the produced operator would * otherwise capture only the first operand of the result. Parentheses are also * required when the parent is a `??` expression, which cannot be mixed with * `&&`/`||` without grouping, and inside a `for` statement initializer, where * the grammar forbids an unparenthesized `in` operator. * * @param node - The negated expression ESLint node being fixed. * @param targetOperator - The logical operator produced by the fix. * @returns True if the fix result must be wrapped in parentheses. */ export declare function needsParentParens( node: ParentedNode, targetOperator: LogicalOperator, ): boolean export {}