From 4773460f3f230c9738bdfacdb0c13fd3f26bbb7a Mon Sep 17 00:00:00 2001 From: Kaj Kowalski Date: Thu, 18 Dec 2025 05:56:11 +0100 Subject: [PATCH] Add golangci-lint config and lint tasks - Add .golangci.yml with sensible defaults for the project - Add lint and lint:fix tasks to Taskfile - Remove unused findGitRoot function - Apply gofumpt formatting fixes --- .golangci.yml | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++ Taskfile.yml | 10 ++++++++ main.go | 16 ++----------- 3 files changed, 76 insertions(+), 14 deletions(-) create mode 100644 .golangci.yml diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..e8cab11 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,64 @@ +version: "2" + +linters: + default: standard + enable: + - errcheck + - govet + - staticcheck + - unused + - ineffassign + - misspell + - unconvert + - unparam + - gosec + - prealloc + - revive + - gocritic + - errname + - errorlint + - nilerr + - bodyclose + - durationcheck + - exhaustive + - copyloopvar + - perfsprint + - usestdlibvars + disable: + - depguard + - funlen + - gochecknoglobals + - gochecknoinits + - lll + - wsl + - nlreturn + - varnamelen + - exhaustruct + - ireturn + - nonamedreturns + + exclusions: + generated: lax + presets: + - comments + - std-error-handling + - common-false-positives + rules: + - path: _test\.go + linters: + - errcheck + - gosec + - dupl + +formatters: + enable: + - gofumpt + - goimports + +issues: + max-issues-per-linter: 50 + max-same-issues: 3 + +run: + timeout: 5m + tests: true diff --git a/Taskfile.yml b/Taskfile.yml index 761d7e0..f7ebb61 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -69,6 +69,16 @@ tasks: cmds: - go mod tidy + lint: + desc: Run golangci-lint + cmds: + - golangci-lint run + + lint:fix: + desc: Run golangci-lint with auto-fix + cmds: + - golangci-lint run --fix + clean: desc: Remove built binary cmds: diff --git a/main.go b/main.go index b681dd4..4261ee9 100644 --- a/main.go +++ b/main.go @@ -105,7 +105,8 @@ func formatContextInfo(contextSize int, usage *struct { InputTokens int `json:"input_tokens"` CacheCreationTokens int `json:"cache_creation_input_tokens"` CacheReadInputTokens int `json:"cache_read_input_tokens"` -}) string { +}, +) string { totalK := contextSize / 1000 if usage == nil { @@ -177,19 +178,6 @@ func getGitInfo(cwd string) string { return fmt.Sprintf(" git:(%s)", branch) } -func findGitRoot(path string) string { - for { - if _, err := os.Stat(filepath.Join(path, ".git")); err == nil { - return path - } - parent := filepath.Dir(path) - if parent == path { - return "" - } - path = parent - } -} - func getTerminalWidth() int { ws, err := unix.IoctlGetWinsize(int(os.Stdout.Fd()), unix.TIOCGWINSZ) if err != nil {