your-tools / ruplacer

Find and replace text in source files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: nothing found to replace when no match found

micisse opened this issue · comments

commented

In some cases, if no match is found, it's not a mistake.

For example: Read a folder with several files in it, then execute the ruplacer command for each file to replace, for example, "Hi" with "Bye" in each file read. If "Hi" is found, replace, otherwise skip (this should not be considered an error). If a match is found, OK, otherwise, SKIP. Wouldn't it be better to have a skip flag to prevent this behavior?

In my terminal, I get a lot of errors when there aren't any.

Capture d’écran_2023-09-19_23-52-43

Other proposal: With ripgrep for example, it's possible to display only the modified items in output and not the entire file content + changes, especially for large files. This could be an idea for a new feature flag.

Capture d’écran_2023-09-20_00-15-09

This looks like a bug - the message should only get printed once. How did you run ruplacer ?

commented

@dmerejkowsky In fact I use a regex on top of it to look for different files in which I want to make the changes. The ruplacer command is therefore called for each file in the loop, which is why the message is displayed several times, and that's normal. The problem is the error display. If ruplacer finds nothing, then there's nothing to change, so skip it (It's not a mistake). I don't pass global folder as arguments to ruplacer, but specific files.. For example:

// node
const result = /*find with regex somes files*/

result.forEach((file) => {
     const command = `ruplacer --go "find" "replace with" "${file}"`
    ...
})