An else follows a branch that always leaves with return, throw, break or continue
What it finds
When the if branch always leaves, the else adds a level of nesting for code that runs anyway only when the condition is false. Writing that code after the if keeps the main path at the left margin. else if chains are left alone.
From the rule's source, else_after_return.rs.
class Flow{ int Sign(int x) { if (x < 0) { return -1; } elsetx0 reports: this else follows a branch that always leaves { return 1; } }} Turn it on, off or suppress it
The rule runs from the all tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:else-after-return" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:else-after-return] reason="..."tx0 explain tx0/csharp:else-after-return shows the same in the terminal. Found a false positive? Report it.