Skip to content

docs: fix revive defer rule configuration #5804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 15, 2025

Conversation

take0fit
Copy link
Contributor

This is my first time creating a pull request.
Please let me know if I made any mistakes in the process.

Fix incorrect revive defer rule arguments format in docs

The current documentation lists the defer rule configuration for revive as follows:

- name: defer
  severity: warning
  disabled: false
  exclude: [""]
  arguments:
    - "call-chain"
    - "loop"
    - "method-call"
    - "recover"
    - "immediate-recover"
    - "return"

However, this format is incorrect. According to the official revive rule descriptions (source), the arguments field should be passed as a nested list:

- name: defer
  severity: warning
  disabled: false
  exclude: [""]
  arguments: [["call-chain", "loop", "method-call", "recover", "return"]]

Why is a nested list required?

In revive, the Configure method for the defer rule expects its first argument to be castable to a []any. Since the top-level arguments are passed as a []interface{}, the actual list must be nested as the first element. Otherwise, the cast fails at runtime.

In contrast, rules like early-return handle scalar arguments and use a simple switch structure. But the defer rule iterates over a list of options using range, making the nested structure essential for flexibility and correctness.

This commit updates the golangci-lint documentation to reflect the correct format.

After スクリーンショット 2025-05-16 1 01 40

Copy link

boring-cyborg bot commented May 15, 2025

Hey, thank you for opening your first Pull Request !

@CLAassistant
Copy link

CLAassistant commented May 15, 2025

CLA assistant check
All committers have signed the CLA.

@ldez ldez changed the title Fix revive defer rule configuration format in .golangci.reference.yml docs: fix revive defer rule configuration May 15, 2025
@ldez ldez self-requested a review May 15, 2025 18:16
@ldez ldez added this to the v2-unreleased milestone May 15, 2025
@ldez ldez added the bug Something isn't working label May 15, 2025
Copy link
Member

@ldez ldez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thank you 👍

@ldez ldez merged commit ccf16f7 into golangci:main May 15, 2025
18 checks passed
@take0fit take0fit deleted the fix-revive-doc-example branch May 16, 2025 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: docs bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants