📄 isConditionalTest¶
📊 Analysis Summary¶
| Metric | Count |
|---|---|
| 🔧 Functions | 1 |
| 📦 Imports | 2 |
📚 Table of Contents¶
🛠️ File Location:¶
📂 packages/eslint-plugin/src/util/isConditionalTest.ts
📦 Imports¶
| Name | Source |
|---|---|
TSESTree |
@typescript-eslint/utils |
AST_NODE_TYPES |
@typescript-eslint/utils |
Functions¶
isConditionalTest(node: TSESTree.Node): boolean¶
Parameters:
nodeTSESTree.Node
Returns: boolean
Calls:
isConditionalTestparent.expressions.at
Code
export function isConditionalTest(node: TSESTree.Node): boolean {
const parent = node.parent;
if (parent == null) {
return false;
}
if (parent.type === AST_NODE_TYPES.LogicalExpression) {
return isConditionalTest(parent);
}
if (
parent.type === AST_NODE_TYPES.ConditionalExpression &&
(parent.consequent === node || parent.alternate === node)
) {
return isConditionalTest(parent);
}
if (
parent.type === AST_NODE_TYPES.SequenceExpression &&
parent.expressions.at(-1) === node
) {
return isConditionalTest(parent);
}
if (
parent.type === AST_NODE_TYPES.UnaryExpression &&
parent.operator === '!'
) {
return isConditionalTest(parent);
}
if (
(parent.type === AST_NODE_TYPES.ConditionalExpression ||
parent.type === AST_NODE_TYPES.DoWhileStatement ||
parent.type === AST_NODE_TYPES.IfStatement ||
parent.type === AST_NODE_TYPES.ForStatement ||
parent.type === AST_NODE_TYPES.WhileStatement) &&
parent.test === node
) {
return true;
}
return false;
}
Generated by Syntax Scribe