Skip to content

Fix --js code running for a file with no match #859

Closed

Description

@mathiasrw

Today

--js code that runs once per file runs at the start of each file, before the search, also when the file has no match. Its value is then not used.

> rexreplace foo 'console.error("ran for " + name); "x"' a.txt b.txt --js -S   # only a.txt has foo
ran for b
ran for a

So code with a side effect, like printing or writing a file, runs for files it does not change, and an error in the code is told for the first file, also when it has no match.

Change

The code runs at the first match of the file. A file with no match does not run it.

Good to know

Found in the review of 26 October. It changes what code with a side effect does, so it goes in the release note of v8.

Activity

  1. added a commit that references this issue on Oct 27, 2026
    4dbef7c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions