Skip to content

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

@alexandear

Description

@alexandear

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.

Details

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

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions