mgechev/revive

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

Open

#1498 aperta il 29 ago 2025

Vedi su GitHub
 (0 commenti) (1 reazione) (0 assegnatari)Go (316 fork)github user discovery
docsgood first issue

Metriche repository

Star
 (5517 star)
Metriche merge PR
 (Metriche PR in attesa)

Descrizione

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

Guida contributor