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
I can't seem to find any parameters for comments or such on "choose body", while creating a new ruleset.
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.
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.
Is there a way to check whether the last line of a file contains a certain comment?
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:
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"
@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.
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.
Maybe you should try to use the second rule (e.g. you have end line character after last comment). Without testing it is hard to advise something else.
You can find the number of the last line in a file with the following rule:
If you prefer python, then you can take the content of a file in a python method: