Skip to content

Commit d655a3a

Browse files
authored
manual: add description about namingng. if misra is needed then cppcheck premium is recommended. do not describe misra.py in premium manual because that shouldn't be used. (#7518)
1 parent 7761784 commit d655a3a

File tree

2 files changed

+100
-40
lines changed

2 files changed

+100
-40
lines changed

man/manual-premium.md

Lines changed: 42 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -981,47 +981,68 @@ Cppcheck is distributed with a few addons which are listed below.
981981

982982
## Supported addons
983983

984-
### misra.py
984+
### namingng.py
985+
986+
[namingng.py](https://github.com/danmar/cppcheck/blob/main/addons/namingng.py) allows you to configure and check naming conventions.
987+
988+
You need to have a configuration file that defines your naming conventions. By default the filename `namingng.config.json` is used but there is an option so you can use any filename you want.
989+
990+
Example configuration of naming conventions:
991+
```
992+
{
993+
"RE_VARNAME": ["[a-z]*[a-zA-Z0-9_]*\\Z"],
994+
"RE_PRIVATE_MEMBER_VARIABLE": null,
995+
"RE_FUNCTIONNAME": ["[a-z0-9A-Z]*\\Z"],
996+
"_comment": "comments can be added to the config with underscore-prefixed keys",
997+
"include_guard": {
998+
"input": "path",
999+
"prefix": "GUARD_",
1000+
"case": "upper",
1001+
"max_linenr": 5,
1002+
"RE_HEADERFILE": "[^/].*\\.h\\Z",
1003+
"required": true
1004+
},
1005+
"var_prefixes": {"uint32_t": "ui32"},
1006+
"function_prefixes": {"uint16_t": "ui16",
1007+
"uint32_t": "ui32"}
1008+
}
1009+
```
9851010

986-
[misra.py](https://github.com/danmar/cppcheck/blob/main/addons/misra.py) is used to verify compliance with MISRA C 2012, a proprietary set of guidelines to avoid questionable code, developed for embedded systems.
1011+
### threadsafety.py
9871012

988-
The full list of supported rules is available on: [https://files.cppchecksolutions.com/misrac2023.html](https://files.cppchecksolutions.com/misrac2023.html)
1013+
[threadsafety.py](https://github.com/danmar/cppcheck/blob/main/addons/threadsafety.py) analyses Cppcheck dump files to locate thread safety issues like static local objects used by multiple threads.
9891014

9901015
### y2038.py
9911016

9921017
[y2038.py](https://github.com/danmar/cppcheck/blob/main/addons/y2038.py) checks Linux systems for [year 2038 problem](https://en.wikipedia.org/wiki/Year_2038_problem) safety. This required [modified environment](https://github.com/3adev/y2038). See complete description [here](https://github.com/danmar/cppcheck/blob/main/addons/doc/y2038.txt).
9931018

994-
### threadsafety.py
995-
996-
[threadsafety.py](https://github.com/danmar/cppcheck/blob/main/addons/threadsafety.py) analyses Cppcheck dump files to locate thread safety issues like static local objects used by multiple threads.
997-
9981019
## Running Addons
9991020

1000-
Addons could be run through Cppcheck command line utility as follows:
1021+
Addons can be executed with the `--addon` option:
10011022

1002-
cppcheck --addon=misra.py somefile.c
1023+
cppcheck --addon=namingng.py somefile.c
10031024

1004-
This will launch all Cppcheck checks and additionally calls specific checks provided by selected addon.
1025+
Likewise, if you have created your own script you can execute that:
10051026

1006-
Some addons need extra arguments. You can configure how you want to execute an addon in a json file. For example put this in misra.json:
1027+
cppcheck --addon=mychecks.py somefile.c
1028+
1029+
You can configure how you want to execute an addon in a json file. For example:
10071030

10081031
{
1009-
"script": "misra.py",
1032+
"script": "mychecks.py",
10101033
"args": [
1011-
"--rule-texts=misra.txt"
1012-
]
1034+
"--some-option"
1035+
],
1036+
"ctu": false
10131037
}
10141038

1015-
And then the configuration can be executed on the Cppcheck command line:
1016-
1017-
cppcheck --addon=misra.json somefile.c
1039+
To use that json file to execute your addon use the --addon option:
10181040

1019-
By default Cppcheck would search addon at the standard path which was specified
1020-
during the installation process. You also can set this path directly, for example:
1041+
cppcheck --addon=mychecks.json somefile.c
10211042

1022-
cppcheck --addon=/opt/cppcheck/configurations/my_misra.json somefile.c
1043+
Cppcheck search for addons in the local folder first and then in the installation folder. A different path can be specified explicitly, for instance:
10231044

1024-
This allows you to create and manage multiple configuration files for different projects.
1045+
cppcheck --addon=path/to/my-addon.py somefile.c
10251046

10261047
# Library configuration
10271048

man/manual.md

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -986,47 +986,86 @@ Cppcheck is distributed with a few addons which are listed below.
986986

987987
[misra.py](https://github.com/danmar/cppcheck/blob/main/addons/misra.py) is used to verify compliance with MISRA C 2012, a proprietary set of guidelines to avoid questionable code, developed for embedded systems.
988988

989-
The misra rule texts should be downloaded from [MISRA](https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/tools)
989+
The misra.py script does not provide rule texts, those should be downloaded from [MISRA](https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/tools)
990990

991-
Use the option `--rule-texts` to specify the rules text file that has been downloaded from [MISRA](https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/tools).
991+
To load the rule texts, create a configuration file. Example `misra.json`:
992992

993-
Checkers in open source Cppcheck only cover MISRA rules partially.
993+
{
994+
"script": "misra.py",
995+
"args": [
996+
"--rule-texts=misra_c_2012__headlines_for_cppcheck - AMD1+AMD2.txt"
997+
],
998+
"ctu": true
999+
}
9941000

995-
### y2038.py
1001+
To use that `misra.json` in Cppcheck analysis, use option `--addon=misra.json`:
9961002

997-
[y2038.py](https://github.com/danmar/cppcheck/blob/main/addons/y2038.py) checks Linux systems for [year 2038 problem](https://en.wikipedia.org/wiki/Year_2038_problem) safety. This required [modified environment](https://github.com/3adev/y2038). See complete description [here](https://github.com/danmar/cppcheck/blob/main/addons/doc/y2038.txt).
1003+
cppcheck --addon=misra.json --enable=style somefile.c
1004+
1005+
Misra checkers in open source Cppcheck only cover MISRA rules partially and for full coverage use Cppcheck Premium.
1006+
1007+
### namingng.py
1008+
1009+
[namingng.py](https://github.com/danmar/cppcheck/blob/main/addons/namingng.py) allows you to configure and check naming conventions.
1010+
1011+
You need to have a configuration file that defines your naming conventions. By default the filename `namingng.config.json` is used but there is an option so you can use any filename you want.
1012+
1013+
Example configuration of naming conventions:
1014+
```
1015+
{
1016+
"RE_VARNAME": ["[a-z]*[a-zA-Z0-9_]*\\Z"],
1017+
"RE_PRIVATE_MEMBER_VARIABLE": null,
1018+
"RE_FUNCTIONNAME": ["[a-z0-9A-Z]*\\Z"],
1019+
"_comment": "comments can be added to the config with underscore-prefixed keys",
1020+
"include_guard": {
1021+
"input": "path",
1022+
"prefix": "GUARD_",
1023+
"case": "upper",
1024+
"max_linenr": 5,
1025+
"RE_HEADERFILE": "[^/].*\\.h\\Z",
1026+
"required": true
1027+
},
1028+
"var_prefixes": {"uint32_t": "ui32"},
1029+
"function_prefixes": {"uint16_t": "ui16",
1030+
"uint32_t": "ui32"}
1031+
}
1032+
```
9981033

9991034
### threadsafety.py
10001035

10011036
[threadsafety.py](https://github.com/danmar/cppcheck/blob/main/addons/threadsafety.py) analyses Cppcheck dump files to locate thread safety issues like static local objects used by multiple threads.
10021037

1038+
### y2038.py
1039+
1040+
[y2038.py](https://github.com/danmar/cppcheck/blob/main/addons/y2038.py) checks Linux systems for [year 2038 problem](https://en.wikipedia.org/wiki/Year_2038_problem) safety. This required [modified environment](https://github.com/3adev/y2038). See complete description [here](https://github.com/danmar/cppcheck/blob/main/addons/doc/y2038.txt).
1041+
10031042
## Running Addons
10041043

1005-
Addons could be run through Cppcheck command line utility as follows:
1044+
Addons can be executed with the `--addon` option:
1045+
1046+
cppcheck --addon=namingng.py somefile.c
10061047

1007-
cppcheck --addon=misra.py somefile.c
1048+
Likewise, if you have created your own script you can execute that:
10081049

1009-
This will launch all Cppcheck checks and additionally calls specific checks provided by selected addon.
1050+
cppcheck --addon=mychecks.py somefile.c
10101051

1011-
Some addons need extra arguments. You can configure how you want to execute an addon in a json file. For example put this in misra.json:
1052+
You can configure how you want to execute an addon in a json file. For example:
10121053

10131054
{
1014-
"script": "misra.py",
1055+
"script": "mychecks.py",
10151056
"args": [
1016-
"--rule-texts=misra.txt"
1017-
]
1057+
"--some-option"
1058+
],
1059+
"ctu": false
10181060
}
10191061

1020-
And then the configuration can be executed on the Cppcheck command line:
1021-
1022-
cppcheck --addon=misra.json somefile.c
1062+
To use that json file to execute your addon use the --addon option:
10231063

1024-
By default Cppcheck would search addon at the standard path which was specified
1025-
during the installation process. You also can set this path directly, for example:
1064+
cppcheck --addon=mychecks.json somefile.c
10261065

1027-
cppcheck --addon=/opt/cppcheck/configurations/my_misra.json somefile.c
1066+
Cppcheck search for addons in the local folder first and then in the installation folder. A different path can be specified explicitly, for instance:
10281067

1029-
This allows you to create and manage multiple configuration files for different projects.
1068+
cppcheck --addon=path/to/my-addon.py somefile.c
10301069

10311070
# Library configuration
10321071

0 commit comments

Comments
 (0)