Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1864,6 +1864,9 @@ linters-settings:
# Enforce using methods that accept a context.
# Default: false
context-only: true
# Enforce using static values for log messages.
# Default: false
static-msg: true
# Enforce using constants instead of raw keys.
# Default: false
no-raw-keys: true
Expand Down
2 changes: 2 additions & 0 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ var defaultLintersSettings = LintersSettings{
KVOnly: false,
AttrOnly: false,
ContextOnly: false,
StaticMsg: false,
NoRawKeys: false,
KeyNamingCase: "",
ArgsOnSepLines: false,
Expand Down Expand Up @@ -755,6 +756,7 @@ type SlogLintSettings struct {
KVOnly bool `mapstructure:"kv-only"`
AttrOnly bool `mapstructure:"attr-only"`
ContextOnly bool `mapstructure:"context-only"`
StaticMsg bool `mapstructure:"static-msg"`
NoRawKeys bool `mapstructure:"no-raw-keys"`
KeyNamingCase string `mapstructure:"key-naming-case"`
ArgsOnSepLines bool `mapstructure:"args-on-sep-lines"`
Expand Down
1 change: 1 addition & 0 deletions pkg/golinters/sloglint.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func NewSlogLint(settings *config.SlogLintSettings) *goanalysis.Linter {
KVOnly: settings.KVOnly,
AttrOnly: settings.AttrOnly,
ContextOnly: settings.ContextOnly,
StaticMsg: settings.StaticMsg,
NoRawKeys: settings.NoRawKeys,
KeyNamingCase: settings.KeyNamingCase,
ArgsOnSepLines: settings.ArgsOnSepLines,
Expand Down
3 changes: 3 additions & 0 deletions test/testdata/configs/sloglint_static_msg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
linters-settings:
sloglint:
static-msg: true
19 changes: 19 additions & 0 deletions test/testdata/sloglint_static_msg.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//go:build go1.21

//golangcitest:args -Esloglint
//golangcitest:config_path testdata/configs/sloglint_static_msg.yml
package testdata

import (
"log/slog"
)

func test() {
slog.Info("msg")

const msg1 = "msg"
slog.Info(msg1)

msg2 := "msg"
slog.Info(msg2) // want `message should be a string literal or a constant`
}