Skip to content

Commit b6ae874

Browse files
committed
Add: test for nolint range
1 parent 0f8df04 commit b6ae874

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

Diff for: pkg/result/processors/nolint_test.go

+35
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,41 @@ func TestNolint(t *testing.T) {
122122
}
123123
}
124124

125+
func newNolintRangeFileIssue(line int, fromLinter string) result.Issue {
126+
return result.Issue{
127+
Pos: token.Position{
128+
Filename: filepath.Join("testdata", "nolintrange.go"),
129+
Line: line,
130+
},
131+
FromLinter: fromLinter,
132+
}
133+
}
134+
135+
func TestNolintRange(t *testing.T) {
136+
p := newTestNolintProcessor(getMockLog())
137+
defer p.Finish()
138+
139+
// normal nolint range
140+
for i := 3; i <= 6; i++ {
141+
processAssertEmpty(t, p, newNolintRangeFileIssue(i, "gofmt"))
142+
}
143+
144+
processAssertSame(t, p, newNolintRangeFileIssue(7, "any"))
145+
146+
// nested nolint range
147+
for i := 8; i <= 13; i++ {
148+
processAssertEmpty(t, p, newNolintRangeFileIssue(i, "unused"))
149+
}
150+
for i := 9; i <= 12; i++ {
151+
processAssertEmpty(t, p, newNolintRangeFileIssue(i, "gofmt"))
152+
}
153+
154+
// nolint range without nolint-end
155+
for i := 15; i <= 20; i++ {
156+
processAssertEmpty(t, p, newNolintRangeFileIssue(i, "deadcode"))
157+
}
158+
}
159+
125160
func TestNolintInvalidLinterName(t *testing.T) {
126161
fileName := filepath.Join("testdata", "nolint_bad_names.go")
127162
issues := []result.Issue{

Diff for: pkg/result/processors/testdata/nolintrange.go

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package testdata
2+
3+
//nolint-begin:gofmt
4+
var nolintRange int
5+
6+
//nolint-end:gofmt
7+
8+
//nolint-begin:unused
9+
//nolint-begin:gofmt
10+
var nolintRangeNested int
11+
12+
//nolint-end:gofmt
13+
//nolint-end:unused
14+
15+
//nolint-begin:deadcode
16+
17+
var nolintRangeWithoutEnd1 int
18+
var nolintRangeWithoutEnd2 int
19+
var nolintRangeWithoutEnd3 int
20+
var nolintRangeWithoutEnd4 int

0 commit comments

Comments
 (0)