Revive
🔥 ~6x faster, stricter, configurable, extensible, and beautiful drop-in replacement for golint
Install / Use
/learn @mgechev/ReviveREADME
revive
Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint.
Revive provides a framework for development of custom rules,
and lets you define a strict preset for enhancing your development & code review processes.
Here's how revive is different from golint:
- Allows to enable or disable rules using a configuration file.
- Allows to configure the linting rules with a TOML file.
- 2x faster running the same rules as golint.
- Provides functionality for disabling a specific rule or the entire linter for a file or a range of lines.
golintallows this only for generated files.
- Optional type checking. Most rules in golint do not require type checking. If you disable them in the config file, revive will run over 6x faster than golint.
- Provides multiple formatters which let us customize the output.
- Allows to customize the return code for the entire linter or based on the failure of only some rules.
- Everyone can extend it easily with custom rules or formatters.
Reviveprovides more rules compared togolint.
- Installation
- Usage
- Available Rules
- Configurable rules
- Available Formatters
- Extensibility
- Speed Comparison
- Overriding colorization detection
- Who uses Revive
- Contributors
- Star History
- License
Installation
revive is available inside the majority of package managers.
<img alt="Repology packaging status" src="https://repology.org/badge/vertical-allrepos/revive.svg">
Homebrew
Install revive using brew:
brew install revive
To upgrade to the latest version:
brew upgrade revive
Install from Sources
Install the latest stable release directly from source:
go install github.com/mgechev/revive@latest
To install the latest commit from the main branch:
go install github.com/mgechev/revive@HEAD
Docker
You can run revive using Docker to avoid installing it directly on your system:
docker run -v "$(pwd)":/var/YOUR_REPOSITORY ghcr.io/mgechev/revive:v1.10.0 -config /var/YOUR_REPOSITORY/revive.toml -formatter stylish ./var/YOUR_REPOSITORY/...
Note: Replace YOUR_REPOSITORY with the path to your repository.
A volume must be mounted to share the current repository with the container. For more details, refer to the bind mounts Docker documentation.
-v: Mounts the current directory ($(pwd)) to/var/YOUR_REPOSITORYinside the container.ghcr.io/mgechev/revive:v1.10.0: Specifies the Docker image and its version.revive: The command to run inside the container.- Flags like
-configand-formatterare the same as when using the binary directly.
Manual Binary Download
Download the precompiled binary from the Releases page:
- Select the appropriate binary for your OS and architecture.
- Extract the binary and move it to a directory in your
PATH(e.g.,/usr/local/bin). - Verify installation:
revive -version
Usage
Since the default behavior of revive is compatible with golint, without providing any additional flags,
the only difference you'd notice is faster execution.
revive supports a -config flag whose value should correspond to a TOML file describing which rules to use for revive's linting.
If not provided, revive will try to use a global config file (assumed to be located at $HOME/revive.toml).
Otherwise, if no configuration TOML file is found then revive uses a built-in set of default linting rules.
Text Editors
- Support for VSCode via vscode-go by changing the
go.lintToolsetting torevive:
{
"go.lintTool": "revive",
}
-
Support for GoLand via File Watchers.
-
Support for vim via dense-analysis/ale.
let g:ale_linters = { \ 'go': ['revive'], \}
GitHub Actions
- Revive Action with annotation support
Continuous Integration
Codeac.io - Automated code review service integrates with GitHub, Bitbucket and GitLab (even self-hosted) and helps you fight technical debt. Check your pull-requests with revive automatically. (Free for open-source projects)
Linter aggregators
golangci-lint
To enable revive in golangci-lint you need to add revive to the list of enabled linters:
# golangci-lint configuration file
version: "2"
linters:
enable:
- revive
Then revive can be configured by adding an entry to the linters.settings section of the configuration, for example:
# golangci-lint configuration file
linters:
settings:
revive:
severity: warning
rules:
- name: atomic
- name: line-length-limit
severity: error
arguments: [80]
- name: unhandled-error
arguments: ["fmt.Printf", "myFunction"]
The above configuration enables three rules of revive: atomic, line-length-limit and unhandled-error and passes some arguments to the last two.
The Configuration section of this document provides details on how to configure revive.
Note that while revive configuration is in TOML, that of golangci-lint is in YAML or JSON.
See the golangci-lint website for more information about configuring revive.
Please notice that if no particular configuration is provided, revive will behave as golint does, i.e. all golint rules are enabled
(the Available Rules table details what are the golint rules).
When a configuration is provided, only rules in the configuration are enabled.
Command Line Flags
revive accepts the following command line parameters:
-
-config [PATH]- path to the config file in TOML format, defaults to$HOME/revive.tomlif present. -
-exclude [PATTERN]- pattern for files/directories/packages to be excluded for linting. You can specify the files you want to exclude for linting either as package name (i.e.github.com/mgechev/revive), list them as individual files (i.e.file.go), directories (i.e../foo/...), or any combination of the three. If no exclusion patterns are specified,vendor/...will be excluded by default. -
-formatter [NAME]- formatter to be used for the output. The currently available formatters are:default- will output the failures the same way thatgolintdoes.json- outputs the failures in JSON format.ndjson- outputs the failures as a stream in newline delimited JSON (NDJSON) format.friendly- outputs the failures when found. Shows the summary of all the failures.stylish- formats the failures in a table. Keep in mind that it doesn't stream the output so it might be perceived as slower compared to others.checkstyle- outputs the failures in XML format compatible with that of Java's Checkstyle.
-
-max_open_files- maximum number of open files at the same time. Defaults to unlimited. -
-set_exit_status- set exit status to 1 if any issues are found, overwriteserrorCodeandwarningCodein config. -
-version- get revive version.
Sample Invocations
revive -config revive.toml -exclude file1.go -exclude file2.go -formatter friendly github.com/mgechev/revive package/...
- The command above will use the configuration from
revive.toml revivewill ignorefile1.goand
Related Skills
node-connect
333.7kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
xurl
333.7kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
frontend-design
82.0kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
333.7kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
