reference Rule options

commutative_boolop

Value
true or false
Default
false
See also
ac_matching

With commutative_boolop: true, the boolean operators && and ||, and and or in Python, are matched like | is under ac_matching: the operands of the pattern may appear in any order, among other operands. user.isAdmin && req.secure then matches req.secure && user.active && user.isAdmin.

It depends on ac_matching, and has no effect when that option is false.

Examples

Conditions in a different order

The rule admin-over-https turns the option on.

admin.yaml
rules:  - id: admin-over-https-default    pattern: user.isAdmin && req.secure    message: admin request over HTTPS    languages: [javascript]    severity: WARNING  - id: admin-over-https    pattern: user.isAdmin && req.secure    message: admin request over HTTPS    languages: [javascript]    severity: WARNING    options:      commutative_boolop: true
admin.js
// ruleid: admin-over-https-default, admin-over-httpsif (user.isAdmin && req.secure) {}// ruleid: admin-over-httpsif (req.secure && user.isAdmin) {}// ruleid: admin-over-httpsif (req.secure && user.active && user.isAdmin) {}
Command and result
$ opengrep test .
2/2: ✓ All tests passed
No tests for fixes found.