Added forbidigo linter that catches slog being used without context. (#39432)

<!-- Add the related story/sub-task/bug number, like Resolves #123, or
remove if NA -->
**Related issue:** Resolves #38889 

# Checklist for submitter

## Testing
- [x] QA'd all new/changed functionality manually
This commit is contained in:
Victor Lyuboslavsky
2026-02-09 15:28:42 -06:00
committed by GitHub
parent ac508b9a40
commit 70e3c548f0
+22
View File
@@ -19,6 +19,7 @@ linters:
default: none
enable:
- depguard
- forbidigo
- gosec
- gocritic
- nilnesserr
@@ -32,6 +33,20 @@ linters:
- errcheck
- staticcheck
settings:
forbidigo:
forbid:
- pattern: "^print$"
msg: "use structured logging instead of built-in print"
- pattern: "^println$"
msg: "use structured logging instead of built-in println"
# slog: forbid non-context methods
- pattern: "^slog\\.(Debug|Info|Warn|Error)"
pkg: "^log/slog$"
msg: "Don't use the default logger. Use a specific *slog.Logger instance."
- pattern: "slog\\.Logger\\.(Debug|Info|Warn|Error)$"
msg: "use DebugContext/InfoContext/WarnContext/ErrorContext instead"
analyze-types: true
depguard:
rules:
main:
@@ -218,6 +233,13 @@ linters:
- path: server/datastore/mysql/migrations/[^/]+/[^/]+\.go
linters:
- depguard
# Legacy CLI tools that use slog without context
- path: cmd/cpe/generate.go
linters:
- forbidigo
- path: tools/mdm/migration/micromdm/main.go
linters:
- forbidigo
# cmd gosec exclusions https://github.com/fleetdm/fleet/issues/4451
- path: cmd/osquery-perf/agent.go
linters: