Repository navigation
Add ignore_branches for synthetic else branches - #1189
Merged
Merged
Conversation
Ruby's Coverage library reports an `:else` branch for several syntactic constructs even when the source has no literal `else` keyword: exhaustive `case/in` pattern matches, `case/when` without an `else` arm, `||=` / `&&=`, and `if` / `unless` without an `else`. Those synthetic branches show up as missed and depress branch-coverage percentages despite there being no source code to test against. Only `:implicit_else` is supported today, but the variadic shape leaves room for future synthetic branch types without an API change. Unknown tokens raise `SimpleCov::ConfigurationError` immediately to catch typos. The detection signal is structural rather than textual. An earlier draft scanned the source at the branch's reported `start_col` for the word `else`, but `Coverage` reports the position of the *body* of an explicit `else` arm (e.g. `:nope` on the line below the keyword), not the keyword itself, so the heuristic mis-classified explicit elses as synthetic. The shipped check compares `start_line` against the parent condition's `start_line`: a synthetic else inherits its parent's range and matches, while an explicit `else` arm carries its own line number. This matches every existing branch fixture in the spec suite (case, case_without_else, nested_branches, branches, inline, elsif, branch_tester) without source-text scanning. Resolves #1033.
sferik
force-pushed
the
ignore-branches-implicit-else
branch
from
May 26, 2026 17:55
a0aad12 to
a0722ab
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ruby's Coverage library reports an
:elsebranch for several syntactic constructs even when the source has no literalelsekeyword: exhaustivecase/inpattern matches,case/whenwithout anelsearm,||=/&&=, andif/unlesswithout anelse. Those synthetic branches show up as missed and depress branch-coverage percentages despite there being no source code to test against.Only
:implicit_elseis supported today, but the variadic shape leaves room for future synthetic branch types without an API change. Unknown tokens raiseSimpleCov::ConfigurationErrorimmediately to catch typos.The detection signal is structural rather than textual. An earlier draft scanned the source at the branch's reported
start_colfor the wordelse, butCoveragereports the position of the body of an explicitelsearm (e.g.:nopeon the line below the keyword), not the keyword itself, so the heuristic mis-classified explicit elses as synthetic. The shipped check comparesstart_lineagainst the parent condition'sstart_line: a synthetic else inherits its parent's range and matches, while an explicitelsearm carries its own line number. This matches every existing branch fixture in the spec suite (case, case_without_else, nested_branches, branches, inline, elsif, branch_tester) without source-text scanning.