mgechev/revive

Extend rules documentation with before/after code blocks and real use cases

Closed

#1,498 创建于 2025年8月29日

在 GitHub 查看
 (0 评论) (1 反应) (0 负责人)Go (316 fork)github user discovery
docsgood first issue

仓库指标

Star
 (5,517 star)
PR 合并指标
 (PR 指标待抓取)

描述

Currently, RULES_DESCRIPTIONS.md provides descriptions of rules but lacks practical examples. This makes it harder for developers to quickly understand the impact of enabling a rule.

Proposal

  • Add short before/after code blocks to every rule in RULES_DESCRIPTIONS.md. Can be similar to "Before/After" in go-critic.
  • Where possible, include real use cases of fixing such rules in well-known Open Source codebases.
  • Ensure examples are minimal but illustrative, showing both the violation and the corrected version.

This will make the documentation more practical, reduce ambiguity, and help developers adopt Revive more effectively.

Example

Below is a proposed format for use-any description.

use-any

Description

Since Go 1.18, interface{} has an alias: any. This rule proposes to replace instances of interface{} with any to follow modern Go conventions introduced with generics.

Configuration

N/A

Examples

Before (violation):

func PrintValue(v interface{}) {
    fmt.Println(v)
}

After (fixed):

func PrintValue(v any) {
    fmt.Println(v)
}

Real-world use cases

贡献者指南