reference Rule options

xml_singleton_loose_matching

Value
true or false
Default
true
See also
xml_attrs_implicit_ellipsis, xml_children_ordered

In XML patterns, and in the XML-like syntax of other languages, an element written with open and close tags, <item id="$X"></item>, also matches the self-closing <item id="1"/>, and vice versa.

With xml_singleton_loose_matching: false, each form matches only itself.

Examples

Two ways to write an empty element

The rule item turns the option off.

items.yaml
rules:  - id: item-default    pattern: <item id="$X"></item>    message: item $X    languages: [xml]    severity: INFO  - id: item    pattern: <item id="$X"></item>    message: item $X    languages: [xml]    severity: INFO    options:      xml_singleton_loose_matching: false
items.xml
<root><!-- ruleid: item-default, item --><item id="1"></item><!-- ruleid: item-default --><item id="2"/></root>
Command and result
$ opengrep test .
2/2: ✓ All tests passed
No tests for fixes found.