Confirmed users, Bureaucrats and Sysops emeriti
419
edits
Line 23: | Line 23: | ||
== Indentation and Bracketing == | == Indentation and Bracketing == | ||
* Function arguments should be | * Function arguments that overflow the first line of the call expression should be aligned to underhang the first argument (to start in overflow lines in the column after the opening parenthesis). | ||
JS_SetContext(rt, // bad | JS_SetContext(rt, // bad | ||
cx); | cx); | ||
JS_SetContext(rt, // OK | JS_SetContext(rt, // OK | ||
cx); | cx); | ||
* An opening | * An opening curly brace is placed on the same line as the preceding statement. | ||
if(condition) | if (condition) // bad | ||
{ | { | ||
} | } | ||
if(condition) { | if (condition) { // OK | ||
} | } | ||
* Do not | * Do not put compound statements in one line. Indent the controlled statement on the next line, for clarity and break-pointing. | ||
if(condition) break; | if (condition) break; // bad | ||
if(condition) | if (condition) // OK | ||
break; | break; | ||
* If a statement covers multiple lines, use | * If a statement or condition covers multiple lines, use braces for all the controlled statements (even if the else part fits on one line, brace it too). | ||
if(condition) | if (condition) // bad | ||
CallThisMethod(argument1, | CallThisMethod(argument1, | ||
argument2); | argument2); | ||
if(condition) { | if (condition) { // OK | ||
CallThisMethod(argument1, | CallThisMethod(argument1, | ||
argument2); | argument2); |