Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ If planned renames clash, the process is halted and no change is applied to any
| `-r` | **`--rename`** Search and replace in the name of each file, and rename the file to the result. The folder and the content are not touched. If planned renames clash the process is halted and no change is applied to any file. [boolean] |
| | **`--rename-path`** Like --rename, but on the whole path of each file, so a / in the replacement moves the file. Folders that are not there are made. [boolean] |
| | **`--rename-force`** With --rename or --rename-path, write over a file that is there already. [boolean] |
| `-m` | **`--output-match`** Output each match on a new line. Will not replace any content but you still need to provide a dummy value (like `_`) as replacement parameter. If search pattern does not contain matching groups the full match will be outputted. If search pattern does contain matching groups only matching groups will be outputted (same line with no delimiter). [boolean] |
| `-m` | **`--output-match`** Output each match on a new line. Will not replace any content but you still need to provide a dummy value (like `_`) as replacement parameter. The replacement is not used, so --js code is not run. If search pattern does not contain matching groups the full match will be outputted. If search pattern does contain matching groups only matching groups will be outputted (same line with no delimiter). [boolean] |
| `-T` | **`--trim-pipe`** Trim piped data before processing. If piped data only consists of chars that can be trimmed (new line, space, tabs...) it will become an empty string. [boolean] |
| | **`--js-pipe`** Treat the replacement as javascript, and give the code the piped data as `pipe`. [boolean] |
| `-g` | **`--glob-pipe`** Each line of the piped data is a path or a glob of the files to work on. They are used together with the ones given as arguments. [boolean] |
Expand Down
2 changes: 1 addition & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ const yargs = require('yargs')
.describe(
'm',
`Output each match on a new line. ` +
`Will not replace any content but you still need to provide a dummy value (like \`_\`) as replacement parameter. ` +
`Will not replace any content but you still need to provide a dummy value (like \`_\`) as replacement parameter. The replacement is not used, so --js code is not run. ` +
`If search pattern does not contain matching groups the full match will be outputted. ` +
`If search pattern does contain matching groups only matching groups will be outputted (same line with no delimiter). ` +
``
Expand Down
4 changes: 4 additions & 0 deletions src/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ function newStatus(config) {
async function run(config) {
validateEncoding(config.encoding);

if (config.replacementJs && config.outputMatch) {
warn('The code is not run with --output-match, as only the matches are printed.');
}

if (config.expectZeroDiff && (config.expectDiff || config.expectDiffAll)) {
panic('--expect-zero-diff can not be used with --expect-diff or --expect-diff-all');
}
Expand Down
9 changes: 7 additions & 2 deletions test/engine/output-match.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,14 @@ describe('--output-match', () => {
).toBe('a.\n');
});

test('with --js the code is not run', async () => {
test('with --js the code is not run, and a warning tells so', async () => {
const config = {pipedData: 'foobar', outputMatch: true, replacementJs: true};
expect((await rr('[fb].', 'throw new Error("should not run")', config)).out).toBe('fo\nba\n');
expect(await rr('[fb].', 'throw new Error("should not run")', config)).toEqual({
out: 'fo\nba\n',
err: ' 馃煛 The code is not run with --output-match, as only the matches are printed.\n\n',
exit: null,
});
expect((await rr('[fb].', '_', {...config, quiet: true})).err).toBe('');
});

test('with --replacement-pipe the piped replacement is not used', async () => {
Expand Down
Loading