Skip to content

ast_grep_replace: dryRun previews invalid rewrites as success; $$$ captures flatten multi-line matches #827

Open

Description

@null-axiom

AFT: 0.62.0, OpenCode 2.1.4, macOS.

Two ast_grep_replace problems:

  1. dryRun previews an invalid rewrite as success, while apply refuses it. Pattern foo($A, $B), rewrite bar($B, $A (unbalanced), lang: typescript, dryRun: true → "Would replace 2 match(es)" with a diff containing bar(2, 1;. Without dryRun an invalid rewrite fails with "rewritten code failed syntax validation; no files were written". The preview should run the same validation, so a preview never promises a change apply will reject.
  2. Variadic captures flatten multi-line matches. Source foo(\n 3,\n 4\n);, pattern foo($$$A), rewrite bar($$$A) → bar(3,\n4); (indentation lost; dryRun and apply agree). Expected the captured nodes to keep their original separators/indentation. Relatedly ast_grep_search displays the capture as $A: 1,,,2.

Working as expected: $$$ matching, ignoring matches in strings/comments, globs and negated globs, dryRun leaving files untouched, apply matching the preview for valid rewrites.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions