Skip to content

Commit

Permalink
improve check for conditionals
Browse files Browse the repository at this point in the history
Signed-off-by: Jade Abraham <[email protected]>
  • Loading branch information
jabraham17 committed Aug 29, 2024
1 parent ee7f1cd commit 379842b
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions tools/chplcheck/src/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ def might_incorrectly_report_location(node: AstNode) -> bool:
elif isinstance(node, Conditional):
parent = node.parent()
grandparent = parent.parent() if parent else None
if grandparent and isinstance(grandparent, Conditional):
if (
isinstance(parent, Block)
and parent.block_style() == "implicit"
and grandparent
and isinstance(grandparent, Conditional)
):
return True

return False
Expand Down Expand Up @@ -822,7 +827,13 @@ def unwrap_intermediate_block(node: AstNode) -> Optional[AstNode]:
# var x: int;
# }
elif parent_depth and depth == parent_depth:
yield AdvancedRuleResult(child, anchor=parent_for_indentation)
# conditionals do not support attributes
anchor = (
parent_for_indentation
if not isinstance(parent_for_indentation, Conditional)
else None
)
yield AdvancedRuleResult(child, anchor=anchor)

prev_depth = depth
prev = child
Expand Down

0 comments on commit 379842b

Please sign in to comment.