Skip to content

Commit f91ae30

Browse files
authored
Merge branch 'master' into dev-zerologlint-name-doc
2 parents d653fac + f269abe commit f91ae30

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

.golangci.reference.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff 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

pkg/config/linters_settings.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff 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"`

pkg/golinters/sloglint.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff 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,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
sloglint:
3+
static-msg: true

test/testdata/sloglint_static_msg.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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+
}

0 commit comments

Comments
 (0)