fix: prevent rtk read from corrupting JSON/data files (#464)#522
fix: prevent rtk read from corrupting JSON/data files (#464)#522ousamabenyounes wants to merge 1 commit intortk-ai:developfrom
Conversation
|
LGTM — good fix for a nasty bug. Adding Build passes, 55 filter tests pass. The exact reproduction case from #464 ( One nit (non-blocking): the version bumps in ARCHITECTURE.md/CLAUDE.md/README.md are unrelated noise — ideally drop them from this PR since release-please handles versions. But not a blocker. @aeppling for merge. |
cded07a to
5f4ea62
Compare
|
Thanks! Removed the version bumps from ARCHITECTURE.md, CLAUDE.md and README.md — rebased on latest Note: the Benchmark and Documentation Validation checks are failing due to pre-existing issues on |
Add Language::Data variant for data formats (JSON, YAML, TOML, XML, CSV, etc.) with empty comment patterns to prevent comment stripping. AggressiveFilter falls back to MinimalFilter for data files. Fixes rtk-ai#464 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Signed-off-by: Ousama Ben Younes <benyounes.ousama@gmail.com>
5f4ea62 to
9533614
Compare
Summary
Fixes #464 —
rtk read package.jsoncorrupts JSON files when string values contain/*or*/.Root cause:
.jsonfiles were classified asLanguage::Unknown, which uses/*/*/as block comment delimiters. The string"packages/*"was interpreted as opening a block comment, and"**/package.json"as closing it — everything between was silently deleted.Fix: Add
Language::Datavariant with no comment patterns. JSON, YAML, TOML, XML, CSV, Markdown, and other data formats skip all comment stripping and code filtering entirely.Before/After
Why this matters
package.jsonis read dozens of times per Claude session. When corrupted:Also affects:
tsconfig.json,docker-compose.yml,Cargo.lock,.env,schema.graphql,*.sql, etc.Affected extensions
json,jsonc,json5,yaml,yml,toml,xml,csv,tsv,graphql,gql,sql,md,markdown,txt,env,lockTest plan
test_language_detection_data_formats— all data extensions map toLanguage::Datatest_json_no_comment_stripping— reproduces exact bug:rtk readcorruptspackage.jsonwhen JSON strings contain/*or*/#464 scenario (packages/*, scripts, lint-staged)test_json_aggressive_filter_preserves_structure— aggressive filter also safe for JSONrtk read package.jsonwith the exact fixture from the issuevalidate-docs.shpassesGenerated with Claude Code