You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: pkg/golinters/nolintlint/nolintlint_test.go
+48-94Lines changed: 48 additions & 94 deletions
Original file line number
Diff line number
Diff line change
@@ -40,10 +40,10 @@ func foo() {
40
40
other() //nolintother
41
41
}`,
42
42
expected: []issueWithReplacement{
43
-
{issue: "directive `//nolint` should provide explanation such as `//nolint // this is why` at testing.go:5:1"},
44
-
{issue: "directive `//nolint` should provide explanation such as `//nolint // this is why` at testing.go:7:9"},
45
-
{issue: "directive `//nolint //` should provide explanation such as `//nolint // this is why` at testing.go:8:9"},
46
-
{issue: "directive `//nolint // ` should provide explanation such as `//nolint // this is why` at testing.go:9:9"},
43
+
{"directive `//nolint` should provide explanation such as `//nolint // this is why` at testing.go:5:1", nil},
44
+
{"directive `//nolint` should provide explanation such as `//nolint // this is why` at testing.go:7:9", nil},
45
+
{"directive `//nolint //` should provide explanation such as `//nolint // this is why` at testing.go:8:9", nil},
46
+
{"directive `//nolint // ` should provide explanation such as `//nolint // this is why` at testing.go:9:9", nil},
47
47
},
48
48
},
49
49
{
@@ -57,7 +57,7 @@ package bar
57
57
//nolint:dupl
58
58
func foo() {}`,
59
59
expected: []issueWithReplacement{
60
-
{issue: "directive `//nolint:dupl` should provide explanation such as `//nolint:dupl // this is why` at testing.go:6:1"},
60
+
{"directive `//nolint:dupl` should provide explanation such as `//nolint:dupl // this is why` at testing.go:6:1", nil},
61
61
},
62
62
},
63
63
{
@@ -83,8 +83,8 @@ func foo() {
83
83
bad() // nolint // because
84
84
}`,
85
85
expected: []issueWithReplacement{
86
-
{issue: "directive `//nolint` should mention specific linter such as `//nolint:my-linter` at testing.go:6:9"},
87
-
{issue: "directive `// nolint // because` should mention specific linter such as `// nolint:my-linter` at testing.go:7:9"},
86
+
{"directive `//nolint` should mention specific linter such as `//nolint:my-linter` at testing.go:6:9", nil},
87
+
{"directive `// nolint // because` should mention specific linter such as `// nolint:my-linter` at testing.go:7:9", nil},
88
88
},
89
89
},
90
90
{
@@ -97,16 +97,18 @@ func foo() {
97
97
bad() // nolint
98
98
good() //nolint
99
99
}`,
100
-
expected: []issueWithReplacement{{
101
-
issue: "directive `// nolint` should be written without leading space as `//nolint` at testing.go:5:9",
102
-
replacement: &result.Replacement{
103
-
Inline: &result.InlineFix{
104
-
StartCol: 10,
105
-
Length: 1,
106
-
NewString: "",
100
+
expected: []issueWithReplacement{
101
+
{
102
+
"directive `// nolint` should be written without leading space as `//nolint` at testing.go:5:9",
103
+
&result.Replacement{
104
+
Inline: &result.InlineFix{
105
+
StartCol: 10,
106
+
Length: 1,
107
+
NewString: "",
108
+
},
107
109
},
108
110
},
109
-
}},
111
+
},
110
112
},
111
113
{
112
114
desc: "extra spaces in front of directive are reported",
@@ -117,16 +119,18 @@ func foo() {
117
119
bad() // nolint
118
120
good() // nolint
119
121
}`,
120
-
expected: []issueWithReplacement{{
121
-
issue: "directive `// nolint` should not have more than one leading space at testing.go:5:9",
122
-
replacement: &result.Replacement{
123
-
Inline: &result.InlineFix{
124
-
StartCol: 10,
125
-
Length: 2,
126
-
NewString: " ",
122
+
expected: []issueWithReplacement{
123
+
{
124
+
"directive `// nolint` should not have more than one leading space at testing.go:5:9",
125
+
&result.Replacement{
126
+
Inline: &result.InlineFix{
127
+
StartCol: 10,
128
+
Length: 2,
129
+
NewString: " ",
130
+
},
127
131
},
128
132
},
129
-
}},
133
+
},
130
134
},
131
135
{
132
136
desc: "spaces are allowed in comma-separated list of linters",
@@ -140,7 +144,7 @@ func foo() {
140
144
good() // nolint: linter1, linter2
141
145
}`,
142
146
expected: []issueWithReplacement{
143
-
{issue: "directive `// nolint:linter1 linter2` should match `// nolint[:<comma-separated-linters>] [// <explanation>]` at testing.go:6:9"}, //nolint:lll // this is a string
147
+
{"directive `// nolint:linter1 linter2` should match `// nolint[:<comma-separated-linters>] [// <explanation>]` at testing.go:6:9", nil}, //nolint:lll // this is a string
144
148
},
145
149
},
146
150
{
@@ -162,16 +166,18 @@ package bar
162
166
func foo() {
163
167
bad() //nolint
164
168
}`,
165
-
expected: []issueWithReplacement{{
166
-
issue: "directive `//nolint` is unused at testing.go:5:9",
167
-
replacement: &result.Replacement{
168
-
Inline: &result.InlineFix{
169
-
StartCol: 8,
170
-
Length: 8,
171
-
NewString: "",
169
+
expected: []issueWithReplacement{
170
+
{
171
+
"directive `//nolint` is unused at testing.go:5:9",
172
+
&result.Replacement{
173
+
Inline: &result.InlineFix{
174
+
StartCol: 8,
175
+
Length: 8,
176
+
NewString: "",
177
+
},
172
178
},
173
179
},
174
-
}},
180
+
},
175
181
},
176
182
{
177
183
desc: "needs unused with one specific linter generates replacement",
@@ -181,89 +187,37 @@ package bar
181
187
182
188
func foo() {
183
189
bad() //nolint:somelinter
184
-
}`,
185
-
expected: []issueWithReplacement{{
186
-
issue: "directive `//nolint:somelinter` is unused for linter \"somelinter\" at testing.go:5:9",
187
-
replacement: &result.Replacement{
188
-
Inline: &result.InlineFix{
189
-
StartCol: 8,
190
-
Length: 19,
191
-
NewString: "",
192
-
},
193
-
},
194
-
}},
195
-
},
196
-
{
197
-
desc: "needs unused with multiple specific linters generates a replacement for each linter",
198
-
needs: NeedsUnused,
199
-
contents: `
200
-
package bar
201
-
202
-
func foo() {
203
-
bad() //nolint:linter1,linter2,linter3
204
190
}`,
205
191
expected: []issueWithReplacement{
206
192
{
207
-
issue: "directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter1\" at testing.go:5:9",
208
-
replacement: &result.Replacement{
209
-
Inline: &result.InlineFix{
210
-
StartCol: 17,
211
-
Length: 8,
212
-
NewString: "",
213
-
},
214
-
},
215
-
},
216
-
{
217
-
issue: "directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter2\" at testing.go:5:9",
218
-
replacement: &result.Replacement{
219
-
Inline: &result.InlineFix{
220
-
StartCol: 25,
221
-
Length: 8,
222
-
NewString: "",
223
-
},
224
-
},
225
-
},
226
-
{
227
-
issue: "directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter3\" at testing.go:5:9",
228
-
replacement: &result.Replacement{
193
+
"directive `//nolint:somelinter` is unused for linter \"somelinter\" at testing.go:5:9",
194
+
&result.Replacement{
229
195
Inline: &result.InlineFix{
230
-
StartCol: 33,
231
-
Length: 7,
196
+
StartCol: 8,
197
+
Length: 19,
232
198
NewString: "",
233
199
},
234
200
},
235
201
},
236
202
},
237
203
},
238
204
{
239
-
desc: "needs unused with multiple specific linters generates a replacement preserving space after commas",
205
+
desc: "needs unused with multiple specific linters does not generate replacements",
240
206
needs: NeedsUnused,
241
207
contents: `
242
208
package bar
243
209
244
210
func foo() {
245
-
good() //nolint:linter1,linter2
211
+
bad() //nolint:linter1,linter2
246
212
}`,
247
213
expected: []issueWithReplacement{
248
214
{
249
-
issue: "directive `//nolint:linter1, linter2` is unused for linter \"linter1\" at testing.go:5:10",
250
-
replacement: &result.Replacement{
251
-
Inline: &result.InlineFix{
252
-
StartCol: 18,
253
-
Length: 8,
254
-
NewString: "",
255
-
},
256
-
},
215
+
"directive `//nolint:linter1,linter2` is unused for linter \"linter1\" at testing.go:5:9",
216
+
nil,
257
217
},
258
218
{
259
-
issue: "directive `//nolint:linter1, linter2` is unused for linter \"linter2\" at testing.go:5:10",
260
-
replacement: &result.Replacement{
261
-
Inline: &result.InlineFix{
262
-
StartCol: 26,
263
-
Length: 8,
264
-
NewString: "",
265
-
},
266
-
},
219
+
"directive `//nolint:linter1,linter2` is unused for linter \"linter2\" at testing.go:5:9",
0 commit comments