Summary
Extract a groupSatisfied helper in internal/doctor/doctor.go to eliminate duplicated pipe-splitting logic in CheckVariables().
Context
PR #778 introduced OptionalTargetVariableGroups support with a pipe-split-and-lookup pattern that appears three times in CheckVariables():
- Validation counting (line ~786): splits group on
|, iterates members, checks target.Variables[m]
- Verbose detail for mapped targets (line ~893): identical split-iterate-check logic
- Verbose detail for unmapped targets (line ~871): iterates groups without split (same pattern surface)
The first two are structurally identical.
Proposed Change
Extract a shared helper:
func groupSatisfied(group string, vars map[string]string) bool {
for _, m := range strings.Split(group, "|") {
if _, ok := vars[m]; ok {
return true
}
}
return false
}
Replace the inline loops at all call sites with groupSatisfied(group, target.Variables).
Motivation
- DRY (Constitution I, CS-004): identical logic in multiple locations
- Low risk: pure refactoring within a single function, no signature or behavior changes
- Improves readability and reduces maintenance surface
Files
- internal/doctor/doctor.go
- internal/doctor/doctor_test.go (no changes expected; existing tests cover behavior)
References
- Identified during review of #778
Summary
Extract a
groupSatisfiedhelper ininternal/doctor/doctor.goto eliminate duplicated pipe-splitting logic inCheckVariables().Context
PR #778 introduced
OptionalTargetVariableGroupssupport with a pipe-split-and-lookup pattern that appears three times inCheckVariables():|, iterates members, checkstarget.Variables[m]The first two are structurally identical.
Proposed Change
Extract a shared helper: