symmetric_eq
- Value
trueorfalse- Default
false- See also
ac_matching
With symmetric_eq: true, request.method == "POST" also matches "POST" == request.method, and the same holds for !=. Other comparisons keep their order: limit < count does not match count > limit.
It depends on ac_matching, and has no effect when that option is false.
commutative_compop is an older name for this option. It still works, but it prints a deprecation warning for every == and != the rule is matched against.
Examples
A comparison in the reverse order
The rule post-request turns the option on.
post.yaml
rules: - id: post-request-default pattern: request.method == "POST" message: handles a POST request languages: [python] severity: WARNING - id: post-request pattern: request.method == "POST" message: handles a POST request languages: [python] severity: WARNING options: symmetric_eq: truepost.py
def handle(request): # ruleid: post-request-default, post-request if request.method == "POST": pass # ruleid: post-request if "POST" == request.method: passCommand and result
$ opengrep test .
2/2: ✓ All tests passed
No tests for fixes found.The old name
compop.yaml
rules: - id: post-request pattern: request.method == "POST" message: handles a POST request languages: [python] severity: WARNING options: commutative_compop: truecompop.py
def handle(request): if "POST" == request.method: pass if request.method == "GET": pass if user.role == "admin": passCommand and result
$ opengrep scan --config compop.yaml compop.py 2>&1 >/dev/null | grep -m1 deprecated
warning `commutative_compop` rule option has been deprecated. Please use `symmetric_eq` instead.
$ opengrep scan --config compop.yaml compop.py 2>&1 >/dev/null | grep -c deprecated
3The three comparisons produce three warnings, although only the first matches.