Skip to content

Commit 134336b

Browse files
authored
docs: add golangci-lint integration info (#16)
1 parent b2f5791 commit 134336b

File tree

1 file changed

+28
-13
lines changed

1 file changed

+28
-13
lines changed

README.md

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,36 @@ The linter has several options, so you can adjust it to your own code style.
3131

3232
## 📦 Install
3333

34-
Download a prebuilt binary from the [Releases][1] page.
34+
`sloglint` is integrated into [`golangci-lint`][1], and this is the recommended way to use it.
3535

36-
## 📋 Usage
36+
To enable the linter, add the following lines to `.golangci.yml`:
3737

38-
```shell
39-
sloglint [flags] ./...
38+
```yaml
39+
linters:
40+
enable:
41+
- sloglint
4042
```
4143
44+
Alternatively, you can download a prebuilt binary from the [Releases][2] page to use `sloglint` standalone.
45+
46+
## 📋 Usage
47+
48+
Run `golangci-lint` with `sloglint` enabled.
49+
See the list of [available options][3] to configure the linter.
50+
51+
When using `sloglint` standalone, pass the options as flags of the same name.
52+
4253
### Key-value pairs only
4354

44-
The `-kv-only` flag causes `sloglint` to report any use of attributes:
55+
The `kv-only` option causes `sloglint` to report any use of attributes:
4556

4657
```go
4758
slog.Info("a user has logged in", slog.Int("user_id", 42)) // sloglint: attributes should not be used
4859
```
4960

5061
### Attributes only
5162

52-
In contrast, the `-attr-only` flag causes `sloglint` to report any use of key-value pairs:
63+
In contrast, the `attr-only` option causes `sloglint` to report any use of key-value pairs:
5364

5465
```go
5566
slog.Info("a user has logged in", "user_id", 42) // sloglint: key-value pairs should not be used
@@ -59,7 +70,7 @@ slog.Info("a user has logged in", "user_id", 42) // sloglint: key-value pairs sh
5970

6071
Some `slog.Handler` implementations make use of the given `context.Context` (e.g. to access context values).
6172
For them to work properly, you need to pass a context to all logger calls.
62-
The `-context-only` flag causes `sloglint` to report the use of methods without a context:
73+
The `context-only` option causes `sloglint` to report the use of methods without a context:
6374

6475
```go
6576
slog.Info("a user has logged in") // sloglint: methods without a context should not be used
@@ -74,7 +85,7 @@ slog.InfoContext(ctx, "a user has logged in")
7485
### No raw keys
7586

7687
To prevent typos, you may want to forbid the use of raw keys altogether.
77-
The `-no-raw-keys` flag causes `sloglint` to report the use of strings as keys
88+
The `no-raw-keys` option causes `sloglint` to report the use of strings as keys
7889
(including `slog.Attr` calls, e.g. `slog.Int("user_id", 42)`):
7990

8091
```go
@@ -97,21 +108,23 @@ func UserId(value int) slog.Attr { return slog.Int("user_id", value) }
97108
slog.Info("a user has logged in", UserId(42))
98109
```
99110

100-
> 💡 Such helpers can be automatically generated for you by the [`sloggen`][2] tool. Give it a try too!
111+
> 💡 Such helpers can be automatically generated for you by the [`sloggen`][4] tool. Give it a try too!
101112

102113
### Key naming convention
103114

104115
To ensure consistency in logs, you may want to enforce a single key naming convention.
105-
The `-key-naming-case=<snake|kebab|camel|pascal>` flag causes `sloglint` to report keys written in a case other than the given one:
116+
The `key-naming-case` option causes `sloglint` to report keys written in a case other than the given one:
106117

107118
```go
108119
slog.Info("a user has logged in", "user-id", 42) // sloglint: keys should be written in snake_case
109120
```
110121

122+
Possible values are `snake`, `kebab`, `camel`, or `pascal`.
123+
111124
### Arguments on separate lines
112125

113126
To improve code readability, you may want to put arguments on separate lines, especially when using key-value pairs.
114-
The `-args-on-sep-lines` flag causes `sloglint` to report 2+ arguments on the same line:
127+
The `args-on-sep-lines` option causes `sloglint` to report 2+ arguments on the same line:
115128

116129
```go
117130
slog.Info("a user has logged in", "user_id", 42, "ip_address", "192.0.2.0") // sloglint: arguments should be put on separate lines
@@ -126,5 +139,7 @@ slog.Info("a user has logged in",
126139
)
127140
```
128141

129-
[1]: https://github.com/go-simpler/sloglint/releases
130-
[2]: https://github.com/go-simpler/sloggen
142+
[1]: https://golangci-lint.run
143+
[2]: https://github.com/go-simpler/sloglint/releases
144+
[3]: https://golangci-lint.run/usage/linters/#sloglint
145+
[4]: https://github.com/go-simpler/sloggen

0 commit comments

Comments
 (0)