Skip to content

Coding Standards

fabien-d edited this page Dec 2, 2012 · 4 revisions

Alertify Coding Standards are set for all code in the code-base to look like a single person wrote it. This is not to say my style preference is better than another, it's simply to keep the project consistent and easier to read.

Most of the code standards are based on idiomatic.js with a few minor overwrites/differences or project specifics.

Project Specific

  1. Whitespace: Tabs for indentation (spaces to align multiline variables)
  • 1 space between function brackets and operators
  1. Quotes: Double quotes
  2. Single Line Statements: No curly braces for single line statements (code on 1 line not 2)

Whitespace

function () {
	// tabs
	var tab;
};

// spaces to align variables
var a..= "",
....ab.= "";

// spaces between operators and function brackets
// yes
function () {
a + b = c;
a === b

// no
function(){
a+b=c;
a===b

Single Line Statements

Yes

if (statement) something();
else somethingElse();

No

if (statement)
	something();
else
	somethingElse();

Lint

Current JSHint configuration

jshint : {
	options: {
		curly     : false,
		eqeqeq    : true,
		immed     : true,
		latedef   : true,
		noempty   : true,
		newcap    : true,
		noarg     : true,
		sub       : true,
		undef     : true,
		boss      : true,
		eqnull    : true,
		node      : true,
		smarttabs : true,
		es5       : true
	},
	globals : {
		exports : true,
		define  : true		
	}
}
Clone this wiki locally