chore: setup non-blocking lints

cognitive-glitch committed Nov 24, 2025 at 22:28 UTC 7f22dd174be2931f3ed21ff1b0687540dc28061e
2 files changed +142
golangci.yml new
+88
@@ -0,0 +1,88 @@
1 +version: "2"
2 +
3 +run:
4 + tests: true
5 + # Go 1.25+ will handle modules impeccably; ensure the linter knows the version.
6 + go: "1.25"
7 +
8 +linters:
9 + default: standard
10 +
11 + enable:
12 + # --- The Essentials (Bugs & Correctness) ---
13 + - govet # Standard vet
14 + - errcheck # Unchecked errors are fatal
15 + - staticcheck # Dominant static analysis
16 +
17 + # --- The Dark Arts (Performance & Concurrency) ---
18 + - prealloc # Encourages slice pre-allocation (critical for low latency)
19 + - bodyclose # Ensures HTTP response bodies are closed
20 + - noctx # HTTP requests must have context (prevents goroutine leaks)
21 + - copyloopvar # Detects loop variable copying (Modern Go replacement for exportloopref)
22 + - intrange # Suggests using newer `for i := range n` syntax (Go 1.22+)
23 +
24 + # --- The Hygienists (Style & Formatting) ---
25 + - godot # Comments should end in a period
26 + - misspell # Fixes typos
27 + - whitespace # Detects leading and trailing whitespace
28 + - nolintlint # Forces documentation on why you are ignoring a linter
29 +
30 + # --- Cognitive Load ---
31 + - gocognit # Cognitive complexity (better than cyclomatic)
32 + - nestif # Detects deeply nested if-statements
33 +
34 + exclusions:
35 + rules:
36 + - linters:
37 + - errcheck
38 + source: "^\\s*defer\\s+"
39 +
40 + settings:
41 + errcheck:
42 + # FALSE: Allows you to explicitly ignore an error using `_ = func()`
43 + # If true, `_ = func()` is still a violation.
44 + check-blank: false
45 +
46 + # FALSE: Does not force checking type assertion results (v, ok := x.(T))
47 + check-type-assertions: false
48 +
49 + # List of functions to exclude from checking.
50 + # These are the most common sources of "noise" in standard Go development.
51 + exclude-functions:
52 + - fmt.Printf
53 + - fmt.Println
54 + - fmt.Print
55 + - fmt.Fprintf
56 + - fmt.Fprint
57 + - fmt.Fprintln
58 + - fmt.Sprintf # Rarely fails unless OOM
59 + - os.Unsetenv # Usually safe to ignore
60 + - encoding/json.Marshal # Safe ONLY if you trust the struct tags/types
61 + - encoding/json.Unmarshal # Safe ONLY if you trust the input data
62 + - encoding/json.NewEncoder # Encoder setup
63 + - encoding/json.NewDecoder # Decoder setup
64 + - strings.Builder.WriteString # Writes to memory; usually safe
65 + - strings.Builder.Write # Writes to memory; usually safe
66 + - bytes.Buffer.Write # Writes to memory; usually safe
67 + - bytes.Buffer.WriteString # Writes to memory; usually safe
68 + - io.Copy # Standard I/O operation
69 + - context.WithTimeout # Context creation
70 + - context.WithCancel # Context creation
71 + - log.Printf # Standard logging
72 + - log.Println # Standard logging
73 + - log.Print # Standard logging
74 + - time.Now # Time retrieval
75 + - time.Sleep # Time operations
76 + - sync.Mutex.Lock # Mutex operations
77 + - sync.Mutex.Unlock # Mutex operations
78 + - sync.RWMutex.RLock # RWMutex operations
79 + - sync.RWMutex.RUnlock # RWMutex operations
80 + - atomic.AddInt64 # Atomic operations
81 + - atomic.StoreInt64 # Atomic operations
82 + - atomic.LoadInt64 # Atomic operations
83 + - rand.Read # Cryptographically secure random
84 + - crypto/rand.Read # Secure random source
85 +
86 +issues:
87 + max-issues-per-linter: 0
88 + max-same-issues: 0
pre-commit-config.yaml new
+54
@@ -0,0 +1,54 @@
1 +minimum_pre_commit_version: "3.5.0"
2 +
3 +repos:
4 + # General text cleanup for markdown files
5 + - repo: https://github.com/pre-commit/pre-commit-hooks
6 + rev: v6.0.0
7 + hooks:
8 + # Remove trailing whitespace
9 + - id: trailing-whitespace
10 +
11 + # Ensure files end with a newline
12 + - id: end-of-file-fixer
13 +
14 + # Fix mixed line endings (convert to LF)
15 + - id: mixed-line-ending
16 + args: ["--fix=lf"]
17 +
18 + # Fix UTF-8 byte order marker
19 + - id: fix-byte-order-marker
20 +
21 + - repo: https://github.com/golangci/golangci-lint
22 + rev: v2.6.2
23 + hooks:
24 + - id: golangci-lint
25 + name: golangci-lint
26 + description: Fast linters runner for Go. Note that only modified files are linted, so linters like 'unused' that need to scan all files won't work as expected.
27 + entry: golangci-lint run --new-from-rev HEAD --fix
28 + types: [go]
29 + language: golang
30 + require_serial: true
31 + pass_filenames: false
32 + - id: golangci-lint-full
33 + name: golangci-lint-full
34 + description: Fast linters runner for Go. Runs on all files in the module. Use this hook if you use pre-commit in CI.
35 + entry: golangci-lint run --fix
36 + types: [go]
37 + language: golang
38 + require_serial: true
39 + pass_filenames: false
40 + - id: golangci-lint-fmt
41 + name: golangci-lint-fmt
42 + description: Fast linters runner for Go. Formats all files in the repo.
43 + entry: golangci-lint fmt
44 + types: [go]
45 + language: golang
46 + require_serial: true
47 + pass_filenames: false
48 + - id: golangci-lint-config-verify
49 + name: golangci-lint-config-verify
50 + description: Verifies the configuration file
51 + entry: golangci-lint config verify
52 + files: '\.golangci\.(?:yml|yaml|toml|json)'
53 + language: golang
54 + pass_filenames: false