I have a python script that checks code for coding convention errors. It does this by matching a regex that represents a violation of the coding standard.
One of our standards is that ‘if’, ‘while’ and ‘do-while’ conditionals must contain a conditional operator.
So no
if (var1)
{
// blah
}
Instead I need
if (var1 == TRUE)
{
// blah
}
For example, what I need for if statements is to match “if” at the beginning of the line, and find the situation when it doesn’t contain “==”, “<=”, “>=”, “||” or “&&” anywhere after it. I’ve been pounding my head against the wall for a few hours and I’m hoping someone here can alleviate some of the pain!
Here is what I ended up doing, it works fairly well for the most part, not ideal though and we are looking into a third party parser.