reference Rule options

ac_matching

Value
true or false
Default
true
See also
commutative_boolop, symmetric_eq

a | b | c is parsed as (a | b) | c. With ac_matching, on by default, a chain of one associative operator is matched as a flat list of operands, not as the nested pairs the parser produces. The effect depends on the operator:

With ac_matching: false, operators are matched as the parser nests them. commutative_boolop and symmetric_eq then have no effect.

Examples

Flags combined in any order

The rule trunc-create turns the option off.

flags.yaml
rules:  - id: trunc-create-default    pattern: os.O_CREAT | os.O_TRUNC    message: creates or truncates the file    languages: [python]    severity: WARNING  - id: trunc-create    pattern: os.O_CREAT | os.O_TRUNC    message: creates or truncates the file    languages: [python]    severity: WARNING    options:      ac_matching: false
flags.py
import osdef create(path):    # ruleid: trunc-create-default, trunc-create    os.open(path, os.O_CREAT | os.O_TRUNC)    # ruleid: trunc-create-default    os.open(path, os.O_WRONLY | os.O_CREAT | os.O_TRUNC)    # ruleid: trunc-create-default    os.open(path, os.O_TRUNC | os.O_WRONLY | os.O_CREAT)    # ok: trunc-create-default    os.open(path, os.O_CREAT | os.O_WRONLY)
Command and result
$ opengrep test .
2/2: ✓ All tests passed
No tests for fixes found.

A metavariable for several conditions

guard.yaml
rules:  - id: guard-default    pattern: user.active && $COND && user.admin    message: admin check with extra conditions    languages: [javascript]    severity: WARNING  - id: guard    pattern: user.active && $COND && user.admin    message: admin check with extra conditions    languages: [javascript]    severity: WARNING    options:      ac_matching: false
guard.js
// ruleid: guard-default, guardif (user.active && user.verified && user.admin) {}// ruleid: guard-defaultif (user.active && user.verified && req.secure && user.admin) {}
Command and result
$ opengrep test .
2/2: ✓ All tests passed
No tests for fixes found.