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:
parent
1d5166d70c
commit
10c7c70970
2
Makefile
2
Makefile
|
@ -389,7 +389,7 @@ checkCWEEntries: /tmp/errorlist.xml
|
||||||
$(PYTHON_INTERPRETER) tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml
|
$(PYTHON_INTERPRETER) tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml
|
||||||
.PHONY: validateRules
|
.PHONY: validateRules
|
||||||
validateRules:
|
validateRules:
|
||||||
#xmllint --noout rules/*.xml
|
xmllint --noout rules/*.xml
|
||||||
|
|
||||||
###### Build
|
###### Build
|
||||||
|
|
||||||
|
|
|
@ -713,6 +713,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
|
||||||
tinyxml2::XMLDocument doc;
|
tinyxml2::XMLDocument doc;
|
||||||
if (doc.LoadFile(12+argv[i]) == tinyxml2::XML_SUCCESS) {
|
if (doc.LoadFile(12+argv[i]) == tinyxml2::XML_SUCCESS) {
|
||||||
tinyxml2::XMLElement *node = doc.FirstChildElement();
|
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()) {
|
for (; node && strcmp(node->Value(), "rule") == 0; node = node->NextSiblingElement()) {
|
||||||
Settings::Rule rule;
|
Settings::Rule rule;
|
||||||
|
|
||||||
|
|
|
@ -1,41 +1,43 @@
|
||||||
<?xml version="1.0"?>
|
<?xml version="1.0"?>
|
||||||
<rule version="1">
|
<rules>
|
||||||
|
<rule version="1">
|
||||||
<pattern>Token :: (?:findm|(?:simple|)M)atch \([^,]+,\s+"(?:\s+|[^"]+?\s+")</pattern>
|
<pattern>Token :: (?:findm|(?:simple|)M)atch \([^,]+,\s+"(?:\s+|[^"]+?\s+")</pattern>
|
||||||
<message>
|
<message>
|
||||||
<id>TokenMatchSpacing</id>
|
<id>TokenMatchSpacing</id>
|
||||||
<severity>style</severity>
|
<severity>style</severity>
|
||||||
<summary>Useless extra spacing for Token::*Match.</summary>
|
<summary>Useless extra spacing for Token::*Match.</summary>
|
||||||
</message>
|
</message>
|
||||||
</rule>
|
</rule>
|
||||||
<rule version="1">
|
<rule version="1">
|
||||||
<pattern>(?U)Token :: Match \([^,]+,\s+"[^%|!\[\]]+" \)</pattern>
|
<pattern>(?U)Token :: Match \([^,]+,\s+"[^%|!\[\]]+" \)</pattern>
|
||||||
<message>
|
<message>
|
||||||
<id>UseTokensimpleMatch</id>
|
<id>UseTokensimpleMatch</id>
|
||||||
<severity>error</severity>
|
<severity>error</severity>
|
||||||
<summary>Token::simpleMatch should be used to match tokens without special pattern requirements.</summary>
|
<summary>Token::simpleMatch should be used to match tokens without special pattern requirements.</summary>
|
||||||
</message>
|
</message>
|
||||||
</rule>
|
</rule>
|
||||||
<rule version="1">
|
<rule version="1">
|
||||||
<pattern>\b[\w_]+ \. tokAt \( 0 \)</pattern>
|
<pattern>\b[\w_]+ \. tokAt \( 0 \)</pattern>
|
||||||
<message>
|
<message>
|
||||||
<id>TokentokAt0</id>
|
<id>TokentokAt0</id>
|
||||||
<severity>error</severity>
|
<severity>error</severity>
|
||||||
<summary>tok->tokAt(0) is a slow way to say tok.</summary>
|
<summary>tok->tokAt(0) is a slow way to say tok.</summary>
|
||||||
</message>
|
</message>
|
||||||
</rule>
|
</rule>
|
||||||
<rule version="1">
|
<rule version="1">
|
||||||
<pattern>\b[\w_]+ \. strAt \( 0 \)</pattern>
|
<pattern>\b[\w_]+ \. strAt \( 0 \)</pattern>
|
||||||
<message>
|
<message>
|
||||||
<id>TokenstrAt0</id>
|
<id>TokenstrAt0</id>
|
||||||
<severity>error</severity>
|
<severity>error</severity>
|
||||||
<summary>tok->strAt(0) is a slow way to say tok->str()</summary>
|
<summary>tok->strAt(0) is a slow way to say tok->str()</summary>
|
||||||
</message>
|
</message>
|
||||||
</rule>
|
</rule>
|
||||||
<rule version="1">
|
<rule version="1">
|
||||||
<pattern><![CDATA[Token :: Match \( (\b\w+\b) , \"%var%\" \) && (\b\1\b) \. variable \( \)]]></pattern>
|
<pattern><![CDATA[Token :: Match \( (\b\w+\b) , \"%var%\" \) && (\b\1\b) \. variable \( \)]]></pattern>
|
||||||
<message>
|
<message>
|
||||||
<id>TokenMatchVariable</id>
|
<id>TokenMatchVariable</id>
|
||||||
<severity>error</severity>
|
<severity>error</severity>
|
||||||
<summary>Simplify 'Token :: Match ( expr , %var% ) && expr->variable()' to 'expr->variable()'</summary>
|
<summary>Simplify 'Token :: Match ( expr , %var% ) && expr->variable()' to 'expr->variable()'</summary>
|
||||||
</message>
|
</message>
|
||||||
</rule>
|
</rule>
|
||||||
|
</rules>
|
||||||
|
|
|
@ -503,7 +503,7 @@ int main(int argc, char **argv)
|
||||||
fout << "\t$(PYTHON_INTERPRETER) tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml\n";
|
fout << "\t$(PYTHON_INTERPRETER) tools/listErrorsWithoutCWE.py -F /tmp/errorlist.xml\n";
|
||||||
fout << ".PHONY: validateRules\n";
|
fout << ".PHONY: validateRules\n";
|
||||||
fout << "validateRules:\n";
|
fout << "validateRules:\n";
|
||||||
fout << "\t#xmllint --noout rules/*.xml\n";
|
fout << "\txmllint --noout rules/*.xml\n";
|
||||||
|
|
||||||
fout << "\n###### Build\n\n";
|
fout << "\n###### Build\n\n";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue