File tree Expand file tree Collapse file tree 5 files changed +28
-0
lines changed
Expand file tree Collapse file tree 5 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -1864,6 +1864,9 @@ linters-settings:
18641864 # Enforce using methods that accept a context.
18651865 # Default: false
18661866 context-only : true
1867+ # Enforce using static values for log messages.
1868+ # Default: false
1869+ static-msg : true
18671870 # Enforce using constants instead of raw keys.
18681871 # Default: false
18691872 no-raw-keys : true
Original file line number Diff line number Diff line change @@ -123,6 +123,7 @@ var defaultLintersSettings = LintersSettings{
123123 KVOnly : false ,
124124 AttrOnly : false ,
125125 ContextOnly : false ,
126+ StaticMsg : false ,
126127 NoRawKeys : false ,
127128 KeyNamingCase : "" ,
128129 ArgsOnSepLines : false ,
@@ -755,6 +756,7 @@ type SlogLintSettings struct {
755756 KVOnly bool `mapstructure:"kv-only"`
756757 AttrOnly bool `mapstructure:"attr-only"`
757758 ContextOnly bool `mapstructure:"context-only"`
759+ StaticMsg bool `mapstructure:"static-msg"`
758760 NoRawKeys bool `mapstructure:"no-raw-keys"`
759761 KeyNamingCase string `mapstructure:"key-naming-case"`
760762 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 {
1515 KVOnly : settings .KVOnly ,
1616 AttrOnly : settings .AttrOnly ,
1717 ContextOnly : settings .ContextOnly ,
18+ StaticMsg : settings .StaticMsg ,
1819 NoRawKeys : settings .NoRawKeys ,
1920 KeyNamingCase : settings .KeyNamingCase ,
2021 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