@@ -30,23 +30,27 @@ func (i *ignoredRange) doesMatch(issue *result.Issue) bool {
30
30
return false
31
31
}
32
32
33
- // handle possible unused nolint directives
34
- // nolintlint generates potential issues for every nolint directive and they are filtered out here
35
- if issue .ExpectNoLint {
36
- if issue .ExpectedNoLintLinter != "" {
37
- return i .matchedIssueFromLinter [issue .ExpectedNoLintLinter ]
33
+ // only allow selective nolinting of nolintlint
34
+ nolintFoundForLinter := len (i .linters ) == 0 && issue .FromLinter != golinters .NolintlintName
35
+
36
+ for _ , linterName := range i .linters {
37
+ if linterName == issue .FromLinter {
38
+ nolintFoundForLinter = true
39
+ break
38
40
}
39
- return len (i .matchedIssueFromLinter ) > 0
40
41
}
41
42
42
- if len ( i . linters ) == 0 {
43
+ if nolintFoundForLinter {
43
44
return true
44
45
}
45
46
46
- for _ , linterName := range i .linters {
47
- if linterName == issue .FromLinter {
48
- return true
47
+ // handle possible unused nolint directives
48
+ // nolintlint generates potential issues for every nolint directive and they are filtered out here
49
+ if issue .FromLinter == golinters .NolintlintName && issue .ExpectNoLint {
50
+ if issue .ExpectedNoLintLinter != "" {
51
+ return i .matchedIssueFromLinter [issue .ExpectedNoLintLinter ]
49
52
}
53
+ return len (i .matchedIssueFromLinter ) > 0
50
54
}
51
55
52
56
return false
@@ -142,19 +146,14 @@ func (p *Nolint) buildIgnoredRangesForFile(f *ast.File, fset *token.FileSet, fil
142
146
143
147
func (p * Nolint ) shouldPassIssue (i * result.Issue ) (bool , error ) {
144
148
nolintDebugf ("got issue: %v" , * i )
145
- if i .FromLinter == golinters .NolintlintName {
146
- // always pass nolintlint issues except ones trying find unused nolint directives
147
- if ! i .ExpectNoLint {
148
- return true , nil
149
- }
150
- if i .ExpectedNoLintLinter != "" {
151
- // don't expect disabled linters to cover their nolint statements
152
- nolintDebugf ("enabled linters: %v" , p .enabledLinters )
153
- if p .enabledLinters [i .ExpectedNoLintLinter ] == nil {
154
- return false , nil
155
- }
156
- nolintDebugf ("checking that lint issue was used for %s: %v" , i .ExpectedNoLintLinter , i )
149
+
150
+ if i .FromLinter == golinters .NolintlintName && i .ExpectNoLint && i .ExpectedNoLintLinter != "" {
151
+ // don't expect disabled linters to cover their nolint statements
152
+ nolintDebugf ("enabled linters: %v" , p .enabledLinters )
153
+ if p .enabledLinters [i .ExpectedNoLintLinter ] == nil {
154
+ return false , nil
157
155
}
156
+ nolintDebugf ("checking that lint issue was used for %s: %v" , i .ExpectedNoLintLinter , i )
158
157
}
159
158
160
159
fd , err := p .getOrCreateFileData (i )
0 commit comments