From 49ad998175b5577478becb42cb3707df81a9f98f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 9 May 2025 08:35:36 +0200 Subject: [PATCH 1/2] 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. --- man/manual-premium.md | 54 ++++++++++++++++++++++++++++------------- man/manual.md | 56 +++++++++++++++++++++++++++++++------------ 2 files changed, 78 insertions(+), 32 deletions(-) diff --git a/man/manual-premium.md b/man/manual-premium.md index 585b61cfcff..b8693580bb8 100644 --- a/man/manual-premium.md +++ b/man/manual-premium.md @@ -981,47 +981,67 @@ Cppcheck is distributed with a few addons which are listed below. ## Supported addons -### misra.py +### namingng.py + +[namingng.py](https://github.com/danmar/cppcheck/blob/main/addons/namingng.py) allows you to configure and check naming conventions. + +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. + +Example configuration: +``` +{ + "RE_VARNAME": ["[a-z]*[a-zA-Z0-9_]*\\Z"], + "RE_PRIVATE_MEMBER_VARIABLE": null, + "RE_FUNCTIONNAME": ["[a-z0-9A-Z]*\\Z"], + "_comment": "comments can be added to the config with underscore-prefixed keys", + "include_guard": { + "input": "path", + "prefix": "GUARD_", + "case": "upper", + "max_linenr": 5, + "RE_HEADERFILE": "[^/].*\\.h\\Z", + "required": true + }, + "var_prefixes": {"uint32_t": "ui32"}, + "function_prefixes": {"uint16_t": "ui16", + "uint32_t": "ui32"} +} +``` -[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. +### threadsafety.py -The full list of supported rules is available on: [https://files.cppchecksolutions.com/misrac2023.html](https://files.cppchecksolutions.com/misrac2023.html) +[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. ### y2038.py [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). -### threadsafety.py - -[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. - ## Running Addons Addons could be run through Cppcheck command line utility as follows: - cppcheck --addon=misra.py somefile.c + cppcheck --addon=namingng.py somefile.c This will launch all Cppcheck checks and additionally calls specific checks provided by selected addon. -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: +Some addons need extra arguments. You can configure how you want to execute an addon in a json file. For example put this in `naming.json`: { - "script": "misra.py", + "script": "namingng.py", "args": [ - "--rule-texts=misra.txt" + "--configfile=path/to/naming-conventions.config" ] } -And then the configuration can be executed on the Cppcheck command line: +And then on the Cppcheck command line use `--addon=naming.json`: - cppcheck --addon=misra.json somefile.c + cppcheck --addon=naming.json somefile.c -By default Cppcheck would search addon at the standard path which was specified -during the installation process. You also can set this path directly, for example: +The namingng.py addon is now executed with the `--configfile=path/to/naming-conventions.config` option. - cppcheck --addon=/opt/cppcheck/configurations/my_misra.json somefile.c +Cppcheck search for addons in the local folder first and then in the installation data folder. You can also provide the path explicitly, for instance: -This allows you to create and manage multiple configuration files for different projects. + cppcheck --addon=path/to/my-addon.py somefile.c # Library configuration diff --git a/man/manual.md b/man/manual.md index 71a6fceb2e0..3c29f13388d 100644 --- a/man/manual.md +++ b/man/manual.md @@ -990,43 +990,69 @@ The misra rule texts should be downloaded from [MISRA](https://gitlab.com/MISRA/ 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). -Checkers in open source Cppcheck only cover MISRA rules partially. - -### y2038.py - -[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). +Checkers in open source Cppcheck only cover MISRA rules partially and for full coverage use Cppcheck Premium. + +### namingng.py + +[namingng.py](https://github.com/danmar/cppcheck/blob/main/addons/namingng.py) allows you to configure and check naming conventions. + +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. + +Example configuration: +``` +{ + "RE_VARNAME": ["[a-z]*[a-zA-Z0-9_]*\\Z"], + "RE_PRIVATE_MEMBER_VARIABLE": null, + "RE_FUNCTIONNAME": ["[a-z0-9A-Z]*\\Z"], + "_comment": "comments can be added to the config with underscore-prefixed keys", + "include_guard": { + "input": "path", + "prefix": "GUARD_", + "case": "upper", + "max_linenr": 5, + "RE_HEADERFILE": "[^/].*\\.h\\Z", + "required": true + }, + "var_prefixes": {"uint32_t": "ui32"}, + "function_prefixes": {"uint16_t": "ui16", + "uint32_t": "ui32"} +} +``` ### threadsafety.py [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. +### y2038.py + +[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). + ## Running Addons Addons could be run through Cppcheck command line utility as follows: - cppcheck --addon=misra.py somefile.c + cppcheck --addon=namingng.py somefile.c This will launch all Cppcheck checks and additionally calls specific checks provided by selected addon. -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: +Some addons need extra arguments. You can configure how you want to execute an addon in a json file. For example put this in `naming.json`: { - "script": "misra.py", + "script": "namingng.py", "args": [ - "--rule-texts=misra.txt" + "--configfile=path/to/naming-conventions.config" ] } -And then the configuration can be executed on the Cppcheck command line: +And then on the Cppcheck command line use `--addon=naming.json`: - cppcheck --addon=misra.json somefile.c + cppcheck --addon=naming.json somefile.c -By default Cppcheck would search addon at the standard path which was specified -during the installation process. You also can set this path directly, for example: +The namingng.py addon is now executed with the `--configfile=path/to/naming-conventions.config` option. - cppcheck --addon=/opt/cppcheck/configurations/my_misra.json somefile.c +Cppcheck search for addons in the local folder first and then in the installation data folder. You can also provide the path explicitly, for instance: -This allows you to create and manage multiple configuration files for different projects. + cppcheck --addon=path/to/my-addon.py somefile.c # Library configuration From bed05de6f7daf5f7e9050d1da3094c8e3f8097a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Fri, 9 May 2025 10:52:24 +0200 Subject: [PATCH 2/2] fix --- man/manual-premium.md | 25 +++++++++++++------------ man/manual.md | 43 ++++++++++++++++++++++++++++--------------- 2 files changed, 41 insertions(+), 27 deletions(-) diff --git a/man/manual-premium.md b/man/manual-premium.md index b8693580bb8..dce551b3568 100644 --- a/man/manual-premium.md +++ b/man/manual-premium.md @@ -987,7 +987,7 @@ Cppcheck is distributed with a few addons which are listed below. 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. -Example configuration: +Example configuration of naming conventions: ``` { "RE_VARNAME": ["[a-z]*[a-zA-Z0-9_]*\\Z"], @@ -1018,28 +1018,29 @@ Example configuration: ## Running Addons -Addons could be run through Cppcheck command line utility as follows: +Addons can be executed with the `--addon` option: cppcheck --addon=namingng.py somefile.c -This will launch all Cppcheck checks and additionally calls specific checks provided by selected addon. +Likewise, if you have created your own script you can execute that: -Some addons need extra arguments. You can configure how you want to execute an addon in a json file. For example put this in `naming.json`: + cppcheck --addon=mychecks.py somefile.c + +You can configure how you want to execute an addon in a json file. For example: { - "script": "namingng.py", + "script": "mychecks.py", "args": [ - "--configfile=path/to/naming-conventions.config" - ] + "--some-option" + ], + "ctu": false } -And then on the Cppcheck command line use `--addon=naming.json`: - - cppcheck --addon=naming.json somefile.c +To use that json file to execute your addon use the --addon option: -The namingng.py addon is now executed with the `--configfile=path/to/naming-conventions.config` option. + cppcheck --addon=mychecks.json somefile.c -Cppcheck search for addons in the local folder first and then in the installation data folder. You can also provide the path explicitly, for instance: +Cppcheck search for addons in the local folder first and then in the installation folder. A different path can be specified explicitly, for instance: cppcheck --addon=path/to/my-addon.py somefile.c diff --git a/man/manual.md b/man/manual.md index 3c29f13388d..cdc692552d0 100644 --- a/man/manual.md +++ b/man/manual.md @@ -986,11 +986,23 @@ Cppcheck is distributed with a few addons which are listed below. [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. -The misra rule texts should be downloaded from [MISRA](https://gitlab.com/MISRA/MISRA-C/MISRA-C-2012/tools) +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) -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). +To load the rule texts, create a configuration file. Example `misra.json`: -Checkers in open source Cppcheck only cover MISRA rules partially and for full coverage use Cppcheck Premium. + { + "script": "misra.py", + "args": [ + "--rule-texts=misra_c_2012__headlines_for_cppcheck - AMD1+AMD2.txt" + ], + "ctu": true + } + +To use that `misra.json` in Cppcheck analysis, use option `--addon=misra.json`: + + cppcheck --addon=misra.json --enable=style somefile.c + +Misra checkers in open source Cppcheck only cover MISRA rules partially and for full coverage use Cppcheck Premium. ### namingng.py @@ -998,7 +1010,7 @@ Checkers in open source Cppcheck only cover MISRA rules partially and for full c 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. -Example configuration: +Example configuration of naming conventions: ``` { "RE_VARNAME": ["[a-z]*[a-zA-Z0-9_]*\\Z"], @@ -1029,28 +1041,29 @@ Example configuration: ## Running Addons -Addons could be run through Cppcheck command line utility as follows: +Addons can be executed with the `--addon` option: cppcheck --addon=namingng.py somefile.c -This will launch all Cppcheck checks and additionally calls specific checks provided by selected addon. +Likewise, if you have created your own script you can execute that: -Some addons need extra arguments. You can configure how you want to execute an addon in a json file. For example put this in `naming.json`: + cppcheck --addon=mychecks.py somefile.c + +You can configure how you want to execute an addon in a json file. For example: { - "script": "namingng.py", + "script": "mychecks.py", "args": [ - "--configfile=path/to/naming-conventions.config" - ] + "--some-option" + ], + "ctu": false } -And then on the Cppcheck command line use `--addon=naming.json`: - - cppcheck --addon=naming.json somefile.c +To use that json file to execute your addon use the --addon option: -The namingng.py addon is now executed with the `--configfile=path/to/naming-conventions.config` option. + cppcheck --addon=mychecks.json somefile.c -Cppcheck search for addons in the local folder first and then in the installation data folder. You can also provide the path explicitly, for instance: +Cppcheck search for addons in the local folder first and then in the installation folder. A different path can be specified explicitly, for instance: cppcheck --addon=path/to/my-addon.py somefile.c