Skip to content

Commit

Permalink
build(deps): bump go-simpler.org/sloglint from 0.1.2 to 0.2.0 (#4166)
Browse files Browse the repository at this point in the history
  • Loading branch information
tmzane authored Nov 5, 2023
1 parent 2b7c777 commit f17fef3
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 5 deletions.
7 changes: 7 additions & 0 deletions .golangci.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1824,9 +1824,16 @@ linters-settings:
# Enforce using attributes only (incompatible with kv-only).
# Default: false
attr-only: true
# Enforce using methods that accept a context.
# Default: false
context-only: true
# Enforce using constants instead of raw keys.
# Default: false
no-raw-keys: true
# Enforce a single key naming convention.
# Values: snake, kebab, camel, pascal
# Default: ""
key-naming-case: snake
# Enforce putting arguments on separate lines.
# 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 @@ -120,7 +120,7 @@ require (
github.com/yeya24/promlinter v0.2.0
github.com/ykadowak/zerologlint v0.1.3
gitlab.com/bosi/decorder v0.4.1
go-simpler.org/sloglint v0.1.2
go-simpler.org/sloglint v0.2.0
go.tmz.dev/musttag v0.7.2
golang.org/x/exp v0.0.0-20230510235704-dd950f8aeaea
golang.org/x/tools v0.14.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum

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

12 changes: 8 additions & 4 deletions pkg/config/linters_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ var defaultLintersSettings = LintersSettings{
SlogLint: SlogLintSettings{
KVOnly: false,
AttrOnly: false,
ContextOnly: false,
NoRawKeys: false,
KeyNamingCase: "",
ArgsOnSepLines: false,
},
TagAlign: TagAlignSettings{
Expand Down Expand Up @@ -734,10 +736,12 @@ type RowsErrCheckSettings struct {
}

type SlogLintSettings struct {
KVOnly bool `mapstructure:"kv-only"`
AttrOnly bool `mapstructure:"attr-only"`
NoRawKeys bool `mapstructure:"no-raw-keys"`
ArgsOnSepLines bool `mapstructure:"args-on-sep-lines"`
KVOnly bool `mapstructure:"kv-only"`
AttrOnly bool `mapstructure:"attr-only"`
ContextOnly bool `mapstructure:"context-only"`
NoRawKeys bool `mapstructure:"no-raw-keys"`
KeyNamingCase string `mapstructure:"key-naming-case"`
ArgsOnSepLines bool `mapstructure:"args-on-sep-lines"`
}

type StaticCheckSettings struct {
Expand Down
2 changes: 2 additions & 0 deletions pkg/golinters/sloglint.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ func NewSlogLint(settings *config.SlogLintSettings) *goanalysis.Linter {
opts = &sloglint.Options{
KVOnly: settings.KVOnly,
AttrOnly: settings.AttrOnly,
ContextOnly: settings.ContextOnly,
NoRawKeys: settings.NoRawKeys,
KeyNamingCase: settings.KeyNamingCase,
ArgsOnSepLines: settings.ArgsOnSepLines,
}
}
Expand Down
3 changes: 3 additions & 0 deletions test/testdata/configs/sloglint_context_only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
linters-settings:
sloglint:
context-only: true
3 changes: 3 additions & 0 deletions test/testdata/configs/sloglint_key_naming_case.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
linters-settings:
sloglint:
key-naming-case: snake
16 changes: 16 additions & 0 deletions test/testdata/sloglint_context_only.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//go:build go1.21

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

import (
"context"
"log/slog"
)

func test() {
slog.InfoContext(context.Background(), "msg")

slog.Info("msg") // want `methods without a context should not be used`
}
24 changes: 24 additions & 0 deletions test/testdata/sloglint_key_naming_case.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build go1.21

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

import "log/slog"

const (
snakeKey = "foo_bar"
kebabKey = "foo-bar"
)

func test() {
slog.Info("msg", "foo_bar", 1)
slog.Info("msg", snakeKey, 1)
slog.Info("msg", slog.Int("foo_bar", 1))
slog.Info("msg", slog.Int(snakeKey, 1))

slog.Info("msg", "foo-bar", 1) // want `keys should be written in snake_case`
slog.Info("msg", kebabKey, 1) // want `keys should be written in snake_case`
slog.Info("msg", slog.Int("foo-bar", 1)) // want `keys should be written in snake_case`
slog.Info("msg", slog.Int(kebabKey, 1)) // want `keys should be written in snake_case`
}

0 comments on commit f17fef3

Please sign in to comment.