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
Revert "Update nolintlint to fix nolint formatting and remove unused nolint statements (#1573)" (#1584)
This reverts commit aeb9830.
There are some cases that nolinter fixer wasn't handling properly or expectedly (#1579, #1580, #1581) so we'll fix those in a new attempt.
Copy file name to clipboardExpand all lines: pkg/golinters/nolintlint/nolintlint_test.go
+20-134
Original file line number
Diff line number
Diff line change
@@ -7,22 +7,16 @@ import (
7
7
8
8
"github.com/stretchr/testify/assert"
9
9
"github.com/stretchr/testify/require"
10
-
11
-
"github.com/golangci/golangci-lint/pkg/result"
12
10
)
13
11
14
12
//nolint:funlen
15
13
funcTestNoLintLint(t*testing.T) {
16
-
typeissueWithReplacementstruct {
17
-
issuestring
18
-
replacement*result.Replacement
19
-
}
20
14
testCases:= []struct {
21
15
descstring
22
16
needsNeeds
23
17
excludes []string
24
18
contentsstring
25
-
expected []issueWithReplacement
19
+
expected []string
26
20
}{
27
21
{
28
22
desc: "when no explanation is provided",
@@ -39,11 +33,11 @@ func foo() {
39
33
good() //nolint // this is ok
40
34
other() //nolintother
41
35
}`,
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},
36
+
expected: []string{
37
+
"directive `//nolint` should provide explanation such as `//nolint // this is why` at testing.go:5:1",
38
+
"directive `//nolint` should provide explanation such as `//nolint // this is why` at testing.go:7:9",
39
+
"directive `//nolint //` should provide explanation such as `//nolint // this is why` at testing.go:8:9",
40
+
"directive `//nolint // ` should provide explanation such as `//nolint // this is why` at testing.go:9:9",
47
41
},
48
42
},
49
43
{
@@ -56,8 +50,8 @@ package bar
56
50
//nolint // this is ok
57
51
//nolint:dupl
58
52
func foo() {}`,
59
-
expected: []issueWithReplacement{
60
-
{"directive `//nolint:dupl` should provide explanation such as `//nolint:dupl // this is why` at testing.go:6:1", nil},
53
+
expected: []string{
54
+
"directive `//nolint:dupl` should provide explanation such as `//nolint:dupl // this is why` at testing.go:6:1",
61
55
},
62
56
},
63
57
{
@@ -82,9 +76,9 @@ func foo() {
82
76
bad() //nolint
83
77
bad() // nolint // because
84
78
}`,
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},
79
+
expected: []string{
80
+
"directive `//nolint` should mention specific linter such as `//nolint:my-linter` at testing.go:6:9",
81
+
"directive `// nolint // because` should mention specific linter such as `// nolint:my-linter` at testing.go:7:9",
88
82
},
89
83
},
90
84
{
@@ -97,17 +91,8 @@ func foo() {
97
91
bad() // nolint
98
92
good() //nolint
99
93
}`,
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: 8,
106
-
Length: 3,
107
-
NewString: "//",
108
-
},
109
-
},
110
-
},
94
+
expected: []string{
95
+
"directive `// nolint` should be written without leading space as `//nolint` at testing.go:5:9",
111
96
},
112
97
},
113
98
{
@@ -119,17 +104,8 @@ func foo() {
119
104
bad() // nolint
120
105
good() // nolint
121
106
}`,
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: 8,
128
-
Length: 4,
129
-
NewString: "//",
130
-
},
131
-
},
132
-
},
107
+
expected: []string{
108
+
"directive `// nolint` should not have more than one leading space at testing.go:5:9",
133
109
},
134
110
},
135
111
{
@@ -143,8 +119,8 @@ func foo() {
143
119
good() // nolint: linter1,linter2
144
120
good() // nolint: linter1, linter2
145
121
}`,
146
-
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
122
+
expected: []string{
123
+
"directive `// nolint:linter1 linter2` should match `// nolint[:<comma-separated-linters>] [// <explanation>]` at testing.go:6:9", //nolint:lll // this is a string
148
124
},
149
125
},
150
126
{
@@ -157,92 +133,6 @@ func foo() {
157
133
// something else
158
134
}`,
159
135
},
160
-
{
161
-
desc: "needs unused without specific linter generates replacement",
162
-
needs: NeedsUnused,
163
-
contents: `
164
-
package bar
165
-
166
-
func foo() {
167
-
bad() //nolint
168
-
}`,
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
-
},
178
-
},
179
-
},
180
-
},
181
-
},
182
-
{
183
-
desc: "needs unused with one specific linter generates replacement",
184
-
needs: NeedsUnused,
185
-
contents: `
186
-
package bar
187
-
188
-
func foo() {
189
-
bad() //nolint:somelinter
190
-
}`,
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
-
},
200
-
},
201
-
},
202
-
},
203
-
},
204
-
{
205
-
desc: "needs unused with multiple specific linter generates replacement for each linter",
206
-
needs: NeedsUnused,
207
-
contents: `
208
-
package bar
209
-
210
-
func foo() {
211
-
bad() //nolint:linter1,linter2,linter3
212
-
}`,
213
-
expected: []issueWithReplacement{
214
-
{
215
-
"directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter1\" at testing.go:5:9",
216
-
&result.Replacement{
217
-
Inline: &result.InlineFix{
218
-
StartCol: 17,
219
-
Length: 22,
220
-
NewString: "linter2,linter3",
221
-
},
222
-
},
223
-
},
224
-
{
225
-
"directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter2\" at testing.go:5:9",
226
-
&result.Replacement{
227
-
Inline: &result.InlineFix{
228
-
StartCol: 17,
229
-
Length: 22,
230
-
NewString: "linter1,linter3",
231
-
},
232
-
},
233
-
},
234
-
{
235
-
"directive `//nolint:linter1,linter2,linter3` is unused for linter \"linter3\" at testing.go:5:9",
0 commit comments