Menu

Checking for correct comments with CppCheck

2018-08-17
2018-08-31
  • Nick Ridgway

    Nick Ridgway - 2018-08-17

    Hello,

    I have been investigating adding some rules and checks to CppCheck to check some rules relating to having correctly formatted comments in the right places in code. I tried to make it so that comments were not removed by simplecpp and the CppCheck preprocessor so I could add a new class of rules/checks, but found that I had to make more changes that I expected fairly deep in the codebase. Would you be interested in a pull request to enable this functionality?

    The checks I am interested in adding are for rules like all 'magic numbers' must be followed by a comment that explains what the number is.

     
  • Daniel Marjamäki

    I guess you have seen that the comments are saved in the dump files? In the "raw" token list.

    Would you be interested in a pull request to enable this functionality?

    Feel free to publish your changes. However I can't guarantee I will merge it if there is no "use".

    The checks I am interested in adding are for rules like all 'magic numbers' must be followed by a comment that explains what the number is.

    That sounds like a good idea. However it might belong better in a addon than in core Cppcheck. But it depends on what the noise ratio and acceptance ratio for this rule would be. It's common practice that magic numbers are avoided. Do you know if some official coding lines say that comments should be used (that is not required but would help)?

     
  • Nick Ridgway

    Nick Ridgway - 2018-08-29

    The changes include some small changes to simplecpp. Should I include them in the pull request or make a separate one in that repo?

     
  • Daniel Marjamäki

    Good question. I guess that it would be easier to keep this together if there is a single PR in the cppcheck repo. So feel free to create a single PR.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.