sloglint
sloglint copied to clipboard
Use of `context: scope` configuration value causes deferred functions to not be linted
Given a file like this:
package main
import "log/slog"
func main() {
defer func() {
// We expect this to fail due to use of kv pairs
slog.Error("some error", "key", "value")
}()
}
And a configuration file:
version: '2'
linters:
default: 'none'
enable:
- sloglint
settings:
sloglint:
attr-only: true
We correctly receive a lint issue:
$ golangci-lint --version
golangci-lint has version 2.2.1 built with go1.24.4 from 66496a9 on 2025-06-29T15:57:59Z
$ golangci-lint run
main.go:8:3: key-value pairs should not be used (sloglint)
slog.Error("some error", "arg", "value")
^
1 issues:
* sloglint: 1
However if we add context: scope to the configuration file:
version: '2'
linters:
default: 'none'
enable:
- sloglint
settings:
sloglint:
attr-only: true
context: 'scope'
The lint issue vanishes:
$ golangci-lint run
0 issues.
If context is set to scope, we use inspector.Inspector.WithStack instead of inspector.Inspector.Preorder, I guess that's the cause here. There also might be a bug in the inspector lib, I can see that the documentation (and possibly the implementation) has been updated. I'll take a look, thanks for the report.