Skip to content

Commit be1bb6d

Browse files
build(deps): bump go-simpler.org/sloglint from 0.6.0 to 0.7.0 (#4718)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent d94cbbf commit be1bb6d

File tree

8 files changed

+74
-14
lines changed

8 files changed

+74
-14
lines changed

.golangci.next.reference.yml

+17
Original file line numberDiff line numberDiff line change
@@ -1997,39 +1997,56 @@ linters-settings:
19971997

19981998
sloglint:
19991999
# Enforce not mixing key-value pairs and attributes.
2000+
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#no-mixed-arguments
20002001
# Default: true
20012002
no-mixed-args: false
20022003
# Enforce using key-value pairs only (overrides no-mixed-args, incompatible with attr-only).
2004+
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#key-value-pairs-only
20032005
# Default: false
20042006
kv-only: true
20052007
# Enforce using attributes only (overrides no-mixed-args, incompatible with kv-only).
2008+
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#attributes-only
20062009
# Default: false
20072010
attr-only: true
20082011
# Enforce not using global loggers.
20092012
# Values:
20102013
# - "": disabled
20112014
# - "all": report all global loggers
20122015
# - "default": report only the default slog logger
2016+
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#no-global
20132017
# Default: ""
20142018
no-global: "all"
20152019
# Enforce using methods that accept a context.
20162020
# Values:
20172021
# - "": disabled
20182022
# - "all": report all contextless calls
20192023
# - "scope": report only if a context exists in the scope of the outermost function
2024+
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#context-only
20202025
# Default: ""
20212026
context: "all"
20222027
# Enforce using static values for log messages.
2028+
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#static-messages
20232029
# Default: false
20242030
static-msg: true
20252031
# Enforce using constants instead of raw keys.
2032+
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#no-raw-keys
20262033
# Default: false
20272034
no-raw-keys: true
20282035
# Enforce a single key naming convention.
20292036
# Values: snake, kebab, camel, pascal
2037+
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#key-naming-convention
20302038
# Default: ""
20312039
key-naming-case: snake
2040+
# Enforce not using specific keys.
2041+
# Default: []
2042+
forbidden-keys:
2043+
- time
2044+
- level
2045+
- msg
2046+
- source
2047+
- foo
20322048
# Enforce putting arguments on separate lines.
2049+
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#forbidden-keys
20332050
# Default: false
20342051
args-on-sep-lines: true
20352052

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ require (
122122
github.com/ykadowak/zerologlint v0.1.5
123123
gitlab.com/bosi/decorder v0.4.2
124124
go-simpler.org/musttag v0.12.2
125-
go-simpler.org/sloglint v0.6.0
125+
go-simpler.org/sloglint v0.7.0
126126
go.uber.org/automaxprocs v1.5.3
127127
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
128128
golang.org/x/tools v0.21.0

go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jsonschema/golangci.next.jsonschema.json

+7
Original file line numberDiff line numberDiff line change
@@ -2468,6 +2468,13 @@
24682468
"type": "boolean",
24692469
"default": false
24702470
},
2471+
"forbidden-keys": {
2472+
"description": "Enforce not using specific keys.",
2473+
"type": "array",
2474+
"items": {
2475+
"type": "string"
2476+
}
2477+
},
24712478
"args-on-sep-lines": {
24722479
"description": "Enforce putting arguments on separate lines.",
24732480
"type": "boolean",

pkg/config/linters_settings.go

+14-11
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ var defaultLintersSettings = LintersSettings{
146146
AttrOnly: false,
147147
NoGlobal: "",
148148
Context: "",
149-
ContextOnly: false,
150149
StaticMsg: false,
151150
NoRawKeys: false,
152151
KeyNamingCase: "",
152+
ForbiddenKeys: nil,
153153
ArgsOnSepLines: false,
154154
},
155155
TagAlign: TagAlignSettings{
@@ -819,16 +819,19 @@ type RowsErrCheckSettings struct {
819819
}
820820

821821
type SlogLintSettings struct {
822-
NoMixedArgs bool `mapstructure:"no-mixed-args"`
823-
KVOnly bool `mapstructure:"kv-only"`
824-
AttrOnly bool `mapstructure:"attr-only"`
825-
NoGlobal string `mapstructure:"no-global"`
826-
Context string `mapstructure:"context"`
827-
ContextOnly bool `mapstructure:"context-only"` // Deprecated: use Context instead.
828-
StaticMsg bool `mapstructure:"static-msg"`
829-
NoRawKeys bool `mapstructure:"no-raw-keys"`
830-
KeyNamingCase string `mapstructure:"key-naming-case"`
831-
ArgsOnSepLines bool `mapstructure:"args-on-sep-lines"`
822+
NoMixedArgs bool `mapstructure:"no-mixed-args"`
823+
KVOnly bool `mapstructure:"kv-only"`
824+
AttrOnly bool `mapstructure:"attr-only"`
825+
NoGlobal string `mapstructure:"no-global"`
826+
Context string `mapstructure:"context"`
827+
StaticMsg bool `mapstructure:"static-msg"`
828+
NoRawKeys bool `mapstructure:"no-raw-keys"`
829+
KeyNamingCase string `mapstructure:"key-naming-case"`
830+
ForbiddenKeys []string `mapstructure:"forbidden-keys"`
831+
ArgsOnSepLines bool `mapstructure:"args-on-sep-lines"`
832+
833+
// Deprecated: use Context instead.
834+
ContextOnly bool `mapstructure:"context-only"`
832835
}
833836

834837
type SpancheckSettings struct {

pkg/golinters/sloglint/sloglint.go

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func New(settings *config.SlogLintSettings) *goanalysis.Linter {
2020
StaticMsg: settings.StaticMsg,
2121
NoRawKeys: settings.NoRawKeys,
2222
KeyNamingCase: settings.KeyNamingCase,
23+
ForbiddenKeys: settings.ForbiddenKeys,
2324
ArgsOnSepLines: settings.ArgsOnSepLines,
2425
}
2526
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//golangcitest:args -Esloglint
2+
//golangcitest:config_path testdata/sloglint_forbidden_keys.yml
3+
package testdata
4+
5+
import "log/slog"
6+
7+
const (
8+
snakeKey = "foo_bar"
9+
)
10+
11+
func tests() {
12+
slog.Info("msg")
13+
slog.Info("msg", "foo-bar", 1)
14+
slog.Info("msg", "foo_bar", 1) // want `"foo_bar" key is forbidden and should not be used`
15+
slog.Info("msg", snakeKey, 1) // want `"foo_bar" key is forbidden and should not be used`
16+
slog.Info("msg", slog.Int("foo_bar", 1)) // want `"foo_bar" key is forbidden and should not be used`
17+
slog.Info("msg", slog.Int(snakeKey, 1)) // want `"foo_bar" key is forbidden and should not be used`
18+
slog.Info("msg", slog.Attr{})
19+
slog.Info("msg", slog.Attr{"foo_bar", slog.IntValue(1)}) // want `"foo_bar" key is forbidden and should not be used`
20+
slog.Info("msg", slog.Attr{snakeKey, slog.IntValue(1)}) // want `"foo_bar" key is forbidden and should not be used`
21+
slog.Info("msg", slog.Attr{Key: "foo_bar"}) // want `"foo_bar" key is forbidden and should not be used`
22+
slog.Info("msg", slog.Attr{Key: snakeKey}) // want `"foo_bar" key is forbidden and should not be used`
23+
slog.Info("msg", slog.Attr{Key: "foo_bar", Value: slog.IntValue(1)}) // want `"foo_bar" key is forbidden and should not be used`
24+
slog.Info("msg", slog.Attr{Key: snakeKey, Value: slog.IntValue(1)}) // want `"foo_bar" key is forbidden and should not be used`
25+
slog.Info("msg", slog.Attr{Value: slog.IntValue(1), Key: "foo_bar"}) // want `"foo_bar" key is forbidden and should not be used`
26+
slog.Info("msg", slog.Attr{Value: slog.IntValue(1), Key: snakeKey}) // want `"foo_bar" key is forbidden and should not be used`
27+
slog.Info("msg", slog.Attr{Value: slog.IntValue(1), Key: `foo_bar`}) // want `"foo_bar" key is forbidden and should not be used`
28+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
linters-settings:
2+
sloglint:
3+
forbidden-keys:
4+
- foo_bar

0 commit comments

Comments
 (0)