pattern-not-inside
- See also
pattern-inside,pattern-not,patterns
An item of patterns. It drops the matches of the other items that lie inside code matched by its own pattern. The pattern describes a safe context, such as a with block, a check that guards the call, or a function known to be harmless.
Like pattern-not, it is a negative item: it cannot stand at the top of a rule or among the alternatives of pattern-either.
Examples
A file opened outside a with block
open-without-with.yaml
rules: - id: open-without-with patterns: - pattern: open(...) - pattern-not-inside: | with open(...) as $F: ... message: file opened without a with block languages: [python] severity: INFOopen-without-with.py
# ruleid: open-without-withf = open("report.txt")data = f.read()# ok: open-without-withwith open("report.txt") as f: data = f.read()Command and result
$ opengrep test .
1/1: ✓ All tests passed
No tests for fixes found.