File tree 5 files changed +28
-0
lines changed
5 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -1864,6 +1864,9 @@ linters-settings:
1864
1864
# Enforce using methods that accept a context.
1865
1865
# Default: false
1866
1866
context-only : true
1867
+ # Enforce using static values for log messages.
1868
+ # Default: false
1869
+ static-msg : true
1867
1870
# Enforce using constants instead of raw keys.
1868
1871
# Default: false
1869
1872
no-raw-keys : true
Original file line number Diff line number Diff line change @@ -123,6 +123,7 @@ var defaultLintersSettings = LintersSettings{
123
123
KVOnly : false ,
124
124
AttrOnly : false ,
125
125
ContextOnly : false ,
126
+ StaticMsg : false ,
126
127
NoRawKeys : false ,
127
128
KeyNamingCase : "" ,
128
129
ArgsOnSepLines : false ,
@@ -755,6 +756,7 @@ type SlogLintSettings struct {
755
756
KVOnly bool `mapstructure:"kv-only"`
756
757
AttrOnly bool `mapstructure:"attr-only"`
757
758
ContextOnly bool `mapstructure:"context-only"`
759
+ StaticMsg bool `mapstructure:"static-msg"`
758
760
NoRawKeys bool `mapstructure:"no-raw-keys"`
759
761
KeyNamingCase string `mapstructure:"key-naming-case"`
760
762
ArgsOnSepLines bool `mapstructure:"args-on-sep-lines"`
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ func NewSlogLint(settings *config.SlogLintSettings) *goanalysis.Linter {
15
15
KVOnly : settings .KVOnly ,
16
16
AttrOnly : settings .AttrOnly ,
17
17
ContextOnly : settings .ContextOnly ,
18
+ StaticMsg : settings .StaticMsg ,
18
19
NoRawKeys : settings .NoRawKeys ,
19
20
KeyNamingCase : settings .KeyNamingCase ,
20
21
ArgsOnSepLines : settings .ArgsOnSepLines ,
Original file line number Diff line number Diff line change
1
+ linters-settings :
2
+ sloglint :
3
+ static-msg : true
Original file line number Diff line number Diff line change
1
+ //go:build go1.21
2
+
3
+ //golangcitest:args -Esloglint
4
+ //golangcitest:config_path testdata/configs/sloglint_static_msg.yml
5
+ package testdata
6
+
7
+ import (
8
+ "log/slog"
9
+ )
10
+
11
+ func test () {
12
+ slog .Info ("msg" )
13
+
14
+ const msg1 = "msg"
15
+ slog .Info (msg1 )
16
+
17
+ msg2 := "msg"
18
+ slog .Info (msg2 ) // want `message should be a string literal or a constant`
19
+ }
You can’t perform that action at this time.
0 commit comments