Scripts2026年5月28日·1 分钟阅读

Revive — Fast and Extensible Go Linter

Revive is a fast, configurable Go linter that serves as a drop-in replacement for golint. It supports custom rules, TOML-based configuration, and runs significantly faster than its predecessor while providing more actionable diagnostics.

Agent 就绪

Agent 可直接安装

这个资产可安装;Agent 先选择当前运行时、检查安装计划,再运行匹配命令。

Native · 98/100策略:允许
Agent 入口
任意 MCP/CLI Agent
类型
Skill
安装
Single
信任
信任等级:Established
入口
Revive Linter
直接安装命令
npx -y tokrepo@latest install 09d9f3af-5ad5-11f1-9bc6-00163e2b0d79 --target codex

先 dry-run 确认安装计划,再运行此命令。

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.toml to enable or disable specific rules
  • Set rule severity to warning or error to control exit codes
  • Exclude generated files or test files with exclude patterns 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.

Sources

讨论

登录后参与讨论。
还没有评论,来写第一条吧。

相关资产