@@ -13,16 +13,20 @@ import (
13
13
reviveConfig "github.com/mgechev/revive/config"
14
14
"github.com/mgechev/revive/lint"
15
15
"github.com/mgechev/revive/rule"
16
+ "github.com/pkg/errors"
16
17
"golang.org/x/tools/go/analysis"
17
18
18
19
"github.com/golangci/golangci-lint/pkg/config"
19
20
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
20
21
"github.com/golangci/golangci-lint/pkg/lint/linter"
22
+ "github.com/golangci/golangci-lint/pkg/logutils"
21
23
"github.com/golangci/golangci-lint/pkg/result"
22
24
)
23
25
24
26
const reviveName = "revive"
25
27
28
+ var reviveDebugf = logutils .Debug ("revive" )
29
+
26
30
// jsonObject defines a JSON object of an failure
27
31
type jsonObject struct {
28
32
Severity lint.Severity
@@ -145,18 +149,20 @@ func getReviveConfig(cfg *config.ReviveSettings) (*lint.Config, error) {
145
149
146
150
err := toml .NewEncoder (buf ).Encode (rawRoot )
147
151
if err != nil {
148
- return nil , err
152
+ return nil , errors . Wrap ( err , "failed to encode configuration" )
149
153
}
150
154
151
155
conf = & lint.Config {}
152
156
_ , err = toml .DecodeReader (buf , conf )
153
157
if err != nil {
154
- return nil , err
158
+ return nil , errors . Wrap ( err , "failed to decode configuration" )
155
159
}
156
160
}
157
161
158
162
normalizeConfig (conf )
159
163
164
+ reviveDebugf ("revive configuration: %#v" , conf )
165
+
160
166
return conf , nil
161
167
}
162
168
@@ -184,7 +190,7 @@ func createConfigMap(cfg *config.ReviveSettings) map[string]interface{} {
184
190
for _ , s := range cfg .Rules {
185
191
rawRules [s .Name ] = map [string ]interface {}{
186
192
"severity" : s .Severity ,
187
- "arguments" : s .Arguments ,
193
+ "arguments" : safeTomlSlice ( s .Arguments ) ,
188
194
}
189
195
}
190
196
@@ -195,6 +201,28 @@ func createConfigMap(cfg *config.ReviveSettings) map[string]interface{} {
195
201
return rawRoot
196
202
}
197
203
204
+ func safeTomlSlice (r []interface {}) []interface {} {
205
+ if len (r ) == 0 {
206
+ return nil
207
+ }
208
+
209
+ if _ , ok := r [0 ].(map [interface {}]interface {}); ! ok {
210
+ return r
211
+ }
212
+
213
+ var typed []interface {}
214
+ for _ , elt := range r {
215
+ item := map [string ]interface {}{}
216
+ for k , v := range elt .(map [interface {}]interface {}) {
217
+ item [k .(string )] = v
218
+ }
219
+
220
+ typed = append (typed , item )
221
+ }
222
+
223
+ return typed
224
+ }
225
+
198
226
// This element is not exported by revive, so we need copy the code.
199
227
// Extracted from https://github.com/mgechev/revive/blob/389ba853b0b3587f0c3b71b5f0c61ea4e23928ec/config/config.go#L15
200
228
var defaultRules = []lint.Rule {
0 commit comments