Skip to content

fix(read): preserve template literals in aggressive filter#2430

Open
axelray-dev wants to merge 1 commit into
rtk-ai:developfrom
axelray-dev:fix/2421-aggressive-template-literal-preservation
Open

fix(read): preserve template literals in aggressive filter#2430
axelray-dev wants to merge 1 commit into
rtk-ai:developfrom
axelray-dev:fix/2421-aggressive-template-literal-preservation

Conversation

@axelray-dev

Copy link
Copy Markdown

Fixes #2421

What changed

AggressiveFilter::filter() did not track template literal (backtick) state. Lines inside multi-line JS/TS template literals that didn't match keep-patterns (imports, function signatures, const/let, braces) were silently dropped, corrupting the output.

The fix adds in_template_literal state tracking. Each line's backtick count is checked: an odd count toggles the state. Lines inside template literals are always preserved regardless of pattern matching.

Tests

3 new tests added to src/core/filter.rs:

  • test_aggressive_filter_preserves_multiline_template_literal -- multi-line template with # content
  • test_aggressive_filter_preserves_template_literal_expressions -- ${...} interpolation
  • test_aggressive_filter_preserves_multiple_template_literals -- two separate template literals in one file

Full suite: cargo test --all -- 2153 passed, 0 failed, 8 ignored.

Verification

cargo fmt --all && cargo clippy --all-targets && cargo test --all

All clean. DCO signed.

Signed-off-by: axelray-dev <110029405+axelray-dev@users.noreply.github.com>
@axelray-dev axelray-dev marked this pull request as ready for review June 13, 2026 14:24
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.

rtk read --level aggressive corrupts multi-line JS/TS template literals containing #

1 participant