Skip to content

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 (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.

Terminal window
# Format all packages in the module
go fmt ./...
# Preview what would change (dry-run)
gofmt -d .
# Write changes in-place
gofmt -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.

TypeScript
// .prettierrc
{
"semi": true,
"singleQuote": false,
"printWidth": 100,
"tabWidth": 2,
"trailingComma": "es5"
}
// Run:
// npx prettier --write src/
Go
# 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 is a static analyser that ships with Go. It finds real bugs — not style issues — such as:

  • Passing the wrong type to fmt.Printf format strings
  • Unreachable code after a return
  • Struct tags that are malformed
  • Mutexes copied by value
Terminal window
go vet ./...

Think of it as the subset of ESLint rules that catch actual mistakes, not style preferences.

TypeScript
// ESLint (partial .eslintrc.json)
{
"rules": {
"no-unreachable": "error",
"no-unused-vars": "error",
"@typescript-eslint/no-explicit-any": "warn"
}
}
// Run:
// npx eslint src --ext .ts
Go
# No config needed.
go vet ./...
# Example output when something is wrong:
# ./main.go:12:2: Printf format %d has arg name of wrong type string

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
Terminal window
# Install staticcheck
go install honnef.co/go/tools/cmd/staticcheck@latest
# Run it
staticcheck ./...
# 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.

What file do you create to configure gofmt's style?
Which tool is the Go equivalent of ESLint's bug-detection rules (not style)?
What does `go fmt ./...` do?
golangci-lint is best described as: