Skip to content

Commit 2bd34f3

Browse files
tmzanepull[bot]
authored andcommitted
build(deps): bump go-simpler.org/sloglint from 0.1.2 to 0.2.0 (#4166)
1 parent 45d2e48 commit 2bd34f3

9 files changed

+66
-5
lines changed

.golangci.reference.yml

+7
Original file line numberDiff line numberDiff line change
@@ -1824,9 +1824,16 @@ linters-settings:
18241824
# Enforce using attributes only (incompatible with kv-only).
18251825
# Default: false
18261826
attr-only: true
1827+
# Enforce using methods that accept a context.
1828+
# Default: false
1829+
context-only: true
18271830
# Enforce using constants instead of raw keys.
18281831
# Default: false
18291832
no-raw-keys: true
1833+
# Enforce a single key naming convention.
1834+
# Values: snake, kebab, camel, pascal
1835+
# Default: ""
1836+
key-naming-case: snake
18301837
# Enforce putting arguments on separate lines.
18311838
# Default: false
18321839
args-on-sep-lines: true

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ require (
120120
github.com/yeya24/promlinter v0.2.0
121121
github.com/ykadowak/zerologlint v0.1.3
122122
gitlab.com/bosi/decorder v0.4.1
123-
go-simpler.org/sloglint v0.1.2
123+
go-simpler.org/sloglint v0.2.0
124124
go.tmz.dev/musttag v0.7.2
125125
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea
126126
golang.org/x/tools v0.14.0

go.sum

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

pkg/config/linters_settings.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,9 @@ var defaultLintersSettings = LintersSettings{
119119
SlogLint: SlogLintSettings{
120120
KVOnly: false,
121121
AttrOnly: false,
122+
ContextOnly: false,
122123
NoRawKeys: false,
124+
KeyNamingCase: "",
123125
ArgsOnSepLines: false,
124126
},
125127
TagAlign: TagAlignSettings{
@@ -734,10 +736,12 @@ type RowsErrCheckSettings struct {
734736
}
735737

736738
type SlogLintSettings struct {
737-
KVOnly bool `mapstructure:"kv-only"`
738-
AttrOnly bool `mapstructure:"attr-only"`
739-
NoRawKeys bool `mapstructure:"no-raw-keys"`
740-
ArgsOnSepLines bool `mapstructure:"args-on-sep-lines"`
739+
KVOnly bool `mapstructure:"kv-only"`
740+
AttrOnly bool `mapstructure:"attr-only"`
741+
ContextOnly bool `mapstructure:"context-only"`
742+
NoRawKeys bool `mapstructure:"no-raw-keys"`
743+
KeyNamingCase string `mapstructure:"key-naming-case"`
744+
ArgsOnSepLines bool `mapstructure:"args-on-sep-lines"`
741745
}
742746

743747
type StaticCheckSettings struct {

pkg/golinters/sloglint.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ func NewSlogLint(settings *config.SlogLintSettings) *goanalysis.Linter {
1414
opts = &sloglint.Options{
1515
KVOnly: settings.KVOnly,
1616
AttrOnly: settings.AttrOnly,
17+
ContextOnly: settings.ContextOnly,
1718
NoRawKeys: settings.NoRawKeys,
19+
KeyNamingCase: settings.KeyNamingCase,
1820
ArgsOnSepLines: settings.ArgsOnSepLines,
1921
}
2022
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
sloglint:
3+
context-only: true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
linters-settings:
2+
sloglint:
3+
key-naming-case: snake
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//go:build go1.21
2+
3+
//golangcitest:args -Esloglint
4+
//golangcitest:config_path testdata/configs/sloglint_context_only.yml
5+
package testdata
6+
7+
import (
8+
"context"
9+
"log/slog"
10+
)
11+
12+
func test() {
13+
slog.InfoContext(context.Background(), "msg")
14+
15+
slog.Info("msg") // want `methods without a context should not be used`
16+
}
+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//go:build go1.21
2+
3+
//golangcitest:args -Esloglint
4+
//golangcitest:config_path testdata/configs/sloglint_key_naming_case.yml
5+
package testdata
6+
7+
import "log/slog"
8+
9+
const (
10+
snakeKey = "foo_bar"
11+
kebabKey = "foo-bar"
12+
)
13+
14+
func test() {
15+
slog.Info("msg", "foo_bar", 1)
16+
slog.Info("msg", snakeKey, 1)
17+
slog.Info("msg", slog.Int("foo_bar", 1))
18+
slog.Info("msg", slog.Int(snakeKey, 1))
19+
20+
slog.Info("msg", "foo-bar", 1) // want `keys should be written in snake_case`
21+
slog.Info("msg", kebabKey, 1) // want `keys should be written in snake_case`
22+
slog.Info("msg", slog.Int("foo-bar", 1)) // want `keys should be written in snake_case`
23+
slog.Info("msg", slog.Int(kebabKey, 1)) // want `keys should be written in snake_case`
24+
}

0 commit comments

Comments
 (0)