gofmt là formatter chính thức của Go, chuẩn hóa indentation (tab), spacing, và cú pháp. Không có option cấu hình — một chuẩn duy nhất cho toàn bộ cộng đồng Go. Chạy: gofmt -w .
goimports = gofmt + tự động thêm/xóa import statements. Đây là công cụ được khuyến nghị dùng trong editor (VS Code, GoLand) thay thế gofmt.
bash
goimports -w . # format + fix imports
goimports -l . # chỉ list files cần fixgolangci-lint là meta-linter chạy hàng chục linters song song: staticcheck (bugs tiềm ẩn), errcheck (bỏ sót check error), govet (misuse of sync primitives), revive (code style), gosec (security), v.v.
bash
golangci-lint run ./...
golangci-lint run --fix ./... # tự fix một số issuesCấu hình qua .golangci.yml:
yaml
linters:
enable:
- errcheck
- staticcheck
- gosimple
- unused
- reviveBest practice: tích hợp goimports vào editor (save hook), chạy golangci-lint trong CI pipeline và fail build nếu có lỗi.