@@ -39,19 +39,22 @@ func New(opts *Options) *analysis.Analyzer {
39
39
Requires : []* analysis.Analyzer {inspect .Analyzer },
40
40
Run : func (pass * analysis.Pass ) (any , error ) {
41
41
if opts .KVOnly && opts .AttrOnly {
42
- return nil , errors .New ("sloglint: incompatible options provided" )
42
+ return nil , fmt .Errorf ("sloglint: Options.KVOnly and Options.AttrOnly: %w" , errIncompatible )
43
+ }
44
+ switch opts .KeyNamingCase {
45
+ case "" , snakeCase , kebabCase , camelCase , pascalCase :
46
+ default :
47
+ return nil , fmt .Errorf ("sloglint: Options.KeyNamingCase=%s: %w" , opts .KeyNamingCase , errInvalidValue )
43
48
}
44
49
run (pass , opts )
45
50
return nil , nil
46
51
},
47
52
}
48
53
}
49
54
50
- const (
51
- snakeCase = "snake"
52
- kebabCase = "kebab"
53
- camelCase = "camel"
54
- pascalCase = "pascal"
55
+ var (
56
+ errIncompatible = errors .New ("incompatible options" )
57
+ errInvalidValue = errors .New ("invalid value" )
55
58
)
56
59
57
60
func flags (opts * Options ) flag.FlagSet {
@@ -72,13 +75,8 @@ func flags(opts *Options) flag.FlagSet {
72
75
boolVar (& opts .ArgsOnSepLines , "args-on-sep-lines" , "enforce putting arguments on separate lines" )
73
76
74
77
fs .Func ("key-naming-case" , "enforce a single key naming convention (snake|kebab|camel|pascal)" , func (s string ) error {
75
- switch s {
76
- case snakeCase , kebabCase , camelCase , pascalCase :
77
- opts .KeyNamingCase = s
78
- return nil
79
- default :
80
- return fmt .Errorf ("sloglint: -key-naming-case=%s: invalid value" , s )
81
- }
78
+ opts .KeyNamingCase = s
79
+ return nil
82
80
})
83
81
84
82
return * fs
@@ -118,6 +116,13 @@ var attrFuncs = map[string]struct{}{
118
116
"log/slog.Any" : {},
119
117
}
120
118
119
+ const (
120
+ snakeCase = "snake"
121
+ kebabCase = "kebab"
122
+ camelCase = "camel"
123
+ pascalCase = "pascal"
124
+ )
125
+
121
126
func run (pass * analysis.Pass , opts * Options ) {
122
127
visit := pass .ResultOf [inspect .Analyzer ].(* inspector.Inspector )
123
128
filter := []ast.Node {(* ast .CallExpr )(nil )}
0 commit comments