Skip to content

Code Formatting

Specification > Engineering

This chapter defines the surface formatting rules every source file must follow so that code reads uniformly across the codebase. It is conditional and applies to the JavaScript sources covered by the stack chapter.


RuleRequirement
IndentationYou MUST indent with 4 spaces; you MUST NOT use tabs.
Statement terminatorsYou MUST NOT write trailing semicolons.
String quotesYou MUST use single quotes for string literals.

You MUST place a space inside the parentheses of if conditions, of destructuring payloads, and of static method calls. The opening parenthesis is followed by a space, and the closing parenthesis is preceded by one:

if( isReady === true ) {
const { id, name } = payload
Registry.write( { id, name } )
}

When you chain array methods, you MUST break the chain so that each step starts on its own line. Each callback SHOULD use an intermediate named parameter instead of a dense single-letter one:

const names = users
.filter( ( user ) => user.active === true )
.map( ( user ) => user.name )

You MUST wrap arrow-function parameters in parentheses, even for a single parameter:

// Prohibited
const double = x => x * 2
// Required
const double = ( x ) => x * 2
// Before
if (ready) {
const {id,name}=payload;
return users.filter(u=>u.active).map(u=>u.name);
}
// After
if( ready === true ) {
const { id, name } = payload
return users
.filter( ( user ) => user.active === true )
.map( ( user ) => user.name )
}