0

I'm having trouble getting cppcheck to recognize and apply my custom XML rules file. I've followed the documentation and advice, but still, cppcheck doesn't seem to trigger any warnings based on my rules. I'm wondering if anyone else has encountered similar issues or has any insights into why cppcheck might not be accepting my XML rules file. Could there be any specific configurations or troubleshooting steps I should consider?

my command in my command line is:

cppcheck --rule-file=C:\job\testcppcheck\xmltest.xml file.cpp

with xml:

<?xml version="1.0" ?>
<codingRules>
  <rule>
    <pattern>variable</pattern>
    <message>
      <severity>error</severity>
      <summary>This variable . . .</summary>
    </message>
  </rule>
</codingRules>
Jarod42
  • 203,559
  • 14
  • 181
  • 302
migela
  • 1
  • 1

1 Answers1

0

According to cppcheck writing-rules-1.docbook and cppcheck rule example files your rule grouping by <codingRules> element won't work.

Either don't use a grouping element

<?xml version="1.0" ?>
<rule>
    <pattern>variable</pattern>
    <message>
        <severity>error</severity>
        <summary>This variable . . .</summary>
    </message>
</rule>

or use <rules> element for grouping

<?xml version="1.0" ?>
<rules>
    <rule>
        <pattern>variable</pattern>
        <message>
            <severity>error</severity>
            <summary>This variable . . .</summary>
        </message>
    </rule>
</rules>

With the rule files above I get the expected cppcheck output Processing rule: variable test.cpp:3:0: error: This variable . . . [rule] for a simple test source file which contains matching pattern variable. With the rules file of question there is no additional cppcheck output.

I use official cppcheck release v2.11 (Windows x64). If you create your own cppcheck build make sure HAVE_RULES option is enabled.

Mathias Schmid
  • 431
  • 4
  • 7