diff --git a/README.md b/README.md index dbafdc488d..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* @@ -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 @@ -1097,6 +1091,17 @@ **[[⬆]](#TOC)** + - Name your files using dashes and all lowercase. + ```javascript + //bad + myFile.js + MY_File.js + + //good + my-file.js + ``` + + ## Accessors 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,