Addons: Describe running addons from cppcheck in the manual

This commit is contained in:
Daniel Marjamäki 2019-04-08 21:31:38 +02:00
parent 44dcbda88e
commit 1f68e038be
2 changed files with 103 additions and 15 deletions

View File

@ -81,7 +81,7 @@ namespace {
for (const picojson::value &v : obj["args"].get<picojson::array>()) for (const picojson::value &v : obj["args"].get<picojson::array>())
args += " " + v.get<std::string>(); args += " " + v.get<std::string>();
} }
script = obj["addon"].get<std::string>(); script = obj["script"].get<std::string>();
return ""; return "";
} }
}; };

View File

@ -667,31 +667,68 @@ The speedup you get can be remarkable.
TBD TBD
## MISRA ## Addons
Cppcheck has an addon that checks for MISRA C 2012 compliance. Addons are scripts with extra checks. Cppcheck is distributed with a few addons. You can easily write your own custom addon.
### Requirements If an addon does not need any arguments, you can run it directly on the cppcheck command line. For instance you can run the addon "misc" like this:
You need: cppcheck --addon=misc somefile.c
Python 2.X or 3.X If an addon need additional arguments, you can not execute it directly on the command line. Create a json file with the addon configuration:
The MISRA C 2012 PDF. You can buy this from <http://www.misra.org.uk> (costs 15-20 pounds) {
"script": "misra",
"args": [ "--rule-texts=misra.txt" ]
}
#### MISRA Text file And then such configuration can be executed on the cppcheck command line:
It is not allowed to publish the MISRA rule texts. Therefore the MISRA rule texts are not available directly in the addon. We can not publish the rule texts. Instead, you must provide the rule texts; the addon can read the rule texts from a text file. If you copy/paste all text in "Appendix A Summary of guidelines" from the MISRA pdf, then you have all the rule texts. cppcheck --addon=misra.json somefile.c
If you have installed xpdf, such text file can be generated on the command line (using pdftotext that is included in xpdf): ### CERT
pdftotext misra-c-2012.pdf output.txt Check CERT coding rules. No configuration is needed.
The output might not be 100% perfect so you might need to make minor tweaks manually. Example usage:
Other pdf-to-text utilities might work also. cppcheck --addon=cert somefile.c
To create the text file manually, copy paste Appendix A "Summary of guidelines" from the MISRA PDF. Format: ### Findcasts
Will just locate C-style casts in the code. No configuration is needed.
Example usage:
cppcheck --addon=findcasts somefile.c
### Misc
Misc checks. No configuration is needed.
These are checks that we thought would be useful, however it could sometimes warn for coding style that is by intention. For instance it warns about missing comma
between string literals in array initializer.. that could be a mistake but maybe you use string concatenation by intention.
Example usage:
cppcheck --addon=misc somefile.c
### Misra
Check that your code is Misra C 2012 compliant.
To run the Misra addon you need to write a configuration file, because the addon require parameters.
To run this addon you need to have a text file with the misra rule texts. You copy/paste these rule texts from the Misra C 2012 PDF, buy this PDF from <http://www.misra.org.uk> (costs 15-20 pounds)
This is an example misra configuration file:
{
"script": "misra",
"args": [ "--rule-texts=misra.txt" ]
}
The file misra.txt contains the text from "Appendix A Summary of guidelines" in the Misra C 2012 PDF.
Appendix A Summary of guidelines Appendix A Summary of guidelines
Rule 1.1 Rule 1.1
@ -700,7 +737,58 @@ To create the text file manually, copy paste Appendix A "Summary of guidelines"
Rule text Rule text
... ...
Rules that you want to disable does not need to have a rule text. Rules that don't have rule text will be suppressed by the addon. Usage:
cppcheck --addon=my-misra-config.json somefile.c
### Naming
Check naming conventions. You specify your naming conventions for variables/functions/etc using regular expressions.
Example configuration (variable names must start with lower case, function names must start with upper case):
{
"script": "naming",
"args": [
"--var=[a-z].*",
"--function=[A-Z].*"
]
}
Usage:
cppcheck --addon=my-naming.json somefile.c
### Namingng
Check naming conventions. You specify the naming conventions using regular expressions in a json file.
Example addon configuration:
{
"script": "namingng",
args: [ "--configfile=ROS_naming.json" ]
}
Usage:
cppcheck --addon=namingng-ros.json somefile.c
### Threadsafety
This will warn if you have local static objects that are not threadsafe. No configuration is needed.
Example usage:
cppcheck --addon=threadsafety somefile.c
### Y2038
Check for the Y2038 bug. No configuration is needed.
Example usage:
cppcheck --addon=y2038 somefile.c
## Library configuration ## Library configuration