Skip to content

chore: bump golangci-lint version to v2#157

Merged
gaius-qi merged 1 commit intomainfrom
chore/golangci-lint-v2
Apr 17, 2025
Merged

chore: bump golangci-lint version to v2#157
gaius-qi merged 1 commit intomainfrom
chore/golangci-lint-v2

Conversation

@chlins
Copy link
Member

@chlins chlins commented Apr 17, 2025

This pull request updates the GolangCI-Lint configuration and workflow to align with the latest version and improve linting capabilities. The key changes include upgrading the GolangCI-Lint version, modifying the linting workflow, and restructuring the .golangci.yml configuration file.

GolangCI-Lint Version Upgrade:

  • Updated the GolangCI-Lint action in .github/workflows/lint.yml to use version v7.0.0 and upgraded the linting tool to v2.1.
  • Updated the GOLANGCI_LINT_VERSION in the Makefile to v2.1.2.

Linting Configuration Enhancements:

  • Restructured .golangci.yml to use version 2, added new output formats, enabled specific linters (e.g., errcheck, goconst, gocyclo), and introduced exclusion presets for better control over linting results.

Summary by CodeRabbit

  • Chores
    • Upgraded golangci-lint to version 2.1.2 across workflows and development tools.
    • Updated linting configuration for improved modularity, enhanced exclusions, and revised enabled linters.
    • Adjusted GitHub Actions workflow to use the latest golangci-lint action version.

Signed-off-by: chlins <chlins.zhang@gmail.com>
@coderabbitai
Copy link

coderabbitai bot commented Apr 17, 2025

Walkthrough

The changes update the project's linting infrastructure to align with the latest versions of golangci-lint. The GitHub Actions workflow now references the v7.0.0 release of the golangci-lint action and uses golangci-lint v2.1. The .golangci.yml configuration file is upgraded to version 2 format, introducing modular sections for linters, output, exclusions, issues, and formatters, and adjusting enabled linters and exclusion rules. The Makefile is also updated to install golangci-lint v2.1.2 by default. No application logic or exported entities are affected.

Changes

File(s) Change Summary
.github/workflows/lint.yml Updated golangci-lint GitHub Action from a commit hash to v7.0.0 and upgraded golangci-lint version to v2.1.
.golangci.yml Upgraded config to version 2 format; restructured sections; modified enabled linters, exclusions, and output.
Makefile Changed default golangci-lint version from v1.54.2 to v2.1.2.

Poem

In the warren, we lint and we leap,
With tools all shiny and new.
Our configs are tidy, our code is neat,
As golangci hops to version two!
The Makefile’s fresh, the workflow’s spry—
Now our code can reach for the sky!
🐇✨

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 28c12d6 and ccfa045.

📒 Files selected for processing (3)
  • .github/workflows/lint.yml (1 hunks)
  • .golangci.yml (1 hunks)
  • Makefile (1 hunks)
🔇 Additional comments (11)
Makefile (1)

62-62: Version bump to v2.1.2
This updates the default GolangCI-Lint installer to match the new toolchain version.

.golangci.yml (9)

1-1: Upgrade to GolangCI-Lint config v2
Using version: "2" enables the new, modular configuration schema introduced in v2.


4-9: Define detailed output formats
The output.formats.text block ensures lint results include linter names and line numbers in stdout for clarity.


11-18: Disable all linters by default and selectively enable
Switching to default: none and explicitly enabling key linters (errcheck, goconst, gocyclo, govet, misspell, staticcheck) tightens control over lint checks.


19-21: Configure gocyclo complexity threshold
The threshold is set to 100; please verify this aligns with your code complexity goals—consider lowering if stricter function complexity enforcement is desired.


22-32: Add exclusion presets and custom lint rules
The new exclusions section with built-in presets and a rule to ignore SA1019 warnings should help reduce false positives.


33-37: Exclude generated and third-party code by path
Paths like third_party, builtin, examples, and test/mocks will be skipped; confirm these patterns match your project’s directory structure.


39-39: Focus on new lint issues
Setting issues.new: true surfaces only new problems, making incremental lint improvements more manageable.


40-49: Enable gci and gofmt formatters
Configuring these formatters enforces import grouping and formatting standards; the gci sections align with your module path.


50-55: Exclude generated code and paths from formatting
Mirroring lint exclusions for formatters prevents unintended changes in generated or third-party files.

.github/workflows/lint.yml (1)

23-27: Update GitHub Action to golangci-lint-action@v7.0.0 and version v2.1
Switching from a commit SHA to the official v7.0.0 tag and bumping the lint tool version in CI aligns with the tooling upgrades in the Makefile and config.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@chlins chlins added the dependencies Pull requests that update a dependency file label Apr 17, 2025
@chlins
Copy link
Member Author

chlins commented Apr 17, 2025

@coderabbitai full review

@coderabbitai
Copy link

coderabbitai bot commented Apr 17, 2025

✅ Actions performed

Full review triggered.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
.github/workflows/lint.yml (1)

24-27: Align CI and local golangci-lint versions
The workflow currently pins version: v2.1, whereas the Makefile installs v2.1.2. For deterministic CI runs, consider using the exact patch version in both places.

-          version: v2.1
+          version: v2.1.2
.golangci.yml (1)

20-21: Review gocyclo complexity threshold
Setting min-complexity: 100 effectively disables complexity checks for most functions. Consider lowering this closer to the community default (e.g., 15) to catch overly complex code.

 linters:
   settings:
     gocyclo:
-      min-complexity: 100
+      min-complexity: 15
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 28c12d6 and ccfa045.

📒 Files selected for processing (3)
  • .github/workflows/lint.yml (1 hunks)
  • .golangci.yml (1 hunks)
  • Makefile (1 hunks)
🔇 Additional comments (11)
Makefile (1)

62-62:

Details

✅ Verification successful

Ensure the new golangci-lint version exists
The GOLANGCI_LINT_VERSION was bumped to v2.1.2 to align with the updated CI setup. Please verify that this tag is present in the upstream repository to prevent installation failures.

Run the following to confirm:


🏁 Script executed:

#!/usr/bin/env bash
set -e
# Verify that v2.1.2 exists in golangci-lint releases
gh api repos/golangci/golangci-lint/releases/tags/v2.1.2

Length of output: 69690


golangci‑lint v2.1.2 tag verified
Confirmed that the v2.1.2 release exists upstream (https://github.com/golangci/golangci-lint/releases/tag/v2.1.2); the version bump is safe.

.golangci.yml (10)

1-1: Upgrade to configuration version 2
Switching to version: "2" is required for the new YAML schema. This aligns with golangci-lint v2.x.


4-9: Define output format for lint results
The output.formats.text block directs linter names and issued lines to stdout, improving readability in CI logs. This setup looks correct.


11-18: Enable specific linters with default: none
Using default: none and explicitly enabling errcheck, goconst, gocyclo, govet, misspell, and staticcheck provides fine-grained control. Approved.


23-29: Refine exclusion presets and generated code handling
Applying generated: lax alongside standard presets (comments, common-false-positives, legacy, std-error-handling) is consistent with common practice. Ensure any custom-generated files in this repo are covered.


31-33: Exclude specific staticcheck warnings
Ignoring the SA1019 deprecation warnings is acceptable if you have a migration plan. With issues.new: true, regressions will still surface.


34-37: Exclude third-party and mock directories
Paths like third_party, builtin, examples, and test/mocks are properly excluded. Double‑check for other vendored or generated directories that might need exclusion.


39-40: Only report new issues
Setting issues.new: true is ideal for incremental lint adoption—CI will only fail on fresh violations.


41-44: Enable gci and gofmt formatters
Adding formatters for import grouping (gci) and code formatting (gofmt) ensures consistency across the codebase.


45-50: Configure gci import sections
The ordering (standard, default, prefix(github.com/CloudNativeAI/modctl)) aligns with Go community conventions. Approved.


51-55: Formatters exclusion patterns
Excluding generated code and matching path patterns for formatters keeps behavior consistent with the linters.

Copy link
Member

@gaius-qi gaius-qi left a comment

Choose a reason for hiding this comment

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

LGTM

@gaius-qi gaius-qi merged commit 4764d65 into main Apr 17, 2025
6 checks passed
@gaius-qi gaius-qi deleted the chore/golangci-lint-v2 branch April 17, 2025 08:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants