-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
157 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package golinters | ||
|
||
import ( | ||
"go-simpler.org/sloglint" | ||
"golang.org/x/tools/go/analysis" | ||
|
||
"github.com/golangci/golangci-lint/pkg/config" | ||
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis" | ||
) | ||
|
||
func NewSlogLint(settings *config.SlogLintSettings) *goanalysis.Linter { | ||
var opts *sloglint.Options | ||
if settings != nil { | ||
opts = &sloglint.Options{ | ||
KVOnly: settings.KVOnly, | ||
AttrOnly: settings.AttrOnly, | ||
NoRawKeys: settings.NoRawKeys, | ||
ArgsOnSepLines: settings.ArgsOnSepLines, | ||
} | ||
} | ||
|
||
a := sloglint.New(opts) | ||
|
||
return goanalysis. | ||
NewLinter(a.Name, a.Doc, []*analysis.Analyzer{a}, nil). | ||
WithLoadMode(goanalysis.LoadModeTypesInfo) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
linters-settings: | ||
sloglint: | ||
args-on-sep-lines: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
linters-settings: | ||
sloglint: | ||
attr-only: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
linters-settings: | ||
sloglint: | ||
kv-only: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
linters-settings: | ||
sloglint: | ||
no-raw-keys: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//go:build go1.21 | ||
|
||
//golangcitest:args -Esloglint | ||
package testdata | ||
|
||
import "log/slog" | ||
|
||
func test() { | ||
slog.Info("msg", "foo", 1, "bar", 2) | ||
slog.Info("msg", slog.Int("foo", 1), slog.Int("bar", 2)) | ||
|
||
slog.Info("msg", "foo", 1, slog.Int("bar", 2)) // want `key-value pairs and attributes should not be mixed` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//go:build go1.21 | ||
|
||
//golangcitest:args -Esloglint | ||
//golangcitest:config_path testdata/configs/sloglint_args_on_sep_lines.yml | ||
package testdata | ||
|
||
import "log/slog" | ||
|
||
func test() { | ||
slog.Info("msg", "foo", 1) | ||
slog.Info("msg", | ||
"foo", 1, | ||
"bar", 2, | ||
) | ||
|
||
slog.Info("msg", "foo", 1, "bar", 2) // want `arguments should be put on separate lines` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//go:build go1.21 | ||
|
||
//golangcitest:args -Esloglint | ||
//golangcitest:config_path testdata/configs/sloglint_attr_only.yml | ||
package testdata | ||
|
||
import "log/slog" | ||
|
||
func test() { | ||
slog.Info("msg", slog.Int("foo", 1), slog.Int("bar", 2)) | ||
|
||
slog.Info("msg", "foo", 1, "bar", 2) // want `key-value pairs should not be used` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
//go:build go1.21 | ||
|
||
//golangcitest:args -Esloglint | ||
//golangcitest:config_path testdata/configs/sloglint_kv_only.yml | ||
package testdata | ||
|
||
import "log/slog" | ||
|
||
func test() { | ||
slog.Info("msg", "foo", 1, "bar", 2) | ||
|
||
slog.Info("msg", slog.Int("foo", 1), slog.Int("bar", 2)) // want `attributes should not be used` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
//go:build go1.21 | ||
|
||
//golangcitest:args -Esloglint | ||
//golangcitest:config_path testdata/configs/sloglint_no_raw_keys.yml | ||
package testdata | ||
|
||
import "log/slog" | ||
|
||
const foo = "foo" | ||
|
||
func Foo(value int) slog.Attr { | ||
return slog.Int("foo", value) | ||
} | ||
|
||
func test() { | ||
slog.Info("msg", foo, 1) | ||
slog.Info("msg", Foo(1)) | ||
|
||
slog.Info("msg", "foo", 1) // want `raw keys should not be used` | ||
slog.Info("msg", slog.Int("foo", 1)) // want `raw keys should not be used` | ||
} |