Skip to content

build(deps): bump go-simpler.org/sloglint from 0.6.0 to 0.7.0 #4718

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 19, 2024
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
17 changes: 17 additions & 0 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1995,39 +1995,56 @@ linters-settings:

sloglint:
# Enforce not mixing key-value pairs and attributes.
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#no-mixed-arguments
# Default: true
no-mixed-args: false
# Enforce using key-value pairs only (overrides no-mixed-args, incompatible with attr-only).
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#key-value-pairs-only
# Default: false
kv-only: true
# Enforce using attributes only (overrides no-mixed-args, incompatible with kv-only).
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#attributes-only
# Default: false
attr-only: true
# Enforce not using global loggers.
# Values:
# - "": disabled
# - "all": report all global loggers
# - "default": report only the default slog logger
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#no-global
# Default: ""
no-global: "all"
# Enforce using methods that accept a context.
# Values:
# - "": disabled
# - "all": report all contextless calls
# - "scope": report only if a context exists in the scope of the outermost function
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#context-only
# Default: ""
context: "all"
# Enforce using static values for log messages.
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#static-messages
# Default: false
static-msg: true
# Enforce using constants instead of raw keys.
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#no-raw-keys
# Default: false
no-raw-keys: true
# Enforce a single key naming convention.
# Values: snake, kebab, camel, pascal
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#key-naming-convention
# Default: ""
key-naming-case: snake
# Enforce not using specific keys.
# Default: []
forbidden-keys:
- time
- level
- msg
- source
- foo
# Enforce putting arguments on separate lines.
# https://github.com/go-simpler/sloglint?tab=readme-ov-file#forbidden-keys
# Default: false
args-on-sep-lines: true

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ require (
github.com/ykadowak/zerologlint v0.1.5
gitlab.com/bosi/decorder v0.4.2
go-simpler.org/musttag v0.12.2
go-simpler.org/sloglint v0.6.0
go-simpler.org/sloglint v0.7.0
go.uber.org/automaxprocs v1.5.3
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
golang.org/x/tools v0.21.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2468,6 +2468,13 @@
"type": "boolean",
"default": false
},
"forbidden-keys": {
"description": "Enforce not using specific keys.",
"type": "array",
"items": {
"type": "string"
}
},
"args-on-sep-lines": {
"description": "Enforce putting arguments on separate lines.",
"type": "boolean",
Expand Down
25 changes: 14 additions & 11 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ var defaultLintersSettings = LintersSettings{
AttrOnly: false,
NoGlobal: "",
Context: "",
ContextOnly: false,
StaticMsg: false,
NoRawKeys: false,
KeyNamingCase: "",
ForbiddenKeys: nil,
ArgsOnSepLines: false,
},
TagAlign: TagAlignSettings{
Expand Down Expand Up @@ -819,16 +819,19 @@ type RowsErrCheckSettings struct {
}

type SlogLintSettings struct {
NoMixedArgs bool `mapstructure:"no-mixed-args"`
KVOnly bool `mapstructure:"kv-only"`
AttrOnly bool `mapstructure:"attr-only"`
NoGlobal string `mapstructure:"no-global"`
Context string `mapstructure:"context"`
ContextOnly bool `mapstructure:"context-only"` // Deprecated: use Context instead.
StaticMsg bool `mapstructure:"static-msg"`
NoRawKeys bool `mapstructure:"no-raw-keys"`
KeyNamingCase string `mapstructure:"key-naming-case"`
ArgsOnSepLines bool `mapstructure:"args-on-sep-lines"`
NoMixedArgs bool `mapstructure:"no-mixed-args"`
KVOnly bool `mapstructure:"kv-only"`
AttrOnly bool `mapstructure:"attr-only"`
NoGlobal string `mapstructure:"no-global"`
Context string `mapstructure:"context"`
StaticMsg bool `mapstructure:"static-msg"`
NoRawKeys bool `mapstructure:"no-raw-keys"`
KeyNamingCase string `mapstructure:"key-naming-case"`
ForbiddenKeys []string `mapstructure:"forbidden-keys"`
ArgsOnSepLines bool `mapstructure:"args-on-sep-lines"`

// Deprecated: use Context instead.
ContextOnly bool `mapstructure:"context-only"`
}

type SpancheckSettings struct {
Expand Down
1 change: 1 addition & 0 deletions pkg/golinters/sloglint/sloglint.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func New(settings *config.SlogLintSettings) *goanalysis.Linter {
StaticMsg: settings.StaticMsg,
NoRawKeys: settings.NoRawKeys,
KeyNamingCase: settings.KeyNamingCase,
ForbiddenKeys: settings.ForbiddenKeys,
ArgsOnSepLines: settings.ArgsOnSepLines,
}
}
Expand Down
28 changes: 28 additions & 0 deletions pkg/golinters/sloglint/testdata/sloglint_forbidden_keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
//golangcitest:args -Esloglint
//golangcitest:config_path testdata/sloglint_forbidden_keys.yml
package testdata

import "log/slog"

const (
snakeKey = "foo_bar"
)

func tests() {
slog.Info("msg")
slog.Info("msg", "foo-bar", 1)
slog.Info("msg", "foo_bar", 1) // want `"foo_bar" key is forbidden and should not be used`
slog.Info("msg", snakeKey, 1) // want `"foo_bar" key is forbidden and should not be used`
slog.Info("msg", slog.Int("foo_bar", 1)) // want `"foo_bar" key is forbidden and should not be used`
slog.Info("msg", slog.Int(snakeKey, 1)) // want `"foo_bar" key is forbidden and should not be used`
slog.Info("msg", slog.Attr{})
slog.Info("msg", slog.Attr{"foo_bar", slog.IntValue(1)}) // want `"foo_bar" key is forbidden and should not be used`
slog.Info("msg", slog.Attr{snakeKey, slog.IntValue(1)}) // want `"foo_bar" key is forbidden and should not be used`
slog.Info("msg", slog.Attr{Key: "foo_bar"}) // want `"foo_bar" key is forbidden and should not be used`
slog.Info("msg", slog.Attr{Key: snakeKey}) // want `"foo_bar" key is forbidden and should not be used`
slog.Info("msg", slog.Attr{Key: "foo_bar", Value: slog.IntValue(1)}) // want `"foo_bar" key is forbidden and should not be used`
slog.Info("msg", slog.Attr{Key: snakeKey, Value: slog.IntValue(1)}) // want `"foo_bar" key is forbidden and should not be used`
slog.Info("msg", slog.Attr{Value: slog.IntValue(1), Key: "foo_bar"}) // want `"foo_bar" key is forbidden and should not be used`
slog.Info("msg", slog.Attr{Value: slog.IntValue(1), Key: snakeKey}) // want `"foo_bar" key is forbidden and should not be used`
slog.Info("msg", slog.Attr{Value: slog.IntValue(1), Key: `foo_bar`}) // want `"foo_bar" key is forbidden and should not be used`
}
4 changes: 4 additions & 0 deletions pkg/golinters/sloglint/testdata/sloglint_forbidden_keys.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
linters-settings:
sloglint:
forbidden-keys:
- foo_bar
Loading