lint rule: unreachable branch given a prior guard clause #201
Labels
No labels
P0
P1
P2
P3
bug
create
delete
enhancement
filed-by/agent
filed-by/user
frozen
lint-rule
needs-info
needs-triage
next
plugin/cc-architect
plugin/os
plugin/os-adr
plugin/os-aidd-lint
plugin/os-backlog
plugin/os-context
plugin/os-doc-hygiene
plugin/os-sdlc
plugin/os-vault
project/cc-os
ready-for-agent
ready-for-human
recurring
review
update
waiting
wayfinder:grilling
wayfinder:map
wayfinder:map
wayfinder:research
wayfinder:task
wayfinder:task
wontfix
worklist/deviations
worklist/lint-rule
worklist/new-implement-build
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
jared/cc-os#201
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Migrated from jared/os-sdlc#26 (repo retired).
lint rule: unreachable branch given a prior guard clause
Problem
General pattern (originally found in the retired eval-sandbox's
decision-dice.rb, no longer relevant as a specific file): a conditional
branch whose condition can never be true given an earlier guard clause in
the same method, e.g. a guard that raises when some value is empty, followed
later by a branch that only fires when that same value is empty. The branch
is dead code and never test-coverable.
Detection
(e.g.
mutant) that would surface this branch as an unkillable mutantbecause no test exercises it; (b) a narrow, mechanical rubocop cop that
only flags the specific shape "guard clause raises when
x.empty?, laterbranch condition includes
x.empty?with no intervening reassignment ofx" -- this narrower version is AST-checkable but only catches this one
shape, not general unreachability.
that makes it unreachable.
Correction
Delete the branch, or add a test proving it's reachable via a path not yet
considered.
Pass/fail examples
x.empty?and alater branch also conditioned on
x.empty?with no test exercising it.Provenance
Fable + Codex dual review, run 18 (ticket #18, decision-dice), 2026-07-21.
Reassessed 2026-08-01 during os-sdlc sandbox retirement triage: general
unreachability analysis is likely too broad for a rubocop cop; the narrower
guard-clause-shape version (candidate b above) is the only variant that's
concretely implementable as a cop. Needs a decision on which variant to
pursue before implementation.
Implementation plan
Not decided -- general mutation-testing gate vs. narrow AST cop is an open
call.
Recommendation for maintainer: pursue option (b), the narrow AST cop, not mutation testing. Mutant is slow and flaky against this repo's minitest suite, and general unreachability-given-a-guard is undecidable — scope creep for a cop. The narrow shape (raise-on-empty? guard, later branch re-testing the same predicate with no intervening reassignment) is a small, mechanical Sdlc::UnreachableGuardedBranch cop, consistent with this repo's existing single-file cops. This resolves the open call; ready to implement as scoped.
Implemented via os-sdlc pipeline (APPROVE). Narrow AST cop variant (candidate b per triage): Sdlc/Structural/UnreachableBranchAfterGuard. Merged to main in
b7c2b66.