From 2263fda7438b51b162fa44a2594d6e77b17e5ee8 Mon Sep 17 00:00:00 2001 From: Jico Baligod Date: Mon, 16 Jun 2014 15:56:01 -0400 Subject: [PATCH 1/9] Update name to Crowdtap --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 61d84b0ea8..0f8092e594 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ -# Airbnb JavaScript Style Guide() { +# Crowdtap JavaScript Style Guide() { *A mostly reasonable approach to JavaScript* +Based on the JS styleguide by [Airbnb](https://github.com/airbnb/javascript) ## Table of Contents From 5930b55e3263f5eef89e0b7939542c83b30fe1f5 Mon Sep 17 00:00:00 2001 From: Jico Baligod Date: Mon, 16 Jun 2014 17:29:14 -0400 Subject: [PATCH 2/9] Crowdtap-flavored tweaks LGTMs: - Carlos - Maulin - Tom - Kyle Closes #1 --- README.md | 73 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 46 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 0f8092e594..bb08757e24 100644 --- a/README.md +++ b/README.md @@ -364,40 +364,18 @@ Based on the JS styleguide by [Airbnb](https://github.com/airbnb/javascript) var superPower = new SuperPower(); ``` - - Use one `var` declaration for multiple variables and declare each variable on a newline. + - Use a `var` declaration for each 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'; - ``` - - - 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. - - ```javascript - // bad - var i, len, dragonball, - items = getItems(), - goSportsTeam = true; - - // bad - var i, items = getItems(), - dragonball, - goSportsTeam = true, - len; // good - var items = getItems(), - goSportsTeam = true, - dragonball, - length, - i; + var items = getItems(); + var goSportsTeam = true; + var dragonball = 'z'; ``` - Assign variables at the top of their scope. This helps avoid issues with variable declaration and assignment hoisting related issues. @@ -716,7 +694,16 @@ Based on the JS styleguide by [Airbnb](https://github.com/airbnb/javascript) return this; } - ``` + ``` + + - Prefix quirks, gotchas, hacks, etc. with `XXX`, especially if it's not + immediately obvious by looking at the code. + + ```javascript + dashboard.controller('Filters', function() { + // XXX: Filters are not tested on CI due to Selenium constraints, please test in browser. + }); + ``` **[⬆ back to top](#table-of-contents)** @@ -833,6 +820,24 @@ Based on the JS styleguide by [Airbnb](https://github.com/airbnb/javascript) .call(tron.led); ``` + - Use indentation for deeply nested objects. + + ```javascript + // bad + var user = { name: 'John Smith', posts: [ { id: 123, title: 'Hello world' } ] }; + + // good + var user = { + name: 'John Smith', + posts: [ + { + id: 123, + title: 'Hello world' + } + ] + }; + ``` + **[⬆ back to top](#table-of-contents)** ## Commas @@ -1043,6 +1048,20 @@ Based on the JS styleguide by [Airbnb](https://github.com/airbnb/javascript) }); ``` + - Using snake\_case is only acceptable for attributes returned from an API + + ```javascript + // bad + Users.get().then(function(data) { + $scope.user_name = data.user_name; + }); + + // good + Users.get().then(function(data) { + $scope.userName = data.user_name; + }); + ``` + - Use PascalCase when naming constructors or classes ```javascript From e1dacaddb539d1c529fc07575b6586ae5a96f6f4 Mon Sep 17 00:00:00 2001 From: Jico Baligod Date: Mon, 16 Jun 2014 17:34:40 -0400 Subject: [PATCH 3/9] Update jshintrc --- linters/jshintrc | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/linters/jshintrc b/linters/jshintrc index d3b47148a8..e482d666b0 100644 --- a/linters/jshintrc +++ b/linters/jshintrc @@ -13,6 +13,12 @@ // Define globals exposed by Node.js. "node": true, + // Define globals exposed by Mocha test framework. + "mocha": true, + + // Define globals provided by assets.shared + "predef": ["Q", "EventBus", "ActionFetcher", "B64"], + /* * ENFORCING OPTIONS * ================= @@ -28,6 +34,9 @@ // Suppress warnings about == null comparisons. "eqnull": true, + // Prohibit overwriting prototypes of native objects. + "freeze": true, + // Enforce tab width of 2 spaces. "indent": 2, From 30769ce08a9f9aa44d88c2999b615e1dd001d542 Mon Sep 17 00:00:00 2001 From: Jico Baligod Date: Tue, 17 Jun 2014 10:07:28 -0400 Subject: [PATCH 4/9] Drop single quoted strings option --- linters/jshintrc | 3 --- 1 file changed, 3 deletions(-) diff --git a/linters/jshintrc b/linters/jshintrc index e482d666b0..f5db90527d 100644 --- a/linters/jshintrc +++ b/linters/jshintrc @@ -46,9 +46,6 @@ // Require capitalized names for constructor functions. "newcap": true, - // Enforce use of single quotation marks for strings. - "quotmark": "single", - // Prohibit trailing whitespace. "trailing": true, From 342ca7e7dd543dd6d745391e5a8ca44b626900e6 Mon Sep 17 00:00:00 2001 From: Jico Baligod Date: Tue, 17 Jun 2014 10:08:55 -0400 Subject: [PATCH 5/9] Update SublimeLinter --- .../SublimeLinter/SublimeLinter.sublime-settings | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/linters/SublimeLinter/SublimeLinter.sublime-settings b/linters/SublimeLinter/SublimeLinter.sublime-settings index 12360f3f1c..b98f1f6e98 100644 --- a/linters/SublimeLinter/SublimeLinter.sublime-settings +++ b/linters/SublimeLinter/SublimeLinter.sublime-settings @@ -28,6 +28,12 @@ // Define globals exposed by Node.js. "node": true, + // Define globals exposed by Mocha test framework. + "mocha": true, + + // Define globals provided by assets.shared + "predef": ["Q", "EventBus", "ActionFetcher", "B64"], + /* * ENFORCING OPTIONS * ================= @@ -43,6 +49,9 @@ // Suppress warnings about == null comparisons. "eqnull": true, + // Prohibit overwriting prototypes of native objects. + "freeze": true, + // Enforce tab width of 2 spaces. "indent": 2, @@ -52,9 +61,6 @@ // Require capitalized names for constructor functions. "newcap": true, - // Enforce use of single quotation marks for strings. - "quotmark": "single", - // Prohibit trailing whitespace. "trailing": true, @@ -63,7 +69,7 @@ // Warn when variables are defined but never used. "unused": true, - + // Enforce line length to 80 characters "maxlen": 80, From 1e29ecb77b94c23dd601a31261c645d982c0d7e8 Mon Sep 17 00:00:00 2001 From: Jico Baligod Date: Mon, 23 Jun 2014 20:34:19 -0400 Subject: [PATCH 6/9] Remove 80 char width requirement --- linters/SublimeLinter/SublimeLinter.sublime-settings | 3 --- linters/jshintrc | 3 --- 2 files changed, 6 deletions(-) diff --git a/linters/SublimeLinter/SublimeLinter.sublime-settings b/linters/SublimeLinter/SublimeLinter.sublime-settings index b98f1f6e98..f96d6cc744 100644 --- a/linters/SublimeLinter/SublimeLinter.sublime-settings +++ b/linters/SublimeLinter/SublimeLinter.sublime-settings @@ -70,9 +70,6 @@ // Warn when variables are defined but never used. "unused": true, - // Enforce line length to 80 characters - "maxlen": 80, - // Enforce placing 'use strict' at the top function scope "strict": true } diff --git a/linters/jshintrc b/linters/jshintrc index f5db90527d..081f97e418 100644 --- a/linters/jshintrc +++ b/linters/jshintrc @@ -55,9 +55,6 @@ // Warn when variables are defined but never used. "unused": true, - // Enforce line length to 80 characters - "maxlen": 80, - // Enforce placing 'use strict' at the top function scope "strict": true } From 84caa76557805741b0c926d5062670ada7bc964c Mon Sep 17 00:00:00 2001 From: Jico Baligod Date: Tue, 1 Jul 2014 17:10:51 -0400 Subject: [PATCH 7/9] Add angular to jshint predef --- linters/SublimeLinter/SublimeLinter.sublime-settings | 4 ++-- linters/jshintrc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/linters/SublimeLinter/SublimeLinter.sublime-settings b/linters/SublimeLinter/SublimeLinter.sublime-settings index f96d6cc744..8029716c28 100644 --- a/linters/SublimeLinter/SublimeLinter.sublime-settings +++ b/linters/SublimeLinter/SublimeLinter.sublime-settings @@ -31,8 +31,8 @@ // Define globals exposed by Mocha test framework. "mocha": true, - // Define globals provided by assets.shared - "predef": ["Q", "EventBus", "ActionFetcher", "B64"], + // Define globals from assets.shared and other libraries + "predef": ["Q", "EventBus", "ActionFetcher", "B64", "angular"], /* * ENFORCING OPTIONS diff --git a/linters/jshintrc b/linters/jshintrc index 081f97e418..9c43e487dc 100644 --- a/linters/jshintrc +++ b/linters/jshintrc @@ -16,8 +16,8 @@ // Define globals exposed by Mocha test framework. "mocha": true, - // Define globals provided by assets.shared - "predef": ["Q", "EventBus", "ActionFetcher", "B64"], + // Define globals from assets.shared and other libraries + "predef": ["Q", "EventBus", "ActionFetcher", "B64", "angular"], /* * ENFORCING OPTIONS From b69502121407da1a40310608b6ef392d8896a992 Mon Sep 17 00:00:00 2001 From: Jico Baligod Date: Mon, 29 Jun 2015 13:06:39 -0400 Subject: [PATCH 8/9] Crowdtap flavored tweaks --- README.md | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index bbd8fbb1bc..f1f01a4d59 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,4 @@ -[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/airbnb/javascript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge) - -# Airbnb JavaScript Style Guide() { +# Crowdtap JavaScript Style Guide() { *A mostly reasonable approach to JavaScript* @@ -1231,6 +1229,13 @@ } } ``` + + - [17.6](#17.6) Use `// XXX:` to annotate quirks, gotchas, and hacks, especially if it's not immediately obvious what the code is doing. + + ```javascript + // XXX: Trims the ", 20XX" from the date string if in current year + if (expiresAt.isSame(moment(), 'year')) time = time.slice(0, -6); + ``` **[⬆ back to top](#table-of-contents)** @@ -1737,6 +1742,24 @@ export default AirbnbStyleGuide; ``` + + - [22.9](#22.9) Using snake_case is only acceptable for attributes returned from an API. + + ```javascript + // bad + Users + .get() + .then( (data) => { + vm.user_name = data.user_name; + }); + + // good + Users + .get() + .then( (data) => { + vm.userName = data.user_name; + }); + ``` **[⬆ back to top](#table-of-contents)** From c9e762dd7ace7fb74ab24192b7ccdcc1694c779d Mon Sep 17 00:00:00 2001 From: Robert Stern Date: Mon, 22 Feb 2016 17:06:08 -0500 Subject: [PATCH 9/9] Use braces with all blocks Closes #2 LGTMs by: * Ben --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ce5229871b..eca714314a 100644 --- a/README.md +++ b/README.md @@ -1334,14 +1334,14 @@ Other Style Guides ## Blocks - - [16.1](#16.1) Use braces with all multi-line blocks. + - [16.1](#16.1) Use braces with all blocks. ```javascript // bad if (test) return false; - // good + // bad if (test) return false; // good