Skip to content

Commit 10c7c70

Browse files
committed
Activated 'make validateRules' and improved rule XML file parsing. Now, it optionally accepts '<rules>...</rules>' tags to make xmllint happy.
1 parent 1d5166d commit 10c7c70

4 files changed

Lines changed: 31 additions & 27 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ checkCWEEntries: /tmp/errorlist.xml
389389
$(PYTHON_INTERPRETER) tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml
390390
.PHONY: validateRules
391391
validateRules:
392-
#xmllint --noout rules/*.xml
392+
xmllint --noout rules/*.xml
393393

394394
###### Build
395395

cli/cmdlineparser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -713,6 +713,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
713713
tinyxml2::XMLDocument doc;
714714
if (doc.LoadFile(12+argv[i]) == tinyxml2::XML_SUCCESS) {
715715
tinyxml2::XMLElement *node = doc.FirstChildElement();
716+
if (node && strcmp(node->Value(), "rules") == 0)
717+
node = node->NextSiblingElement("rules");
716718
for (; node && strcmp(node->Value(), "rule") == 0; node = node->NextSiblingElement()) {
717719
Settings::Rule rule;
718720

rules/token-matching.xml

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,43 @@
11
<?xml version="1.0"?>
2-
<rule version="1">
2+
<rules>
3+
<rule version="1">
34
<pattern>Token :: (?:findm|(?:simple|)M)atch \([^,]+,\s+"(?:\s+|[^"]+?\s+")</pattern>
45
<message>
5-
<id>TokenMatchSpacing</id>
6-
<severity>style</severity>
7-
<summary>Useless extra spacing for Token::*Match.</summary>
6+
<id>TokenMatchSpacing</id>
7+
<severity>style</severity>
8+
<summary>Useless extra spacing for Token::*Match.</summary>
89
</message>
9-
</rule>
10-
<rule version="1">
10+
</rule>
11+
<rule version="1">
1112
<pattern>(?U)Token :: Match \([^,]+,\s+"[^%|!\[\]]+" \)</pattern>
1213
<message>
13-
<id>UseTokensimpleMatch</id>
14-
<severity>error</severity>
15-
<summary>Token::simpleMatch should be used to match tokens without special pattern requirements.</summary>
14+
<id>UseTokensimpleMatch</id>
15+
<severity>error</severity>
16+
<summary>Token::simpleMatch should be used to match tokens without special pattern requirements.</summary>
1617
</message>
17-
</rule>
18-
<rule version="1">
18+
</rule>
19+
<rule version="1">
1920
<pattern>\b[\w_]+ \. tokAt \( 0 \)</pattern>
2021
<message>
21-
<id>TokentokAt0</id>
22-
<severity>error</severity>
23-
<summary>tok->tokAt(0) is a slow way to say tok.</summary>
22+
<id>TokentokAt0</id>
23+
<severity>error</severity>
24+
<summary>tok-&gt;tokAt(0) is a slow way to say tok.</summary>
2425
</message>
25-
</rule>
26-
<rule version="1">
26+
</rule>
27+
<rule version="1">
2728
<pattern>\b[\w_]+ \. strAt \( 0 \)</pattern>
2829
<message>
29-
<id>TokenstrAt0</id>
30-
<severity>error</severity>
31-
<summary>tok->strAt(0) is a slow way to say tok->str()</summary>
30+
<id>TokenstrAt0</id>
31+
<severity>error</severity>
32+
<summary>tok-&gt;strAt(0) is a slow way to say tok-&gt;str()</summary>
3233
</message>
33-
</rule>
34-
<rule version="1">
34+
</rule>
35+
<rule version="1">
3536
<pattern><![CDATA[Token :: Match \( (\b\w+\b) , \"%var%\" \) && (\b\1\b) \. variable \( \)]]></pattern>
3637
<message>
37-
<id>TokenMatchVariable</id>
38-
<severity>error</severity>
39-
<summary>Simplify 'Token :: Match ( expr , %var% ) &amp;&amp; expr->variable()' to 'expr->variable()'</summary>
38+
<id>TokenMatchVariable</id>
39+
<severity>error</severity>
40+
<summary>Simplify 'Token :: Match ( expr , %var% ) &amp;&amp; expr-&gt;variable()' to 'expr-&gt;variable()'</summary>
4041
</message>
41-
</rule>
42+
</rule>
43+
</rules>

tools/dmake.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ int main(int argc, char **argv)
503503
fout << "\t$(PYTHON_INTERPRETER) tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml\n";
504504
fout << ".PHONY: validateRules\n";
505505
fout << "validateRules:\n";
506-
fout << "\t#xmllint --noout rules/*.xml\n";
506+
fout << "\txmllint --noout rules/*.xml\n";
507507

508508
fout << "\n###### Build\n\n";
509509

0 commit comments

Comments
 (0)