gofmt, go vet & Linting
Prettier + ESLint + tsc → gofmt + go vet + staticcheck
Section titled “Prettier + ESLint + tsc → gofmt + go vet + staticcheck”In the TypeScript world you need three separate tools to cover formatting, bug-prone patterns, and type errors:
- Prettier reformats code to a consistent style
- ESLint catches suspicious patterns and enforces conventions
- tsc (type-checker) reports type errors
Go collapses this into tools that are all part of the standard Go installation, with a third-party linter (staticcheck or golangci-lint) that is universally adopted.
gofmt — the opinionated formatter
Section titled “gofmt — the opinionated formatter”gofmt (or its alias go fmt) rewrites your source files in-place to match the one true Go style. Unlike Prettier, it has zero configuration. There is no .gofmtrc, no printWidth, no singleQuote option.
# Format all packages in the modulego fmt ./...
# Preview what would change (dry-run)gofmt -d .
# Write changes in-placegofmt -w .Most editors run gofmt on save automatically. If your editor is VS Code, install the official Go extension and it happens without any extra config.
// .prettierrc{ "semi": true, "singleQuote": false, "printWidth": 100, "tabWidth": 2, "trailingComma": "es5"}
// Run:// npx prettier --write src/# No config file needed.# Run:go fmt ./...
# Or wire it into your editor's "format on save".# The result is always the same regardless of who runs it.go vet — the bug detector
Section titled “go vet — the bug detector”go vet is a static analyser that ships with Go. It finds real bugs — not style issues — such as:
- Passing the wrong type to
fmt.Printfformat strings - Unreachable code after a
return - Struct tags that are malformed
- Mutexes copied by value
go vet ./...Think of it as the subset of ESLint rules that catch actual mistakes, not style preferences.
// ESLint (partial .eslintrc.json){ "rules": { "no-unreachable": "error", "no-unused-vars": "error", "@typescript-eslint/no-explicit-any": "warn" }}
// Run:// npx eslint src --ext .ts# No config needed.go vet ./...
# Example output when something is wrong:# ./main.go:12:2: Printf format %d has arg name of wrong type stringstaticcheck and golangci-lint
Section titled “staticcheck and golangci-lint”go vet catches the most obvious bugs. For a richer set of checks — unused exports, deprecated API usage, simplifiable code — the community relies on:
- staticcheck (
honnef.co/go/tools) — a focused, high-signal linter - golangci-lint — a meta-linter that runs many linters in parallel, including
staticcheck,errcheck,gosimple, and more
# Install staticcheckgo install honnef.co/go/tools/cmd/staticcheck@latest
# Run itstaticcheck ./...
# Or use golangci-lint (recommended for CI)# Install: https://golangci-lint.run/usage/install/golangci-lint run ./...A minimal .golangci.yml to start with:
linters: enable: - staticcheck - errcheck - gosimple - unused
linters-settings: staticcheck: go: "1.22"Run this in your terminal after installing golangci-lint. There is no browser-runnable equivalent for a linter.