Creating Custom Coding Rule for Comments

I am looking to create a custom ruleset to check whether code contains certain comments (block comments/normal comments) during static analysis.

Any assistance on this regard would be highly appreciated


  • random_anonymousrandom_anonymous Posts: 5
    edited March 7

    I can't seem to find any parameters for comments or such on "choose body", while creating a new ruleset.

  • mstaronmstaron Posts: 4

    You need to create C++Text rule in RuleWizard:
    Choose File>New>Rule from the menu bar.
    Choose C++Text from the Dictionary drop-down menu and enable the By Node option.
    Choose Comments (// or /*) and click OK.

  • mstaronmstaron Posts: 4

    The body of the comment is represented as a string and is accessible by the property 'Name'.
    Right-click the Comments node and choose Name(S) from the shortcut menu.

    Regular expressions are used to match strings.

  • random_anonymousrandom_anonymous Posts: 5

    Is there a way to check whether the last line of a file contains a certain comment?

  • mstaronmstaron Posts: 4

    If it is the last line of a file, then should be created rule like this:

    If after comment line is an empty line, then should be created rule like this:

  • Jeff EstesJeff Estes Posts: 15 admin

    Rule Wizard also has Python scripting capability for rules. If the requirements for header/footer content gets too complicated, doing it with Rule Wizard "blocks" may get too intense. Look at the RuleWizardUsersGuide for information on this Eg) "Using a Python Method to Enforce a File Naming Rule"

  • random_anonymousrandom_anonymous Posts: 5

    @mstaron I tried your first method, this doesn't seem to work. My block diagram is exactly the same as yours. I am unable to detect for a match/false match in any source code. Please advise.

  • random_anonymousrandom_anonymous Posts: 5

    Is there a way to find the number of lines in a file? I am trying to write a python method for checking whether the last line in a file contains a certain a comment.

Sign In or Register to comment.