-
Notifications
You must be signed in to change notification settings - Fork 9
Closed
Description
Hi, thanks for this linter! I have encountered some problems while using it.
- Panic when using an attribute assigned to a variable (or returned from a function) when using the
slog.Attr
constructor:
main.go
:
package main
import "log/slog"
var MyInt = slog.Int
func main() {
slog.Info("Hello, World!", MyInt("foo-foo", 123))
}
config:
linters:
enable:
- sloglint
linters-settings:
sloglint:
key-naming-case: snake
- No violation is detected when using the custom
slog.Attr
constructor:
main.go
:
package main
import "log/slog"
func UserId(value int) slog.Attr { return slog.Int("user-id", value) }
func main() {
slog.Info("a user has logged in", slog.Int("user-id", 42)) // Detected
slog.Info("a user has logged in", UserId(42))
}
config:
linters:
enable:
- sloglint
linters-settings:
sloglint:
key-naming-case: snake
- The violation is not detected when using the logging function of the assigned variable. This looks like the second case, but I had a quick look at the code and it affects a different part, so I thought I'd mention it.
main.go
package main
import (
"fmt"
"log/slog"
)
var MyInfo = slog.Info
func main() {
slog.Info(fmt.Sprintf("a user with id %d has logged in", 42)) // Detected
MyInfo(fmt.Sprintf("a user with id %d has logged in", 42))
}
config:
linters:
enable:
- sloglint
linters-settings:
sloglint:
static-msg: true
- The
LogAttrs
function (and method) are not detected.
main.go
:
package main
import (
"context"
"fmt"
"log/slog"
)
func main() {
slog.Info(fmt.Sprintf("a user with id %d has logged in", 42)) // Detected
slog.LogAttrs(context.TODO(), slog.LevelInfo, fmt.Sprintf("a user with id %d has logged in", 42), slog.String("id", "42"))
}
config:
linters:
enable:
- sloglint
linters-settings:
sloglint:
static-msg: true
tmzane, knqyf263 and simar7
Metadata
Metadata
Assignees
Labels
No labels