-
Notifications
You must be signed in to change notification settings - Fork 63
Code Style Guide
Tom Brasington edited this page Jan 7, 2014
·
14 revisions
Whitespace
- Four space indent/tab-width.
- Indent/align with spaces.
- No tab characters
- End files with one blank line.
- Round braces are snug:
// Like so:
if (foobar)
{
}
foo(bar, baz);
// Not like:
if ( foobar )
{
}
foo( bar, baz );
Curly Braces
- Go on their own line:
function foo()
{
return "bar";
}
if (foobar)
{
}
while (foobar)
{
}
- May be omitted in 'if', 'while', etc if the body is only one line:
// Note: body goes on it's own line.
// Like so:
if (foo)
bar();
// Not like:
if (foo) bar();
// Note: Lack/presence of braces should be consistent within a given statement.
// Like so:
if (foo)
{
bar();
baz();
}
else
{
quux();
}
// Not like:
if (foo)
{
bar();
baz();
}
else
quux();
Semicolons
- After any expression, return statement, or var statement:
var a = b;
if (foo)
{
}
while (foo)
{
}
function baz()
{
return 42;
}
var foo = function()
{
return 42;
};
Commas
- Go at the end of the line:
var foo = {
bar : 'bar',
baz : 'baz'
};
Modules
- Prepended with the Higgs license header (TODO: link).
- Enclosed in an IIFE (all files are evaluated in the same scope):
(function()
{
exports.myVar = 808;
exports.myFun = function()
{
}
})();
Other
Please have a look at some of the Higgs source code to get a general impression of the style being used.