Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Parsing comment with RuleWizard

LegacyForum
LegacyForum Posts: 1,664 ✭✭
edited December 2016 in C/C++test
Hi,

One of our organizational rules state that the file name shall be included in a Doxygen style comment, like the following:

/**
* @file filename.ext
*
* file_description
*/

I have created the rule to verify everything until the name of the file, however I wasn't able to check if the added filename.ext in Doxygen comment is the actual filename wit extension. I tried to write a Python script but was unable to succeed.

Any help will be highly appreciated.

Comments

  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    Hello aarslan,

    We will need to take a look at the rule you created can you please resend your question with the .rule
    to support@parasoft.com

    Thank you,
    Techie2
  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭

    Hello aarslan,

    We will need to take a look at the rule you created can you please resend your question with the .rule
    to support@parasoft.com

    Thank you,
    Techie2

    Hi techie2,

    In the mean time, I was able to resolve my problem with a Python script.

    For those who may need such a Python, I enclose it here:

    def check( node, context ):
    defname = node.getProperty( 'name' )
    defname = defname.lower()
    filename = node.getProperty( 'filename' )
    filename = filename.replace('\\','/')
    filename = filename[ filename.rfind( '/' ) + 1:]
    filename = filename.lower()
    ndx = defname.find(filename)
    if ( ndx > -1 ):
    defname = defname[ ndx + len(filename): ]
    if (len(defname) == 0):
    return 1
    else:
    if ( not(defname[0].isalnum()) ):
    return 1
    context.report("Filename in the comment does not match the actual filename: " + filename)
    return 0

    This check procedure was added right after parsing the comment block with NextIgnoringWhiteSpace node. It strips the filename and makes it all lowercase, and searches the filename in the comment block. The rule may probably be written in a better way so that the script checks to see that the filename is written right after the @file tag in the comment, but I don't find it quite necessary so omitted that part.

    Thanks for the help.