Skip to content

Commit 3a45453

Browse files
committed
test+refactor: fix dead conditional assert and unify Sprintf in conciseness rule
Two fixes from code-review round 3: - rule_test.go: TestCheck_MessageNoConcatenationWhenExamplesPresent guarded the assert.Contains(msg, "e.g.,") behind `if strings.Contains(msg, "reduce verbose cues")`, making it a no-op in the exact regression it was meant to catch (message drops cue text → outer if is false → inner assert never runs). verboseParagraph() always produces cues, so assert both strings unconditionally. Remove the now-unused "strings" import. - rule.go: Replace the if/else with two identical fmt.Sprintf call sites (same three arguments, same format prefix) with a single call that takes a conditional cuesSuffix string. The base format string now lives in one place so it can't diverge between the cue and no-cue paths. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015QYub2iGP6CeeEFSfjV3Wv
1 parent 12f6a79 commit 3a45453

2 files changed

Lines changed: 11 additions & 18 deletions

File tree

internal/rules/concisenessscoring/rule.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,14 @@ func (r *Rule) Check(f *lint.File) []lint.Diagnostic {
9898

9999
line := astutil.ParagraphLine(para, f)
100100
examples := formatExamples(result.Cues)
101-
var message string
102-
if examples == "" {
103-
message = fmt.Sprintf(
104-
"conciseness score too low (%.2f < %.2f); target >= %.2f",
105-
result.Conciseness, r.MinScore, r.MinScore,
106-
)
107-
} else {
108-
message = fmt.Sprintf(
109-
"conciseness score too low (%.2f < %.2f); target >= %.2f; reduce verbose cues (e.g., %s)",
110-
result.Conciseness, r.MinScore, r.MinScore, examples,
111-
)
101+
var cuesSuffix string
102+
if examples != "" {
103+
cuesSuffix = "; reduce verbose cues (e.g., " + examples + ")"
112104
}
105+
message := fmt.Sprintf(
106+
"conciseness score too low (%.2f < %.2f); target >= %.2f%s",
107+
result.Conciseness, r.MinScore, r.MinScore, cuesSuffix,
108+
)
113109

114110
diags = append(diags, lint.Diagnostic{
115111
File: f.Path,

internal/rules/concisenessscoring/rule_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package concisenessscoring
22

33
import (
44
"errors"
5-
"strings"
65
"sync"
76
"testing"
87

@@ -314,14 +313,12 @@ func TestCheck_MessageNoConcatenationWhenExamplesPresent(t *testing.T) {
314313
t.Skip("model threshold did not trigger on fixture")
315314
}
316315
msg := diags[0].Message
317-
// The message must contain both the score summary and the cue guidance
318-
// in a single string (not two separately allocated pieces).
316+
// The message must contain both the score summary and the cue guidance.
319317
assert.Contains(t, msg, "conciseness score too low")
320318
assert.Contains(t, msg, "target >=")
321-
// If verbose cues were detected, the formatted examples must also be present.
322-
if strings.Contains(msg, "reduce verbose cues") {
323-
assert.Contains(t, msg, "e.g.,", "message with cues must include formatted examples")
324-
}
319+
// verboseParagraph always triggers cue detection; both must be present.
320+
assert.Contains(t, msg, "reduce verbose cues")
321+
assert.Contains(t, msg, "e.g.,", "message with cues must include formatted examples")
325322
}
326323

327324
func TestCheck_NoCuesMessage(t *testing.T) {

0 commit comments

Comments
 (0)