reference Flags

--replacement

Accepted by
opengrep scan
Value
EXPRESSION
See also
--pattern, --autofix, --dryrun, fix

Sets a fix for the pattern given with -e/--pattern, as the fix key does for a rule. The metavariables of the pattern can be used in it: -e 'eval($X)' --replacement 'safe($X)' replaces the call with a call to safe that has the same argument.

The flag applies only to a command-line pattern; rules from a rule file have their own fix. As with the fix of a rule, the change is written to the files only with --autofix, and --dryrun shows it without writing it.

Examples

app.py
eval(1)print(2)
Command and result
$ opengrep scan -q -e 'eval($X)' -l python --replacement 'safe($X)' --autofix --dryrun app.py
app.py

     1: safe(1)
   fix: safe(1)
$ cat app.py
eval(1)
print(2)

The file is unchanged: --dryrun showed the fix instead of writing it.