Skip to content

feat(golang): add golangci-lint 2.x support#53

Merged
tagoro9 merged 1 commit intomainfrom
f/golangci-lint-2
Feb 3, 2026
Merged

feat(golang): add golangci-lint 2.x support#53
tagoro9 merged 1 commit intomainfrom
f/golangci-lint-2

Conversation

@tagoro9
Copy link
Contributor

@tagoro9 tagoro9 commented Feb 3, 2026

Description

Add version detection to handle golangci-lint 2.x which has different default linters and output format flags. Maintain backward compatibility with 1.x versions.

Not as part of this, but I wonder if we should be moving to https://github.com/golangci/golangci-lint/blob/main/.pre-commit-hooks.yaml. They have their own pre-commit hooks now.

Changes

  • feat(golang): add golangci-lint 2.x support

🚀 PR created with fotingo

Add version detection to handle golangci-lint 2.x which has different
default linters and output format flags. Maintain backward compatibility
with 1.x versions.
@tagoro9 tagoro9 requested a review from a team as a code owner February 3, 2026 22:14
@turo-ai-code-review turo-ai-code-review bot added the claude-in-review Claude PR review is currently in progress label Feb 3, 2026
@github-actions
Copy link

github-actions bot commented Feb 3, 2026

Release notes preview

Below is a preview of the release notes if your PR gets merged.


4.1.0 (2026-02-03)

Features

  • golang: add golangci-lint 2.x support (68bc063)

Bug Fixes

  • gha: fix semantic-release (71963f8)
  • gha: update to use lint-release-notes@v4 (5feab1c)
  • golang: workaround to handle golangci in different versions (8453b86)

Comment on lines 24 to +25
else
# version < 1.55.0 → use --out-format
format_flag="--out-format"
fi
## golangci-lint 1.x

Choose a reason for hiding this comment

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

suggestion (consistency): This uses a different extraction pattern (grep -oP) than the major version extraction (line 11 uses sed -n). Consider using a single consistent approach for maintainability.

Why this matters: Using different regex engines (PCRE via grep -P vs sed) makes the code harder to maintain and reason about. If one pattern needs updating, it's unclear whether both should be updated.

Suggested approach: Extract the full version once at the top, then derive both major and full version from it:

Suggested change
else
# version < 1.55.0 → use --out-format
format_flag="--out-format"
fi
## golangci-lint 1.x
## Extract full semver for 1.x format flag detection
version=$(echo "$version_output" | sed -n 's/.*version \([0-9]*\.[0-9]*\.[0-9]*\).*/\1/p')

This maintains consistency with the sed-based approach while supporting the 1.55.0 comparison logic.

version=$(echo "$version_output" | grep -oP 'version \K[0-9]+\.[0-9]+\.[0-9]+')
## Extract major version number (e.g., 1 or 2)
major_version=$(echo "$version_output" | sed -n 's/.*version \([0-9]*\).*/\1/p')

Choose a reason for hiding this comment

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

issue (reliability): The sed pattern 's/.*version \([0-9]*\).*/\1/p' may silently fail if golangci-lint --version output format changes or doesn't match expectations.

Why this matters: If the extraction fails, $major_version will be empty, causing the comparison [ "$major_version" = "2" ] to always fail. This would silently fall back to 1.x behavior even when running 2.x, potentially causing linter failures or unexpected behavior.

Suggested fix: Add explicit validation after extraction:

Suggested change
major_version=$(echo "$version_output" | sed -n 's/.*version \([0-9]*\).*/\1/p')
## Validate major version was successfully extracted
if [ -z "$major_version" ]; then
echo "Error: Failed to extract golangci-lint major version from: $version_output" >&2
return 1
fi

This ensures the script fails fast with a clear error message rather than silently misbehaving.

@turo-ai-code-review
Copy link

Overall Assessment: APPROVE

This PR adds support for golangci-lint 2.x while maintaining backward compatibility with 1.x versions. The implementation correctly identifies that 2.x has different default linters and removes deprecated format flags. The approach is sound and the logic properly branches based on detected major version.

Critical Issues Found

None - the logic is functionally correct and will work as intended.

Performance Concerns

None identified.

Business Logic Review Required

None - this is a straightforward tooling compatibility update.

Notes for Human Reviewers

Two inline comments have been posted suggesting reliability improvements:

  1. Adding validation for version extraction to fail fast if parsing fails (currently fails silently)
  2. Using consistent regex approach between major version and full version extraction

These are code quality suggestions, not blocking issues. The current implementation will work correctly when golangci-lint version output follows expected format, which is the standard case.

Copy link

@turo-ai-code-review turo-ai-code-review bot left a comment

Choose a reason for hiding this comment

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

Automated review complete. No critical issues found.
See this FAQ on how to interact with this review bot.

@turo-ai-code-review turo-ai-code-review bot removed the claude-in-review Claude PR review is currently in progress label Feb 3, 2026
@tagoro9 tagoro9 merged commit 0ef7538 into main Feb 3, 2026
5 of 6 checks passed
@tagoro9 tagoro9 deleted the f/golangci-lint-2 branch February 3, 2026 23:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants