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
This commit is contained in:
64
.golangci.yml
Normal file
64
.golangci.yml
Normal file
@ -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
|
||||||
10
Taskfile.yml
10
Taskfile.yml
@ -69,6 +69,16 @@ tasks:
|
|||||||
cmds:
|
cmds:
|
||||||
- go mod tidy
|
- 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:
|
clean:
|
||||||
desc: Remove built binary
|
desc: Remove built binary
|
||||||
cmds:
|
cmds:
|
||||||
|
|||||||
16
main.go
16
main.go
@ -105,7 +105,8 @@ func formatContextInfo(contextSize int, usage *struct {
|
|||||||
InputTokens int `json:"input_tokens"`
|
InputTokens int `json:"input_tokens"`
|
||||||
CacheCreationTokens int `json:"cache_creation_input_tokens"`
|
CacheCreationTokens int `json:"cache_creation_input_tokens"`
|
||||||
CacheReadInputTokens int `json:"cache_read_input_tokens"`
|
CacheReadInputTokens int `json:"cache_read_input_tokens"`
|
||||||
}) string {
|
},
|
||||||
|
) string {
|
||||||
totalK := contextSize / 1000
|
totalK := contextSize / 1000
|
||||||
|
|
||||||
if usage == nil {
|
if usage == nil {
|
||||||
@ -177,19 +178,6 @@ func getGitInfo(cwd string) string {
|
|||||||
return fmt.Sprintf(" git:(%s)", branch)
|
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 {
|
func getTerminalWidth() int {
|
||||||
ws, err := unix.IoctlGetWinsize(int(os.Stdout.Fd()), unix.TIOCGWINSZ)
|
ws, err := unix.IoctlGetWinsize(int(os.Stdout.Fd()), unix.TIOCGWINSZ)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user