Skip to content

Commit

Permalink
Fix line number in varorder diagnostic
Browse files Browse the repository at this point in the history
  • Loading branch information
rillig committed Jan 26, 2025
1 parent 9a022f2 commit 7386cfb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
16 changes: 6 additions & 10 deletions v23/varorderchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,20 +109,16 @@ func (ck *VarorderChecker) check(mklines []*MkLine, bottom *MkLine) {
commented++
} else {
uncommented++
if uncommented > 1 && v.repetition != many {
mkline := mklines[mi]
mkline.Warnf("The variable \"%s\" should only occur once.", v.canon)
ck.explain(mkline)
return
}
}
mi++
}

if uncommented > 1 && v.repetition != many {
mkline := bottom
if mi < mn {
mkline = mklines[mi]
}
mkline.Warnf("The variable \"%s\" should only occur once.", v.canon)
ck.explain(mkline)
return
}

if v.repetition == once && commented+uncommented == 0 &&
!(v.canon == "LICENSE" && ck.skipLicenseCheck(mklines)) {
mkline := bottom
Expand Down
5 changes: 2 additions & 3 deletions v23/varorderchecker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,8 @@ func (s *Suite) Test_VarorderChecker_Check__once_repeated(c *check.C) {

NewVarorderChecker(mklines).Check()

// FIXME: wrong line, must be 7.
t.CheckOutputLines(
"WARN: Makefile:8: The variable \"CATEGORIES\" " +
"WARN: Makefile:7: The variable \"CATEGORIES\" " +
"should only occur once.")
}

Expand Down Expand Up @@ -657,7 +656,7 @@ func (s *Suite) Test_VarorderChecker_check(c *check.C) {
NewVarorderChecker(mklines).Check()

t.CheckOutputLines(
"WARN: Makefile:6: The variable \"CATEGORIES\" should only occur once.")
"WARN: Makefile:5: The variable \"CATEGORIES\" should only occur once.")
}

// This package does not declare its LICENSE.
Expand Down

0 comments on commit 7386cfb

Please sign in to comment.