fix(cmds/ruby): accept version-only JSON from rubocop/rspec --version#1982
Open
YOMXXX wants to merge 1 commit into
Open
fix(cmds/ruby): accept version-only JSON from rubocop/rspec --version#1982YOMXXX wants to merge 1 commit into
YOMXXX wants to merge 1 commit into
Conversation
Root cause: `rubocop --version` and `rspec --version` emit minimal JSON
like `{"version":"1.86.2"}` which doesn't match the lint/test report
struct (missing `files` / `examples`). The full-struct parser fails,
triggers `[rtk] ...: JSON parse failed (...)` plus a second "output
format not recognized, showing last 5 lines" warning, polluting stdout
with noise for what is otherwise a clean version query.
Fix: detect version-only JSON shape (`{"version":"..."}` with no
report-specific keys) before attempting the full-struct parse. When
matched, emit a clean `rubocop X.Y.Z` / `rspec X.Y.Z` line, suppress
the warnings, and exit 0. Real reports that happen to include a
`version` field still go through the report parser (regression-guarded).
Tests:
- version-only JSON returns clean line, no warning markers
- whitespace-tolerant detection
- regression: real report with `version` still parses normally
- non-object / malformed JSON rejected by detector (falls through)
Fixes rtk-ai#1946
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1946.
rtk rubocop --versionandrtk rspec --versionwere pollutingstdout with two redundant warnings:
This PR detects the minimal
{"version":"..."}JSON shape emitted by--versionqueries before attempting the full lint/test report parse andsurfaces it as a clean
rubocop 1.86.2/rspec 3.13.2line.Root cause
Both modules inject
--format jsonto get structured output. When the userruns
--version, the tool emits{"version":"..."}instead of a full report.The strongly-typed struct (
RubocopOutput { files, summary }/RspecOutput { examples, summary }) rejects it, the JSON parse error islogged, and
fallback_tailadds a second "output format not recognized"warning before printing the raw line.
Fix
In
filter_rubocop_jsonandfilter_rspec_output, run a lightweightdetector first:
serde_json::Value.versionkey.files/summary/metadatafor rubocop,
examples/summary/summary_linefor rspec) — that meansit's a real report, not a
--versionquery.<tool> <version>cleanly with no warnings.Real reports that happen to carry a
versionfield (which RSpec's JSONformatter does) still flow through the existing report parser; covered by
regression tests.
Test plan
cargo fmt --allcargo clippy --all-targets(zero warnings)cargo test --bin rtk— 1909 passed, 0 failedtest_filter_rubocop_version_only_json_cleantest_filter_rubocop_version_only_json_with_whitespacetest_filter_rubocop_version_only_does_not_swallow_real_reporttest_try_version_only_json_rejects_non_objecttest_filter_rspec_version_only_json_cleantest_filter_rspec_version_only_json_with_whitespacetest_filter_rspec_version_only_does_not_swallow_real_reporttest_try_version_only_json_rspec_rejects_non_objectFiles changed
src/cmds/ruby/rubocop_cmd.rs— addtry_version_only_json(), call it before report parse, add 4 testssrc/cmds/ruby/rspec_cmd.rs— same shape, 4 testsFixes #1946