Go Language Guide¶
linthis uses golangci-lint for linting and gofmt for formatting Go code.
Supported File Extensions¶
.go
Required Tools¶
Linter: golangci-lint¶
# macOS
brew install golangci-lint
# Linux
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Windows
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
# Verify installation
golangci-lint --version
Formatter: gofmt¶
gofmt is included with the Go installation.
# Verify installation
gofmt -h
Configuration¶
Basic Example¶
# .linthis/config.toml
[go]
max_complexity = 15
excludes = ["vendor/**", "*_test.go"]
Disable Specific Rules¶
[go.rules]
disable = [
"errcheck",
"gosimple"
]
Custom Rules¶
[[rules.custom]]
code = "go/no-panic"
pattern = "\\bpanic\\s*\\("
message = "Avoid panic in production code"
severity = "warning"
suggestion = "Return an error instead"
languages = ["go"]
[[rules.custom]]
code = "go/no-todo"
pattern = "// TODO"
message = "TODO comment found"
severity = "info"
languages = ["go"]
CLI Usage¶
# Check Go files only
linthis -c --lang go
# Format Go files only
linthis -f --lang go
Golangci-lint Configuration¶
Create .golangci.yml:
linters:
enable:
- errcheck
- gosimple
- govet
- ineffassign
- staticcheck
- unused
linters-settings:
errcheck:
check-type-assertions: true
govet:
check-shadowing: true
issues:
exclude-rules:
- path: _test\.go
linters:
- errcheck
Common Issues¶
Golangci-lint not found¶
Warning: No go linter available for go files
Install: brew install golangci-lint
Slow first run¶
Golangci-lint caches results. First run may be slow, subsequent runs are faster.
Vendor directory being checked¶
Add to excludes:
[go]
excludes = ["vendor/**"]
Best Practices¶
- Use .golangci.yml: Consistent configuration across your project
- Enable multiple linters: golangci-lint aggregates many linters
- Complexity limits: Go code is typically less complex, set
max_complexity = 15 - Test exclusions: Consider different rules for test files