Skip to content

fix(golangci): detect major version and use correct output flag for v2#597

Open
bnema wants to merge 1 commit intortk-ai:developfrom
bnema:fix/golangci-v2-output-flags
Open

fix(golangci): detect major version and use correct output flag for v2#597
bnema wants to merge 1 commit intortk-ai:developfrom
bnema:fix/golangci-v2-output-flags

Conversation

@bnema
Copy link

@bnema bnema commented Mar 15, 2026

Summary

The golangci-lint wrapper injects --out-format=json to get structured output, but this flag was removed in golangci-lint v2. The wrapper now detects the installed major version and injects the correct flag.

What changed

The wrapper runs golangci-lint version before the actual lint invocation, parses the major version from the output, and selects the appropriate flag:

  • v2+: --output.json.path=stdout
  • v1: --out-format=json (existing behavior)

The user-supplied flag detection was also updated to recognise both v1 and v2 output flags, so the wrapper does not override them.

The version parsing logic is extracted into its own function with unit tests covering v1 output, v2 output, empty input, and garbage input. Three additional tests cover the flag detection for v1 flags, v2 flags, and no flags.

Related

Closes #596

References

@bnema bnema force-pushed the fix/golangci-v2-output-flags branch from 183ddc3 to ee04933 Compare March 15, 2026 06:34
golangci-lint v2 removed the --out-format flag. The wrapper now runs
golangci-lint version, parses the major version, and injects
--output.json.path=stdout for v2 or --out-format=json for v1.

The user-supplied flag detection is also updated to recognise both
v1 and v2 output flags.

Closes rtk-ai#596

Signed-off-by: brice <b@bnema.dev>
@aeppling aeppling added bug Something isn't working enhancement New feature or request labels Mar 17, 2026
@aeppling
Copy link
Contributor

Hello bnema !

Thanks for contributing ,

PR #612 also fix this, we need to review both to know which one to take for this fix.

@aeppling
Copy link
Contributor

After reviewing both this PR and #612 side-by-side, i'm in favor of #612 as the base for this fix because it addresses several additional issues that could cause problems:

  1. v2 stdout mixing: golangci-lint v2 emits both its default text summary and JSON to stdout simultaneously when using
    --output.json.path=stdout. This means serde_json::from_str would fail on the mixed output. fix: golangci-lint v1/v2 compatibility and non-run subcommand passthrough #612 solves this by writing JSON to a temp file instead.

  2. Subcommand passthrough: commands like rtk golangci-lint version or rtk golangci-lint linters currently break because run is always injected. fix: golangci-lint v1/v2 compatibility and non-run subcommand passthrough #612 detects non-run subcommands and passes them through.

  3. Fallback direction: defaulting to v1 on detection failure re-introduces the original bug for v2 users (the exact scenario this PR tries to fix). fix: golangci-lint v1/v2 compatibility and non-run subcommand passthrough #612 defaults to v2, which is the safer direction since v1 is EOL.

That said, your v prefix handling (trim_start_matches('v')) is something #612 is missing and would need to adopt, we've flagged that there.

Your work directly contributed to catching that gap.

@aeppling aeppling self-assigned this Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants