Activated 'make validateRules' and improved rule XML file parsing. Now, it optionally accepts '<rules>...</rules>' tags to make xmllint happy.

This commit is contained in:
orbitcowboy 2022-06-22 00:03:18 +02:00
parent 1d5166d70c
commit 10c7c70970
4 changed files with 31 additions and 27 deletions

View File

@ -389,7 +389,7 @@ checkCWEEntries: /tmp/errorlist.xml
$(PYTHON_INTERPRETER) tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml
.PHONY: validateRules
validateRules:
#xmllint --noout rules/*.xml
xmllint --noout rules/*.xml
###### Build

View File

@ -713,6 +713,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
tinyxml2::XMLDocument doc;
if (doc.LoadFile(12+argv[i]) == tinyxml2::XML_SUCCESS) {
tinyxml2::XMLElement *node = doc.FirstChildElement();
if (node && strcmp(node->Value(), "rules") == 0)
node = node->NextSiblingElement("rules");
for (; node && strcmp(node->Value(), "rule") == 0; node = node->NextSiblingElement()) {
Settings::Rule rule;

View File

@ -1,41 +1,43 @@
<?xml version="1.0"?>
<rule version="1">
<rules>
<rule version="1">
<pattern>Token :: (?:findm|(?:simple|)M)atch \([^,]+,\s+"(?:\s+|[^"]+?\s+")</pattern>
<message>
<id>TokenMatchSpacing</id>
<severity>style</severity>
<summary>Useless extra spacing for Token::*Match.</summary>
<id>TokenMatchSpacing</id>
<severity>style</severity>
<summary>Useless extra spacing for Token::*Match.</summary>
</message>
</rule>
<rule version="1">
</rule>
<rule version="1">
<pattern>(?U)Token :: Match \([^,]+,\s+"[^%|!\[\]]+" \)</pattern>
<message>
<id>UseTokensimpleMatch</id>
<severity>error</severity>
<summary>Token::simpleMatch should be used to match tokens without special pattern requirements.</summary>
<id>UseTokensimpleMatch</id>
<severity>error</severity>
<summary>Token::simpleMatch should be used to match tokens without special pattern requirements.</summary>
</message>
</rule>
<rule version="1">
</rule>
<rule version="1">
<pattern>\b[\w_]+ \. tokAt \( 0 \)</pattern>
<message>
<id>TokentokAt0</id>
<severity>error</severity>
<summary>tok->tokAt(0) is a slow way to say tok.</summary>
<id>TokentokAt0</id>
<severity>error</severity>
<summary>tok-&gt;tokAt(0) is a slow way to say tok.</summary>
</message>
</rule>
<rule version="1">
</rule>
<rule version="1">
<pattern>\b[\w_]+ \. strAt \( 0 \)</pattern>
<message>
<id>TokenstrAt0</id>
<severity>error</severity>
<summary>tok->strAt(0) is a slow way to say tok->str()</summary>
<id>TokenstrAt0</id>
<severity>error</severity>
<summary>tok-&gt;strAt(0) is a slow way to say tok-&gt;str()</summary>
</message>
</rule>
<rule version="1">
</rule>
<rule version="1">
<pattern><![CDATA[Token :: Match \( (\b\w+\b) , \"%var%\" \) && (\b\1\b) \. variable \( \)]]></pattern>
<message>
<id>TokenMatchVariable</id>
<severity>error</severity>
<summary>Simplify 'Token :: Match ( expr , %var% ) &amp;&amp; expr->variable()' to 'expr->variable()'</summary>
<id>TokenMatchVariable</id>
<severity>error</severity>
<summary>Simplify 'Token :: Match ( expr , %var% ) &amp;&amp; expr-&gt;variable()' to 'expr-&gt;variable()'</summary>
</message>
</rule>
</rule>
</rules>

View File

@ -503,7 +503,7 @@ int main(int argc, char **argv)
fout << "\t$(PYTHON_INTERPRETER) tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml\n";
fout << ".PHONY: validateRules\n";
fout << "validateRules:\n";
fout << "\t#xmllint --noout rules/*.xml\n";
fout << "\txmllint --noout rules/*.xml\n";
fout << "\n###### Build\n\n";