Skip to content

Add the rr object, pad() and print() to --js to close #856 - #857

Closed
mathiasrw wants to merge 2 commits into
fix/854from
fix/856
Closed

mathiasrw wants to merge 2 commits into
fix/854from
fix/856

Conversation

@mathiasrw

@mathiasrw mathiasrw commented Oct 25, 2026 •

Copy link
Copy Markdown
Owner

Closes #856

Stacked on #855.

Change

  • rr is the object behind the short names. rr.year is $year, rr[1] is $1, and rr.n is $n, with all the cousins, like rr.n00 and rr.year_. Groups are text and the numbers are numbers. A named group overwrites a name it shares, also _.
  • rr._ has the values of RexReplace with long names:
    • rr._.fileInfo: filePath, filePathRel, dirPath, dirPathRel, dirName, fileName, name, ext, bytes, size, mtime, ctime, mtimeObj, ctimeObj
    • rr._.count: fileNumber ($n), filesTotal ($t), matchedFileNumber ($i), changedFileNumber ($c), matchThisFile ($m), matchUntilNow ($M)
    • text, find, pipe, cwd, time, timeObj
  • rr.stdin is the piped data, and rr.print() and rr.printErr() print to stdout and stderr with a line break, also with --quiet-total.
  • pad(value, width = 3, char = '0'), like pad($1) for 007.
  • file_path and file_path_rel, the same as file and file_rel, with their space cousins.
  • Code that uses rr runs once per match, as it can reach a group in a way the search of the code can not see. It is found as rr. or rr[ with no letter, digit, _ or $ in front.
  • Code that runs once per file now runs at its first match, so a file without a match does not run it. Before, it ran for every file, and the result was thrown away.

The rr object is only made when the code uses it. The values of the file are made once per file, and each match gets an object on top with $m, $M, the groups and the counts. 20 000 matches: $1.toUpperCase() takes 230 ms, as before, and rr[1].toUpperCase() 287 ms.

Tests

test/fix/856.test.js is new, and 19 of its 20 tests fail without the change. The one that passes checks that brr.n is not taken for rr.n. It covers each short name in rr, text and numbers, the run per match, a group that overwrites rr.n and rr._, the long names of a file and of the counts over three files, rr.print with --quiet-total, rr.printErr, rr.stdin, pad(), file_path, and that a file without a match does not run the code. The help and the README tell all of it. yarn test-ci passes.

Follow-up

For #855: shorter help for -E and --flags, and the comments that said what the code does are gone or say why now.

@mathiasrw

Copy link
Copy Markdown
Owner Author

Replaced by #861 after the review of 26 October: one flat rr object with long names, and the change for files with no match in its own PR, #860.

@mathiasrw mathiasrw closed this Oct 27, 2026
@mathiasrw
mathiasrw deleted the fix/856 branch October 27, 2026 02:04
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.

1 participant