--matching-diagnosis
- Accepted by
opengrep test- See also
opengrep test,--matching-explanations
A failing test of opengrep test lists the lines that were missed or reported incorrectly. With --matching-diagnosis, the output also has a section that explains each of these lines: which part of the pattern did not match, or which condition removed the match.
--matching-explanations provides similar information in the JSON output of a scan.
Examples
Why a line was not matched
find-eval.yaml
rules: - id: find-eval pattern: eval(...) message: found eval languages: [python] severity: WARNINGfind-eval.py
# ruleid: find-evalevaluate(1)Command and result
$ opengrep test --matching-diagnosis . 2>&1 | grep -A2 'Matching diagnosis:'
Matching diagnosis:
find-eval.py: Unexpected lack of match at line 2
This line was never matched by any base pattern, nor introduced by any `focus-metavariable`.The annotation asks for a match on line 2, which evaluate(1) does not produce, so the test fails and the diagnosis says the line matched no pattern at all.