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
+50-58Lines changed: 50 additions & 58 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
-
{"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},
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"},
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
-
{"directive `//nolint:dupl` should provide explanation such as `//nolint:dupl // this is why` at testing.go:6:1", nil},
60
+
{issue: "directive `//nolint:dupl` should provide explanation such as `//nolint:dupl // this is why` at testing.go:6:1"},
61
61
},
62
62
},
63
63
{
@@ -83,8 +83,8 @@ func foo() {
83
83
bad() // nolint // because
84
84
}`,
85
85
expected: []issueWithReplacement{
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},
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"},
88
88
},
89
89
},
90
90
{
@@ -97,18 +97,16 @@ func foo() {
97
97
bad() // nolint
98
98
good() //nolint
99
99
}`,
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
-
},
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: "",
109
107
},
110
108
},
111
-
},
109
+
}},
112
110
},
113
111
{
114
112
desc: "extra spaces in front of directive are reported",
@@ -119,18 +117,16 @@ func foo() {
119
117
bad() // nolint
120
118
good() // nolint
121
119
}`,
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
-
},
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: " ",
131
127
},
132
128
},
133
-
},
129
+
}},
134
130
},
135
131
{
136
132
desc: "spaces are allowed in comma-separated list of linters",
@@ -144,7 +140,7 @@ func foo() {
144
140
good() // nolint: linter1, linter2
145
141
}`,
146
142
expected: []issueWithReplacement{
147
-
{"directive `// nolint:linter1 linter2` should match `// nolint[:<comma-separated-linters>] [// <explanation>]` at testing.go:6:9", nil}, //nolint:lll // this is a string
143
+
{issue: "directive `// nolint:linter1 linter2` should match `// nolint[:<comma-separated-linters>] [// <explanation>]` at testing.go:6:9"}, //nolint:lll // this is a string
148
144
},
149
145
},
150
146
{
@@ -166,18 +162,16 @@ package bar
166
162
func foo() {
167
163
bad() //nolint
168
164
}`,
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
-
},
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: "",
178
172
},
179
173
},
180
-
},
174
+
}},
181
175
},
182
176
{
183
177
desc: "needs unused with one specific linter generates replacement",
@@ -188,18 +182,16 @@ package bar
188
182
func foo() {
189
183
bad() //nolint:somelinter
190
184
}`,
191
-
expected: []issueWithReplacement{
192
-
{
193
-
"directive `//nolint:somelinter` is unused for linter \"somelinter\" at testing.go:5:9",
194
-
&result.Replacement{
195
-
Inline: &result.InlineFix{
196
-
StartCol: 8,
197
-
Length: 19,
198
-
NewString: "",
199
-
},
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: "",
200
192
},
201
193
},
202
-
},
194
+
}},
203
195
},
204
196
{
205
197
desc: "needs unused with multiple specific linters generates a replacement for each linter",
@@ -212,8 +204,8 @@ func foo() {
212
204
}`,
213
205
expected: []issueWithReplacement{
214
206
{
215
-
"directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter1\" at testing.go:5:9",
216
-
&result.Replacement{
207
+
issue: "directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter1\" at testing.go:5:9",
208
+
replacement: &result.Replacement{
217
209
Inline: &result.InlineFix{
218
210
StartCol: 17,
219
211
Length: 8,
@@ -222,8 +214,8 @@ func foo() {
222
214
},
223
215
},
224
216
{
225
-
"directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter2\" at testing.go:5:9",
226
-
&result.Replacement{
217
+
issue: "directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter2\" at testing.go:5:9",
218
+
replacement: &result.Replacement{
227
219
Inline: &result.InlineFix{
228
220
StartCol: 25,
229
221
Length: 8,
@@ -232,8 +224,8 @@ func foo() {
232
224
},
233
225
},
234
226
{
235
-
"directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter3\" at testing.go:5:9",
236
-
&result.Replacement{
227
+
issue: "directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter3\" at testing.go:5:9",
228
+
replacement: &result.Replacement{
237
229
Inline: &result.InlineFix{
238
230
StartCol: 33,
239
231
Length: 7,
@@ -254,8 +246,8 @@ func foo() {
254
246
}`,
255
247
expected: []issueWithReplacement{
256
248
{
257
-
"directive `//nolint:linter1, linter2` is unused for linter \"linter1\" at testing.go:5:10",
258
-
&result.Replacement{
249
+
issue: "directive `//nolint:linter1, linter2` is unused for linter \"linter1\" at testing.go:5:10",
250
+
replacement: &result.Replacement{
259
251
Inline: &result.InlineFix{
260
252
StartCol: 18,
261
253
Length: 8,
@@ -264,8 +256,8 @@ func foo() {
264
256
},
265
257
},
266
258
{
267
-
"directive `//nolint:linter1, linter2` is unused for linter \"linter2\" at testing.go:5:10",
268
-
&result.Replacement{
259
+
issue: "directive `//nolint:linter1, linter2` is unused for linter \"linter2\" at testing.go:5:10",
0 commit comments