Maintain consistent formatting and structural choices throughout the codebase to improve readability and maintainability. This includes always using braces for control structures (even single-line statements), choosing appropriate control flow constructs for clarity, and organizing code to prevent execution order issues.
Key practices:
Example of consistent brace usage:
// Good - always use braces
if (!node.lastLayout) {
node.lastLayout = {};
}
// Avoid - inconsistent formatting
if (!node.lastLayout) node.lastLayout = {};
Example of clearer control structure:
// Preferred for simple cases
if (typeof val === 'number') {
obj[key] = roundNumber(val);
} else if (typeof val === 'object') {
inplaceRoundNumbersInObject(val);
}
// Instead of switch for simple type checking
These consistent choices make code more predictable for team members and reduce cognitive load during code reviews.
Enter the URL of a public GitHub repository