-
Notifications
You must be signed in to change notification settings - Fork 2
Coding Standards
This document states the coding standards by which all Steamed Pears abide.
-
80 character line limit
-
Indent 2 spaces -- no tabs
-
Essentially whole-file indentation is discretionary.
-
Include a vim modeline at the end of the file (within the last 5 lines)
-
/* vim: set softtabstop=2 shiftwidth=2 tabstop=8 expandtab textwidth=80: */ -
Include the licence info block at the top of the file (as near the top as possible, and in its own comment block, using the comment markers appropriate for the language):
/* Copyright by Steamed Pears, 2013. For licensing information, see the LICENCE file in the root directory of this project. */ <!-- Copyright by Steamed Pears, 2013. For licensing information, see the LICENCE file in the root directory of this project. -->
- Double quotes:
<tag attr="blah"></tag> - Lower case
- Conform to HTML5
- Use non-XML style:
<br>
Refer to CSS for id and class naming standards
-
Single quotes:
foo('bar') -
No spaces before and after attributes within parentheses:
function (x) { -
Curly braces on their opening line:
function() { -
Unquoted keys in objects:
{foo:'bar'} -
Use JSHint
-
No fancy ExpressJS style comma first continuations
-
Declare var statements whenever you need a new variable. Not just one var statement per function up top.
-
In argument lists and array literals, a space following commas:
(arg1, arg2, arg3) -
Spaces around all (symbolic, non-unary) operators:
1 + 2 * 3,cond ? truePart : falsePart,x = y, etc. -
Space following the
functionkeyword iff the function is anonymous:function (arg) {...}butfunction foo(arg) {...} -
Space following control structure keywords:
switch (cond),if (cond),while (cond), etc. -
Space preceding the brace opening a block:
if (cond) { -
Name methods with the constructor name, an underscore, and the function name:
function MyConstructor(args) {...}; MyConstructor.prototype = { method: function MyConstructor_method(args) {...} } -
In object literals and
casestatements, space after:but not before. -
ifstatements with one-line consequents should be all on one line or have braces. -
If there's an
elseclause, just put in the braces. -
elseandelse ifon the same line as the}from theif. -
Indent
caseto the same level as the enclosingswitch; indent the body one level more.
- Lower case:
this-is-an-id - Use dashes for spaces in classes and ids:
.this-is-a-class
-
Comment boxes are used to visually partition script files, but they are only to be used outside of blocks of any kind. In other words, they should never be indented. The first line of a comment box is a forward slash followed by 77 asterisks, the last line is 77 asterisks followed by a forward slash. Every line in between begins with an asterisk, a space, a string (comment), then spaces up to the 77th character column, then a closing asterisk. Comment boxes are of the form:
/****************************************************************************** * Start the server * * Start the server * * Start the server * ******************************************************************************/
-
In bash scripts, comment headers will be like above, but with 78 hash symbols.
############################################################################## # Helper functions # ############################################################################## -
The ISO8601 date string shall be acquired by the following command:
date +%Y-%m-%dT%H%M%S%Z