From d72eb3ae209a07ccd51cf44779df6b56d08c8631 Mon Sep 17 00:00:00 2001 From: Joe Sepi Date: Wed, 21 Aug 2013 13:08:24 -0400 Subject: [PATCH 1/4] some initial tweaks to the styleguide. let's discuss --- README.md | 52 +++++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index dbafdc488d..5f60878e8d 100644 --- a/README.md +++ b/README.md @@ -356,6 +356,7 @@ ## Variables + - Always use `var` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that. ```javascript @@ -366,28 +367,28 @@ var superPower = new SuperPower(); ``` - - Use one `var` declaration for multiple variables and declare each variable on a newline. + - Use a `var` declaration for every assigned variable and declare each variable on a newline. ```javascript // bad - var items = getItems(); - var goSportsTeam = true; - var dragonball = 'z'; - - // good var items = getItems(), goSportsTeam = true, dragonball = 'z'; + + // bad + var items = getItems() + , goSportsTeam = true + , dragonball = 'z'; + + // good + var items = getItems(); + var goSportsTeam = true; + var dragonball = 'z'; ``` - - Declare unassigned variables last. This is helpful when later on you might need to assign a variable depending on one of the previous assigned variables. + - Declare unassigned variables first and on one line, separated by commas. ```javascript - // bad - var i, len, dragonball, - items = getItems(), - goSportsTeam = true; - // bad var i, items = getItems(), dragonball, @@ -395,11 +396,9 @@ len; // good - var items = getItems(), - goSportsTeam = true, - dragonball, - length, - i; + var i, len, dragonball; + var items = getItems(); + var goSportsTeam = true; ``` - Assign variables at the top of their scope. This helps avoid issues with variable declaration and assignment hoisting related issues. @@ -719,19 +718,19 @@ return this; } - ``` + ``` **[[⬆]](#TOC)** ## Whitespace - - Use soft tabs set to 2 spaces + - Use soft tabs set to 4 spaces ```javascript // bad function() { - ∙∙∙∙var name; + ∙∙var name; } // bad @@ -741,7 +740,7 @@ // good function() { - ∙∙var name; + ∙∙∙∙var name; } ``` - Place 1 space before the leading brace. @@ -779,7 +778,7 @@ ``` ```javascript - // good + // good (trust me, there is a new line at the end of this snippet) (function(global) { // ...stuff... })(this); @@ -829,11 +828,6 @@ , upon , aTime; - // good - var once, - upon, - aTime; - // bad var hero = { firstName: 'Bob' @@ -851,9 +845,9 @@ }; ``` - - Additional trailing comma: **Nope.** This can cause problems with IE6/7 and IE9 if it's in quirksmode. Also, in some implementations of ES3 would add length to an array if it had an additional trailing comma. This was clarified in ES5 ([source](http://es5.github.io/#D)): + - Additional trailing comma: **Nope.** This can cause problems with IE6/7 and IE9 if it's in quirksmode. Also, in some implementations of ES3 would add length to an array if it had an additional trailing comma. This was clarified in ES5 ([source](http://es5.github.io/#D)): - > Edition 5 clarifies the fact that a trailing comma at the end of an ArrayInitialiser does not add to the length of the array. This is not a semantic change from Edition 3 but some implementations may have previously misinterpreted this. + > Edition 5 clarifies the fact that a trailing comma at the end of an ArrayInitialiser does not add to the length of the array. This is not a semantic change from Edition 3 but some implementations may have previously misinterpreted this. ```javascript // bad From 4ab76658774d3884c308544d89ba6a7aa49fae7c Mon Sep 17 00:00:00 2001 From: Joe Sepi Date: Wed, 21 Aug 2013 16:42:17 -0400 Subject: [PATCH 2/4] updated linter settings --- linters/SublimeLinter/SublimeLinter.sublime-settings | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/linters/SublimeLinter/SublimeLinter.sublime-settings b/linters/SublimeLinter/SublimeLinter.sublime-settings index 1e12f7c6bb..afc2d69cba 100644 --- a/linters/SublimeLinter/SublimeLinter.sublime-settings +++ b/linters/SublimeLinter/SublimeLinter.sublime-settings @@ -44,7 +44,7 @@ "eqnull": true, // Enforce tab width of 2 spaces. - "indent": 2, + "indent": 4, // Prohibit use of a variable before it is defined. "latedef": true, From 72e4d9e412fc0bd1dd1564adfccb18e6d7ab4853 Mon Sep 17 00:00:00 2001 From: Robin Hu Date: Fri, 27 Sep 2013 17:39:43 -0400 Subject: [PATCH 3/4] Updated README to describe file naming conventions. --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 5f60878e8d..254956805a 100644 --- a/README.md +++ b/README.md @@ -1090,6 +1090,17 @@ ``` **[[⬆]](#TOC)** + + - Name your files using dashes and all lowercase. + ```javascript + //bad + myFile.js + MY_File.js + + //good + my-file.js + ``` + ## Accessors From a1d4c05a8fde72c036fa32d2a7d7a5e0d22e0943 Mon Sep 17 00:00:00 2001 From: Joe Sepi Date: Tue, 22 Oct 2013 14:23:27 -0400 Subject: [PATCH 4/4] updating title --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 254956805a..f9760cd466 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Airbnb JavaScript Style Guide() { +# Novus JavaScript Style Guide() { *A mostly reasonable approach to JavaScript* @@ -1090,17 +1090,17 @@ ``` **[[⬆]](#TOC)** - + - Name your files using dashes and all lowercase. ```javascript //bad myFile.js MY_File.js - + //good my-file.js ``` - + ## Accessors