Skip to content

Commit 64d0cf8

Browse files
committed
Try to add a test
1 parent 6ee5247 commit 64d0cf8

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pkg/result/processors/nolint.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ func (p *Nolint) shouldPassIssue(i *result.Issue) (bool, error) {
164164

165165
for _, ir := range fd.ignoredRanges {
166166
if ir.doesMatch(i) {
167+
nolintDebugf("found ignored range for issue %v: %v", i, ir)
167168
ir.matchedIssueFromLinter[i.FromLinter] = true
168169
if ir.originalRange != nil {
169170
ir.originalRange.matchedIssueFromLinter[i.FromLinter] = true
@@ -203,7 +204,10 @@ func (e *rangeExpander) Visit(node ast.Node) ast.Visitor {
203204
}
204205

205206
expandedRange := *foundRange
206-
expandedRange.originalRange = foundRange
207+
// store the original unexpanded range for matching nolintlint issues
208+
if expandedRange.originalRange == nil {
209+
expandedRange.originalRange = foundRange
210+
}
207211
if expandedRange.To < nodeEndLine {
208212
expandedRange.To = nodeEndLine
209213
}

test/testdata/nolintlint.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
//args: -Enolintlint
1+
//args: -Enolintlint -Emisspell
22
//config: linters-settings.nolintlint.require-explanation=true
33
//config: linters-settings.nolintlint.require-specific=true
44
//config: linters-settings.nolintlint.allow-leading-space=false
@@ -10,4 +10,11 @@ func Foo() {
1010
fmt.Println("not specific") //nolint // ERROR "directive `.*` should mention specific linter such as `//nolint:my-linter`"
1111
fmt.Println("not machine readable") // nolint // ERROR "directive `.*` should be written as `//nolint`"
1212
fmt.Println("extra spaces") // nolint:deadcode // because // ERROR "directive `.*` should not have more than one leading space"
13+
14+
// test expanded range
15+
//nolint:misspell // deliberate misspelling to trigger nolintlint
16+
func() {
17+
mispell := true
18+
fmt.Println(mispell)
19+
}()
1320
}

0 commit comments

Comments
 (0)