5
5
"go/ast"
6
6
"go/types"
7
7
"path/filepath"
8
+ "reflect"
8
9
"runtime"
9
10
"sort"
10
11
"strings"
@@ -87,7 +88,7 @@ func configureCheckerInfo(info *gocriticlinter.CheckerInfo, allParams map[string
87
88
for k , p := range params {
88
89
v , ok := infoParams [k ]
89
90
if ok {
90
- v .Value = p
91
+ v .Value = normalizeCheckerParamsValue ( p )
91
92
continue
92
93
}
93
94
@@ -110,6 +111,26 @@ func configureCheckerInfo(info *gocriticlinter.CheckerInfo, allParams map[string
110
111
return nil
111
112
}
112
113
114
+ // normalizeCheckerParamsValue normalizes value types.
115
+ // go-critic asserts that CheckerParam.Value has some specific types,
116
+ // but the file parsers (TOML, YAML, JSON) don't create the same representation for raw type.
117
+ // then we have to convert value types into the expected value types.
118
+ // Maybe in the future, this kind of conversion will be done in go-critic itself.
119
+ //nolint:exhaustive // only 3 types (int, bool, and string) are supported by CheckerParam.Value
120
+ func normalizeCheckerParamsValue (p interface {}) interface {} {
121
+ rv := reflect .ValueOf (p )
122
+ switch rv .Type ().Kind () {
123
+ case reflect .Int64 , reflect .Int32 , reflect .Int16 , reflect .Int8 , reflect .Int :
124
+ return int (rv .Int ())
125
+ case reflect .Bool :
126
+ return rv .Bool ()
127
+ case reflect .String :
128
+ return rv .String ()
129
+ default :
130
+ return p
131
+ }
132
+ }
133
+
113
134
func buildEnabledCheckers (lintCtx * linter.Context , linterCtx * gocriticlinter.Context ) ([]* gocriticlinter.Checker , error ) {
114
135
s := lintCtx .Settings ().Gocritic
115
136
allParams := s .GetLowercasedParams ()
0 commit comments