Skip to content

Latest commit

 

History

History
129 lines (108 loc) · 3.23 KB

File metadata and controls

129 lines (108 loc) · 3.23 KB
  • use strict;
  • Absolutely no eval() statements
  • Variables must be explicitly declared
  • No trailing whitespace
  • No console.log()
  • No commented out code
  • Use tabs to indent and spaces to align
  • Use single quotes
  • Lower camel case all class members var, function
  • Upper camel case all classes and constructors
  • Lower camel case packages
  • Descriptive variable names
  • Prefix internal/private methods and variables with _
  • Use sugar syntax for all imports except dependencies loaded on demand, a la commonjs "sugar" syntax

File Names

  • lower-case-hyphenated-folder-names
  • Folder names are lower-case dash-separated
  • Anything that talks about a path should talk hyphenated
  • UpperCamelCase all files that export classes (Models, Collections, Views, Controllers, Applications, Modules)
  • Test file name should match the file you are testing with a suffix of Test
  • Marionette Models, Controllers, Routers, and Collections end with their class types
  • Marionette Layouts ends with Layout
  • Marionette Composite or Collection Views end with View
  • Marionette Item Views are the same name as their Composite or Collection View and end with ItemView
  • Template names are lower camel-case, named after their view
  • The type of data ( model or collection ) is singular ( e.g. UserCollection, UserModel )

Spacing & Alignment

Spaces between colons

{
	'key1' : 'value',
	'key2' : 'value',
}

Spaces after commas

[ 1, 2, 'three' ]

Spaces after flow control keywords if, for, while, etc.

if () {
	// stuff
}

Spaces in bracket accessors

myArray[ 0 ]
myObject[ 'weird-name' ]

Function params user pre and post spaces. Function invocation use post spaces.

function ( a, b, c ) {
	// stuff
}
foo( a, b, c );

Code blocks

Open curly braces on the same line as the declaration and they end the line their on. Closing curly braces start on their own line. exception: empty object declaration {}

if () {
	// stuff
}

No inline code blocks

if ( test === 'foo' ) doStuff();

Nor relying on indentation alone

if ( test === 'foo' )
	doStuff();

After 2 key/value pairs in an object or array (generally), line break all key/value pairs.

{ 'a' : 5 }
[ 1, 2, 'three' ]

Object Keys & Values

Keys in key/value pairs must be quoted

{
	'key1' : 'value',
	'key2' : 'value',
}

Consecutive values in key/value pairs must be horizontally aligned

var a         = 'foo'
var testError = 'lorem';

var foo = {
	'key'       : 'value',
	'longerKey' : 'value',
	'a'         : 'value'
}

Each var is separately declared & assigned var; var; var; ...

var a         = 'foo';
var testError = 'lorem';

Comments

Events

  • Event names should fit their purpose, e.g. pageChange for changing a page.
  • When events are emitted as part of an API for external listeners, the class name should be included, e.g. SimpleMenu:change.