-
Notifications
You must be signed in to change notification settings - Fork 0
feat(golang): add golangci-lint 2.x support #53
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,32 +7,49 @@ lint_all() { | |||||||||||||||
| version_output=$(golangci-lint --version) | ||||||||||||||||
| echo "$version_output" | ||||||||||||||||
|
|
||||||||||||||||
| ## Extract semver number (e.g., 1.54.2 or 2.1.2) | ||||||||||||||||
| 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') | ||||||||||||||||
|
|
||||||||||||||||
| ## Use correct format flag depending on version | ||||||||||||||||
| if [ "$(printf '%s\n' "$version" "1.55.0" | sort -V | head -n1)" = "1.55.0" ]; then | ||||||||||||||||
| # version >= 1.55.0 → use --format | ||||||||||||||||
| format_flag="--format" | ||||||||||||||||
| if [ "$major_version" = "2" ]; then | ||||||||||||||||
| ## golangci-lint 2.x | ||||||||||||||||
| ## - Default linters (errcheck, govet, ineffassign, staticcheck, unused) are enabled by default | ||||||||||||||||
| ## - Output format flags changed to --color | ||||||||||||||||
| golangci-lint run \ | ||||||||||||||||
| --allow-parallel-runners \ | ||||||||||||||||
| --fix \ | ||||||||||||||||
| --verbose \ | ||||||||||||||||
| --color always \ | ||||||||||||||||
| --timeout 5m \ | ||||||||||||||||
| ./... | ||||||||||||||||
| else | ||||||||||||||||
| # version < 1.55.0 → use --out-format | ||||||||||||||||
| format_flag="--out-format" | ||||||||||||||||
| fi | ||||||||||||||||
| ## golangci-lint 1.x | ||||||||||||||||
|
Comment on lines
24
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (consistency): This uses a different extraction pattern ( 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
This maintains consistency with the sed-based approach while supporting the 1.55.0 comparison logic. |
||||||||||||||||
| ## Extract full semver number for 1.x format flag detection | ||||||||||||||||
| version=$(echo "$version_output" | sed -n 's/.*version \([0-9]*\.[0-9]*\.[0-9]*\).*/\1/p') | ||||||||||||||||
|
|
||||||||||||||||
| ## Use correct format flag depending on version | ||||||||||||||||
| if [ "$(printf '%s\n' "$version" "1.55.0" | sort -V | head -n1)" = "1.55.0" ]; then | ||||||||||||||||
| # version >= 1.55.0 → use --format | ||||||||||||||||
| format_flag="--format" | ||||||||||||||||
| else | ||||||||||||||||
| # version < 1.55.0 → use --out-format | ||||||||||||||||
| format_flag="--out-format" | ||||||||||||||||
| fi | ||||||||||||||||
|
|
||||||||||||||||
| golangci-lint run \ | ||||||||||||||||
| --allow-parallel-runners \ | ||||||||||||||||
| --fix \ | ||||||||||||||||
| --verbose \ | ||||||||||||||||
| "$format_flag" colored-line-number \ | ||||||||||||||||
| --color always \ | ||||||||||||||||
| --enable errcheck \ | ||||||||||||||||
| --enable gosimple \ | ||||||||||||||||
| --enable govet \ | ||||||||||||||||
| --enable ineffassign \ | ||||||||||||||||
| --enable staticcheck \ | ||||||||||||||||
| --enable unused \ | ||||||||||||||||
| --timeout 5m \ | ||||||||||||||||
| ./... | ||||||||||||||||
| golangci-lint run \ | ||||||||||||||||
| --allow-parallel-runners \ | ||||||||||||||||
| --fix \ | ||||||||||||||||
| --verbose \ | ||||||||||||||||
| "$format_flag" colored-line-number \ | ||||||||||||||||
| --color always \ | ||||||||||||||||
| --enable errcheck \ | ||||||||||||||||
| --enable gosimple \ | ||||||||||||||||
| --enable govet \ | ||||||||||||||||
| --enable ineffassign \ | ||||||||||||||||
| --enable staticcheck \ | ||||||||||||||||
| --enable unused \ | ||||||||||||||||
| --timeout 5m \ | ||||||||||||||||
| ./... | ||||||||||||||||
| fi | ||||||||||||||||
| return $? | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
|
||||||||||||||||
There was a problem hiding this comment.
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 ifgolangci-lint --versionoutput format changes or doesn't match expectations.Why this matters: If the extraction fails,
$major_versionwill 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:
This ensures the script fails fast with a clear error message rather than silently misbehaving.