mccode linter - mccode-dev/McCode GitHub Wiki
We recommend to use the cppcheck c-linter to help you spot potential problems with your component / instrument code.
If you are running a conda-forge based environment, to get it is as simple is
conda install cppcheck
Afterwards all is set up for use via mcrun/mctest
Examples of potential issues checked for are
- un-initialised variables
- indications of ‘undefined behaviour’
- missing error-handling in case of failed
malloc()orfopen()calls - potential memory leaks ... and more. All in all the tool provides a valuable shortcut to help you from “prototype physicist-code” to “validated user code” which is what we strive to ensure McStas/McXtrace is!
The McStas/McXtrace tools are preconfigured to run cppcheck, but it is not added as a dependency - so you will have to manually install it on your system. (We recommend using a conda-based enviroment where both McStas/McXtrace and cppcheck is installed.)
mcrun/mxrunprovides the-C/--c-lintswitch that will generate code for a given instrument and run the lintermctest/mxtestprovides the--lintswitch that will run the linter in a mctest run
Please do not think that you know a given warning from cpplint is “not relevant”! Your code will not be merged to the McStas/McXtrace repo until all warnings and remarks are resolved!