1
- // nolintlint provides a linter to ensure that all //nolint directives are followed by explanations
1
+ // Package nolintlint provides a linter to ensure that all //nolint directives are followed by explanations
2
2
package nolintlint
3
3
4
4
import (
@@ -19,10 +19,12 @@ type BaseIssue struct {
19
19
replacement * result.Replacement
20
20
}
21
21
22
+ //nolint:gocritic // TODO must be change in the future.
22
23
func (b BaseIssue ) Position () token.Position {
23
24
return b .position
24
25
}
25
26
27
+ //nolint:gocritic // TODO must be change in the future.
26
28
func (b BaseIssue ) Replacement () * result.Replacement {
27
29
return b .replacement
28
30
}
@@ -31,64 +33,75 @@ type ExtraLeadingSpace struct {
31
33
BaseIssue
32
34
}
33
35
36
+ //nolint:gocritic // TODO must be change in the future.
34
37
func (i ExtraLeadingSpace ) Details () string {
35
38
return fmt .Sprintf ("directive `%s` should not have more than one leading space" , i .fullDirective )
36
39
}
37
40
41
+ //nolint:gocritic // TODO must be change in the future.
38
42
func (i ExtraLeadingSpace ) String () string { return toString (i ) }
39
43
40
44
type NotMachine struct {
41
45
BaseIssue
42
46
}
43
47
48
+ //nolint:gocritic // TODO must be change in the future.
44
49
func (i NotMachine ) Details () string {
45
50
expected := i .fullDirective [:2 ] + strings .TrimLeftFunc (i .fullDirective [2 :], unicode .IsSpace )
46
51
return fmt .Sprintf ("directive `%s` should be written without leading space as `%s`" ,
47
52
i .fullDirective , expected )
48
53
}
49
54
55
+ //nolint:gocritic // TODO must be change in the future.
50
56
func (i NotMachine ) String () string { return toString (i ) }
51
57
52
58
type NotSpecific struct {
53
59
BaseIssue
54
60
}
55
61
62
+ //nolint:gocritic // TODO must be change in the future.
56
63
func (i NotSpecific ) Details () string {
57
64
return fmt .Sprintf ("directive `%s` should mention specific linter such as `%s:my-linter`" ,
58
65
i .fullDirective , i .directiveWithOptionalLeadingSpace )
59
66
}
60
67
68
+ //nolint:gocritic // TODO must be change in the future.
61
69
func (i NotSpecific ) String () string { return toString (i ) }
62
70
63
71
type ParseError struct {
64
72
BaseIssue
65
73
}
66
74
75
+ //nolint:gocritic // TODO must be change in the future.
67
76
func (i ParseError ) Details () string {
68
77
return fmt .Sprintf ("directive `%s` should match `%s[:<comma-separated-linters>] [// <explanation>]`" ,
69
78
i .fullDirective ,
70
79
i .directiveWithOptionalLeadingSpace )
71
80
}
72
81
82
+ //nolint:gocritic // TODO must be change in the future.
73
83
func (i ParseError ) String () string { return toString (i ) }
74
84
75
85
type NoExplanation struct {
76
86
BaseIssue
77
87
fullDirectiveWithoutExplanation string
78
88
}
79
89
90
+ //nolint:gocritic // TODO must be change in the future.
80
91
func (i NoExplanation ) Details () string {
81
92
return fmt .Sprintf ("directive `%s` should provide explanation such as `%s // this is why`" ,
82
93
i .fullDirective , i .fullDirectiveWithoutExplanation )
83
94
}
84
95
96
+ //nolint:gocritic // TODO must be change in the future.
85
97
func (i NoExplanation ) String () string { return toString (i ) }
86
98
87
99
type UnusedCandidate struct {
88
100
BaseIssue
89
101
ExpectedLinter string
90
102
}
91
103
104
+ //nolint:gocritic // TODO must be change in the future.
92
105
func (i UnusedCandidate ) Details () string {
93
106
details := fmt .Sprintf ("directive `%s` is unused" , i .fullDirective )
94
107
if i .ExpectedLinter != "" {
@@ -97,6 +110,7 @@ func (i UnusedCandidate) Details() string {
97
110
return details
98
111
}
99
112
113
+ //nolint:gocritic // TODO must be change in the future.
100
114
func (i UnusedCandidate ) String () string { return toString (i ) }
101
115
102
116
func toString (i Issue ) string {
@@ -126,8 +140,7 @@ var commentPattern = regexp.MustCompile(`^//\s*(nolint)(:\s*[\w-]+\s*(?:,\s*[\w-
126
140
var fullDirectivePattern = regexp .MustCompile (`^//\s*nolint(?::(\s*[\w-]+\s*(?:,\s*[\w-]+\s*)*))?\s*(//.*)?\s*\n?$` )
127
141
128
142
type Linter struct {
129
- excludes []string // lists individual linters that don't require explanations
130
- needs Needs // indicates which linter checks to perform
143
+ needs Needs // indicates which linter checks to perform
131
144
excludeByLinter map [string ]bool
132
145
}
133
146
@@ -147,6 +160,7 @@ func NewLinter(needs Needs, excludes []string) (*Linter, error) {
147
160
var leadingSpacePattern = regexp .MustCompile (`^//(\s*)` )
148
161
var trailingBlankExplanation = regexp .MustCompile (`\s*(//\s*)?$` )
149
162
163
+ //nolint:funlen,gocyclo
150
164
func (l Linter ) Run (fset * token.FileSet , nodes ... ast.Node ) ([]Issue , error ) {
151
165
var issues []Issue
152
166
@@ -214,7 +228,6 @@ func (l Linter) Run(fset *token.FileSet, nodes ...ast.Node) ([]Issue, error) {
214
228
215
229
lintersText , explanation := fullMatches [1 ], fullMatches [2 ]
216
230
var linters []string
217
- var linterRange []result.Range
218
231
if len (lintersText ) > 0 {
219
232
lls := strings .Split (lintersText , "," )
220
233
linters = make ([]string , 0 , len (lls ))
@@ -227,7 +240,6 @@ func (l Linter) Run(fset *token.FileSet, nodes ...ast.Node) ([]Issue, error) {
227
240
trimmedLinterName := strings .TrimSpace (ll )
228
241
if trimmedLinterName != "" {
229
242
linters = append (linters , trimmedLinterName )
230
- linterRange = append (linterRange , result.Range {From : rangeStart , To : rangeEnd })
231
243
}
232
244
rangeStart = rangeEnd
233
245
}
0 commit comments