Reputation: 9072
I have a project where we're investigating adding a requirement for if conditionals to include braces (the reason is unimportant and off topic). For example:
if (foo)
return bar;
else
return baz;
Becomes:
if (foo) {
return bar;
} else {
return baz;
}
We already use GNU indent to do all sorts of code style checking so ideally we'd be able to force this requirement using GNU indent as we already do with our other style requirements. We can put all that in a Git pre-commit hook and no one has to worry about messing things up.
I can't seem to find a way to force these new braces to actually show up though. It looks like GNU indent will only check that they're in the right spot if they're already there. Is there some way to require these braces to actually be present too?
Upvotes: 4
Views: 278
Reputation: 15586
No. There's a reason it's called indent
. It only indents code.
I think clang-format
might have this capability but I'd have to review the configuration to make sure.
My personal preference would be to just add them manually and turn on compiler warnings if not having them is causing issues with your code.
Upvotes: 1