Force parentheses in if

Is is possible to set a warning/error to check that each condition in an if statement is within its own parentheses?

i.e. require

if (a == b && c == d)
to be

if ((a == b) && (c == d))


1 comment
Comment actions Permalink
It would be a nice enhancement to the formatter style options to include a flag that enables insertion of missing parentheses in this example.Similarly, it would be nice to detect/fix cases where expressions with mixed binary operators are not parenthesized -- not all languages use the same precedence, and it would be "safer" if the code reflected the actual precedence (as well as easier to read). This would be a generalization of the example fo the "if" clause.

Please sign in to leave a comment.