55# handler); in this case, the other path needs not be nested inside the if
66# statement and is flagged.
77
8- fun has_last_breaking_stmt(list ) =
9- match list[list .children_count]
8+ fun has_last_breaking_stmt(stmts ) =
9+ match stmts[stmts .children_count]
1010 | (RaiseStmt | ReturnStmt | ExitStmt(f_cond_expr: null) | GotoStmt) => true
1111 | b@BlockStmt => b.f_stmts.f_exceptions[1] == null and
1212 has_last_breaking_stmt(b.f_stmts.f_stmts)
@@ -15,10 +15,18 @@ fun has_last_breaking_stmt(list) =
1515@check(message="nested path may be moved outside if statement",
1616 category="Style", subcategory="Programming Practice")
1717fun nested_paths(node) =
18- node is StmtList(parent: if_stmt@IfStmt)
19- when if_stmt.f_alternatives[1] == null
20- and if_stmt.f_else_stmts[1] != null
18+ # Match stmt lists that are either the then or the else list of an if stmt
19+ node is (StmtList(parent: if_stmt@IfStmt) |
20+ StmtList(parent: ElsePart(parent: if_stmt@IfStmt)))
21+ when
22+
23+ # No "elsif" branches
24+ if_stmt.f_alternatives[1] == null
25+
26+ # Has an "else" part
27+ and if_stmt.f_else_part.f_stmts[1] != null
28+
2129 and not has_last_breaking_stmt(node)
2230 and has_last_breaking_stmt(if if_stmt.f_then_stmts == node
23- then if_stmt.f_else_stmts
31+ then if_stmt.f_else_part.f_stmts
2432 else if_stmt.f_then_stmts)
0 commit comments