("One True Brace Style", OBTS, 1TBS)
That is, for the keywords 'if', 'else', 'while', 'do', and 'for', if
there's only one statement, insert the braces.
Suggested option name: --braces-single-statement-conditionals, -bssc, or
maybe -otbs
(for the truly maniacal, -nbssc would remove such braces... but I'm not
asking for the removal, but the insertion)
This style makes the code less error-prone by always having an explicit
block, which makes it easier to insert/delete lines at will from the
block. For example these
if (foo) bar();
if (zzz) a=b; else c=d;
while (xyz) p++;
do re() while (mi);
for (...) j--;
would become these (assuming K&R with -i2 otherwise):
if (foo) {
bar();
}
if (zzz) {
a = b;
} else {
c = d;
}
while (xyz) {
p++;
}
do {
re();
} while (mi);
for (...) {
j--;
}
One tricky part I see is handling of trailing comments:
if (foo) /* blah */
/* blefuscu */
bar(); /* bleh */
should probably become
if (foo) { /* blah */
/* blefuscu */
bar(); /* bleh */
}
and an evil thing like
if (foo) /* evil */ bar();
should *probably* become
if (foo) { /* evil */
bar();
}
That is, the braces are inserted immediately after the conditional and
the single-statements, possibly before a trailing comment (they are
*not* to be inserted as the last thing in the line...)
_______________________________________________
bug-indent mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-indent