Permalink
Browse files

Add js-style to index; fix rst issues

  • Loading branch information...
willkg committed Jul 23, 2012
1 parent 2ce4028 commit 0bcdc0187a8831e5412cccc195a49a5a84fab41c
Showing with 39 additions and 17 deletions.
  1. +1 −1 coding.rst
  2. +1 −0 index.rst
  3. +37 −16 js-style.rst
View
@@ -202,7 +202,7 @@ Indentation within templates should be handled as such::
.. index:: playdoh
Playdoh
-~~~~~~~
+^^^^^^^
New web-apps should be spawned from Playdoh_ and existing ones should
follow the spirit of Playdoh_. Playdoh_ collects lessons that several
View
@@ -37,6 +37,7 @@ are sometimes done.
git
jenkins
coding
+ js-style
l10n
packaging
data
View
@@ -1,3 +1,5 @@
+.. _js-style:
+
JS Style Guide
==============
@@ -6,15 +8,18 @@ First and Foremost
**ALWAYS** use JSHint_ on your code.
-- There are some exceptions for which JSHint complains about things in
- node that you can ignore, like how it doesn't know what 'const' is
- and complains about not knowing what 'require' is. You can add
- keywords to ignore to a `.jshintrc` file.
+.. Note::
+
+ There are some exceptions for which JSHint complains about things in
+ node that you can ignore, like how it doesn't know what 'const' is
+ and complains about not knowing what 'require' is. You can add
+ keywords to ignore to a `.jshintrc` file.
.. _JSHint: http://www.jshint.com/
+
Variable Formatting:
--------------------
+--------------------
::
@@ -31,10 +36,11 @@ Variable Formatting:
// Client-side
var MY_CONST = ...
-Indentation:
-~~~~~~~~~~~~
-4-space indents (no tabs)
+Indentation
+~~~~~~~~~~~
+
+4-space indents (no tabs).
For our projects, always assign var on a newline, not comma separated::
@@ -48,6 +54,7 @@ For our projects, always assign var on a newline, not comma separated::
var b = 2;
var c = 3;
+
Use ``[]`` to assign a new array, not ``new Array()``.
Use ``{}`` for new objects, as well.
@@ -64,21 +71,24 @@ and the other not so much)::
'other longer stuff'
];
-Never assign multiple variables on the same line.
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Never assign multiple variables on the same line
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bad::
var a = 1, b = 'foo', c = 'wtf';
-DO NOT line up variable names.
+
+DO NOT line up variable names
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bad::
var wut = true;
var boohoo = false;
+
Semi-colons
-----------
@@ -87,8 +97,11 @@ Semi-colons
Not because ASI is black-magic, or whatever. I'm sure we all understand
ASI. Just do it for consistency.
-Conditionals and Loops::
------------------------
+
+Conditionals and Loops
+----------------------
+
+::
// Bad
if (something) doStuff()
@@ -98,8 +111,11 @@ Conditionals and Loops::
doStuff();
}
-Space after keyword, and space before curly::
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Space after keyword, and space before curly
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+::
// Bad
if(bad){
@@ -111,6 +127,7 @@ Space after keyword, and space before curly::
}
+
Functions
---------
@@ -127,6 +144,7 @@ and brace::
}
+
Anonymous Functions
~~~~~~~~~~~~~~~~~~~
@@ -152,7 +170,8 @@ Quotes
Always use single quotes: ``'not double'``
-- Only exception: ``"don't escape single quotes in strings. use double quotes"``
+Only exception: ``"don't escape single quotes in strings. use double quotes"``
+
Comments
--------
@@ -164,11 +183,13 @@ For node functions, always provide a clear comment in this format::
* Returns: whatever it returns
*/
+
If comments are really long, also do it in the ``/* ... */`` format
like above. Otherwise make short comments like::
// This is my short comment and it ends in a period.
+
Ternaries
---------

0 comments on commit 0bcdc01

Please sign in to comment.