| name | golang-compliance |
| description | Go code quality and compliance analysis using golangci-lint, staticcheck, go vet, and revive. Use when asked to check code quality, find linting violations, audit Go code for correctness, or when the user asks "what's wrong with this code?" for a Go project.
|
| allowed-tools | Bash(go *), Bash(golangci-lint *), Bash(staticcheck *), Bash(revive *), Read, Grep, Glob |
Go Compliance & Quality Analysis
Detailed workflow for running compliance checks on Go projects — the equivalent of und codecheck from SciTools Understand.
Quick Reference
| Und Command | Go Equivalent |
|---|
und codecheck "Config" | golangci-lint run |
und analyze | go build ./... + golangci-lint run |
und codecheck -exitstatus | golangci-lint run (exits 1 on issues) |
Step 1 — Environment Check
Before running any analysis, verify the required tools are installed:
which golangci-lint || echo "MISSING: go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest"
which staticcheck || echo "MISSING: go install honnef.co/go/tools/cmd/staticcheck@latest"
which revive || echo "MISSING: go install github.com/mgechev/revive@latest"
Step 2 — Module Readiness
go mod verify
go mod tidy
Step 3 — Build Validation (Compile Pass)
go build -v ./...
go build -v ./cmd/...
Step 4 — Standard Vet (Built-in)
go vet ./...
go vet -shadow ./...
Step 5 — Full Lint Sweep (golangci-lint)
golangci-lint run ./...
golangci-lint run --out-format=tab ./...
golangci-lint run --out-format=json ./... > lint-report.json
golangci-lint run --out-format=json ./... | \
jq '[.Issues[] | .Pos.Filename] | group_by(.) | map({file: .[0], count: length}) | sort_by(-.count)[:10]'
Step 6 — Deep Static Analysis (staticcheck)
staticcheck ./...
staticcheck -checks="SA*" ./...
staticcheck -checks="S*" ./...
staticcheck -checks="ST*" ./...
staticcheck -checks="QF*" ./...
Step 7 — Style Rules (revive)
revive -formatter friendly ./...
revive -formatter friendly -set_exit_status ./...
Configuration: .golangci.yml
For repeatable compliance runs, create .golangci.yml at the project root.
Suggested minimum configuration for architectural compliance:
run:
timeout: 5m
go: "1.22"
linters:
enable:
- govet
- staticcheck
- errcheck
- gosimple
- ineffassign
- unused
- gocyclo
- misspell
- revive
linters-settings:
gocyclo:
min-complexity: 15
errcheck:
check-type-assertions: true
check-blank: true
issues:
exclude-rules:
- path: "_test\\.go"
linters:
- errcheck
Interpreting Results
After running compliance tools, categorize findings:
Critical (must fix before merge):
errcheck — unhandled errors
govet — suspicious code constructs
staticcheck SA* — correctness issues
Warnings (should fix):
staticcheck S* — simplification opportunities
gocyclo violations — overly complex functions
ineffassign — wasted assignments
Suggestions (consider improving):
revive style violations
misspell corrections
staticcheck QF* — quick fixes
Equivalent to und codecheck -exitstatus for Scripts
#!/bin/bash
echo "=== Go Compliance Check ==="
echo "1. Build..."
go build ./... || exit 1
echo "2. Vet..."
go vet ./... || exit 1
echo "3. Lint..."
golangci-lint run --timeout 5m || exit 1
echo "=== All checks passed ==="
Supporting Files