Introduction
Revive is a Go linter built as a faster, more configurable successor to the now-archived golint. It checks Go source code for style violations, naming conventions, and common mistakes, and lets teams define custom rules to enforce project-specific standards.
What Revive Does
- Enforces Go naming conventions (exported names, package comments, error types)
- Detects unreachable code, unused parameters, and unnecessary blank identifiers
- Validates function complexity, argument counts, and return value patterns
- Supports custom rules written as Go functions loaded at runtime
- Outputs diagnostics in text, JSON, or friendly formatted styles
Architecture Overview
Revive parses Go source files using the standard go/ast and go/token packages, then runs each file through a pipeline of rule checkers. Rules implement a simple interface receiving an AST file and returning failures. Configuration is loaded from a TOML file that enables, disables, or sets severity and arguments per rule. The runner parallelizes across packages for speed.
Self-Hosting & Configuration
- Install with
go install github.com/mgechev/revive@latest - Create a
revive.tomlto enable or disable specific rules - Set rule severity to
warningorerrorto control exit codes - Exclude generated files or test files with
excludepatterns in config - Integrates with golangci-lint as a bundled linter
Key Features
- Drop-in golint replacement with backward-compatible rule set
- TOML-based config for per-rule severity, arguments, and exclusions
- Custom rule API lets teams add project-specific checks
- Parallel execution across packages for fast analysis of large codebases
- Multiple output formatters including JSON for CI integration
Comparison with Similar Tools
- golint — archived and unmaintained; Revive is its actively developed successor
- Staticcheck — focuses on correctness and bug detection; Revive focuses on style and conventions
- golangci-lint — meta-linter that can run Revive alongside other tools
- go vet — catches low-level issues; Revive targets higher-level style and readability
- gofmt/gofumpt — handle formatting only; Revive addresses semantic style rules
FAQ
Q: Is Revive a drop-in replacement for golint? A: Yes, Revive includes all of golint's rules and adds many more while maintaining backward compatibility.
Q: How do I write a custom rule?
A: Implement the revive.Rule interface with a Name() and Apply(*File, Arguments) method, then reference it in your config.
Q: Can I use Revive with golangci-lint? A: Yes, golangci-lint includes Revive as one of its bundled linters with pass-through config support.
Q: How fast is Revive compared to golint? A: Revive runs rules in parallel and is typically several times faster than golint on multi-package projects.