--optimizations
- Accepted by
opengrep scan,opengrep ci- Value
allornone- Default
all- See also
--jobs,--timeout,--matching-explanations
With all, the default, the engine uses its optimizations. The main one is the prefilter: before a rule runs on a file, Opengrep determines from the literals of the rule whether the file can match, and skips the file when it cannot.
none turns the optimizations off and runs every rule on every candidate file. It serves as a diagnostic: a finding that is reported with --optimizations none but not without it shows that the prefilter skipped a file it should have scanned. Any other value is rejected, with exit status 2.
Examples
Running without the prefilter
rule.yaml
rules: - id: find-eval pattern: eval(...) message: found eval languages: [python] severity: WARNINGapp.py
eval(1)Command and result
$ opengrep scan -q --config rule.yaml --optimizations none app.py
app.py
warn find-eval
found eval
1: eval(1)
$ opengrep scan --config rule.yaml --optimizations some app.py 2>&1 >/dev/null | grep -o 'unsupported value.*'
unsupported value "some"