NodeBB Style Guide¶
For the most part, NodeBB follows the Google Javascript Style Guide.
Code Formatting¶
Note
The existing codebase as of July 2013 does not adhere to this style guide 100%. If you see instances where the style guide is not adhered to, feel free to restyle and send off a pull request.
Indentation & Bracing¶
NodeBB uses tabbed indentation. Bracing should follow the One True Brace Style:
if (condition) {
// code here ...
} else {
// otherwise ...
}
Put conditionals and statements on separate lines and wrap with curly braces even if it’s just one line:
if (leTired) {
haveANap();
}
Errors¶
Most callbacks return an error as the first parameter. Handle this error first before processing further.
someFunction(parameters, function(err, data) {
if (err) {
return callback(err); // or handle error
}
// proceed as usual
});
Variables¶
Variables should always be prefaced with the var keyword:
var foo = 'bar';
Use var on multiple declarations :
var foo = 'bar';
var bar = 'baz';
Nomenclature¶
CamelCase if at all possible:
functionNamesLikeThis, variableNamesLikeThis, ClassNamesLikeThis, EnumNamesLikeThis, methodNamesLikeThis, CONSTANT_VALUES_LIKE_THIS, foo.namespaceNamesLikeThis.bar, and filenameslikethis.js.