Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

False positives for logging constant keys in another package? #66

Open
yizeng opened this issue Jan 21, 2025 · 0 comments
Open

False positives for logging constant keys in another package? #66

yizeng opened this issue Jan 21, 2025 · 0 comments

Comments

@yizeng
Copy link

yizeng commented Jan 21, 2025

Wondering if I'm missing anything or this is by design: I defined a bunch of logging constant keys in a separate logging package and set no-raw-keys: true, but I get false positives "raw keys should not be used (sloglint)".

// main.go
package main

import (
	"log/slog"

	"sloglint-example/logging"
)

func main() {
	contentLength := int64(12345)
	url := "https://example.com/file"

	slog.Info("File downloaded successfully",
		slog.Int64(logging.KeyContentLength, contentLength),
		slog.String(logging.KeyURL, url),
	)
}
// logging/logging.go
package logging

const (
	KeyContentLength = "content_length"
	KeyURL           = "url"
)
linters:
  disable-all: true
  enable:
    - sloglint # Enable only sloglint

linters-settings:
  sloglint:
    # Enforce not mixing key-value pairs and attributes.
    no-mixed-args: true
    # Enforce using key-value pairs only (overrides no-mixed-args, incompatible with attr-only).
    kv-only: false
    # Enforce using attributes only (overrides no-mixed-args, incompatible with kv-only).
    attr-only: true
    # Enforce using methods that accept a context.
    context: scope
    # Enforce using static values for log messages.
    static-msg: false
    # Enforce using constants instead of raw keys.
    no-raw-keys: true
    # Enforce a single key naming convention.
    # Values: snake, kebab, camel, pascal
    key-naming-case: snake
    # Enforce putting arguments on separate lines.
    args-on-sep-lines: true

Expected: No errors
Actual:

main.go:13:2: raw keys should not be used (sloglint)
slog.Info("File downloaded successfully",
^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant