From 23c79a459b86de75d43f3624b01d58fcc7f03149 Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Mon, 27 May 2013 20:05:30 -0300 Subject: [PATCH 01/17] Start Apontador guideline changes --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 9ffa524ba4..4888d6aeda 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ -# Airbnb JavaScript Style Guide() { +# Apontador JavaScript Style Guide() { *A mostly reasonable approach to JavaScript* +Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript). + ## Table of Contents @@ -1402,6 +1404,7 @@ (The MIT License) +Copyright (c) 2013 Apontador Copyright (c) 2012 Airbnb Permission is hereby granted, free of charge, to any person obtaining From f0e006f146ac10af3e1a3c4a65b7bd7fe7128b1c Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Mon, 27 May 2013 20:07:48 -0300 Subject: [PATCH 02/17] fix copyright license --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 4888d6aeda..22b1b199df 100644 --- a/README.md +++ b/README.md @@ -1405,6 +1405,7 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. (The MIT License) Copyright (c) 2013 Apontador + Copyright (c) 2012 Airbnb Permission is hereby granted, free of charge, to any person obtaining From 3dbe7ddffd41db43d197fdde3a714bee8c603b0f Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Tue, 28 May 2013 13:46:18 -0300 Subject: [PATCH 03/17] remove unnecessary linter --- .../SublimeLinter.sublime-settings | 67 ------------------- 1 file changed, 67 deletions(-) delete mode 100644 linters/SublimeLinter/SublimeLinter.sublime-settings diff --git a/linters/SublimeLinter/SublimeLinter.sublime-settings b/linters/SublimeLinter/SublimeLinter.sublime-settings deleted file mode 100644 index 1e12f7c6bb..0000000000 --- a/linters/SublimeLinter/SublimeLinter.sublime-settings +++ /dev/null @@ -1,67 +0,0 @@ -/** - * Airbnb JSHint settings for use with SublimeLinter and Sublime Text 2. - * - * 1. Install SublimeLinter at https://github.com/SublimeLinter/SublimeLinter - * 2. Open user preferences for the SublimeLinter package in Sublime Text 2 - * * For Mac OS X go to _Sublime Text 2_ > _Preferences_ > _Package Settings_ > _SublimeLinter_ > _Settings - User_ - * 3. Paste the contents of this file into your settings file - * 4. Save the settings file - * - * @version 0.3.0 - * @see https://github.com/SublimeLinter/SublimeLinter - * @see http://www.jshint.com/docs/ - */ -{ - "jshint_options": - { - /* - * ENVIRONMENTS - * ================= - */ - - // Define globals exposed by modern browsers. - "browser": true, - - // Define globals exposed by jQuery. - "jquery": true, - - // Define globals exposed by Node.js. - "node": true, - - /* - * ENFORCING OPTIONS - * ================= - */ - - // Force all variable names to use either camelCase style or UPPER_CASE - // with underscores. - "camelcase": true, - - // Prohibit use of == and != in favor of === and !==. - "eqeqeq": true, - - // Suppress warnings about == null comparisons. - "eqnull": true, - - // Enforce tab width of 2 spaces. - "indent": 2, - - // Prohibit use of a variable before it is defined. - "latedef": true, - - // Require capitalized names for constructor functions. - "newcap": true, - - // Enforce use of single quotation marks for strings. - "quotmark": "single", - - // Prohibit trailing whitespace. - "trailing": true, - - // Prohibit use of explicitly undeclared variables. - "undef": true, - - // Warn when variables are defined but never used. - "unused": true - } -} From 0c6f6d5c7d750eb62502250c03e1405f8688ea0b Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Tue, 28 May 2013 13:50:59 -0300 Subject: [PATCH 04/17] 4 spaces, multiline blocks with braces --- README.md | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 22b1b199df..834c388996 100644 --- a/README.md +++ b/README.md @@ -588,19 +588,16 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. ## Blocks - - Use braces with all multi-line blocks. + - Always use multiline blocks with braces. ```javascript // bad if (test) return false; - // good - if (test) return false; - // good if (test) { - return false; + return false; } // bad @@ -608,7 +605,7 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. // good function() { - return false; + return false; } ``` @@ -710,12 +707,12 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. ## Whitespace - - Use soft tabs set to 2 spaces + - Use soft tabs set to 4 spaces ```javascript // bad function() { - ∙∙∙∙var name; + ∙∙var name; } // bad @@ -725,7 +722,7 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. // good function() { - ∙∙var name; + ∙∙∙∙var name; } ``` - Place 1 space before the leading brace. From 742b0e4fc85582add1608fe5745dd5f6999f80cd Mon Sep 17 00:00:00 2001 From: Renan Ivo Date: Wed, 29 May 2013 17:09:55 -0300 Subject: [PATCH 05/17] add our rules and .jshintrc --- .jshintrc | 81 +++++++++++++++++++++ README.md | 195 ++++++++++++++------------------------------------- resources.md | 49 +++++++++++++ 3 files changed, 182 insertions(+), 143 deletions(-) create mode 100644 .jshintrc create mode 100644 resources.md diff --git a/.jshintrc b/.jshintrc new file mode 100644 index 0000000000..0d9ba6836c --- /dev/null +++ b/.jshintrc @@ -0,0 +1,81 @@ +{ + /* + * ENVIRONMENTS + * ================= + */ + + // Define globals exposed by modern browsers. + 'browser': true, + + // Define globals exposed by jQuery. + 'jquery': true, + + /* + * ENFORCING OPTIONS + * ================= + */ + + // Force all variable names to use either camelCase style or UPPER_CASE + // with underscores. + 'camelcase': true, + + // Prohibit use of == and != in favor of === and !==. + 'eqeqeq': true, + + // Suppress warnings about == null comparisons. + 'eqnull': true, + + // Enforce tab width of 2 spaces. + 'indent': 2, + + // Prohibit use of a variable before it is defined. + 'latedef': true, + + // Require capitalized names for constructor functions. + 'newcap': true, + + // Enforce use of single quotation marks for strings. + 'quotmark': "single", + + // Prohibit trailing whitespace. + 'trailing': true, + + // Prohibit use of explicitly undeclared variables. + 'undef': true, + + // Warn when variables are defined but never used. + 'unused': true, + + // Warns when you define and never use your variables + 'curly': true + + // Warns when you use eval + 'evil': true + + // Warns you to filter inherited properties out in a for..in loop + 'forin': true + + // Prohibits the use of immediate function invocations without wrapping them in parentheses + 'immed': true + + // Prohibits the use of arguments.caller and arguments.callee + 'noarg': true + + // Prohibits empty blocks + 'noempty': true + + // Prohibits the use of constructor functions for side-effects + 'nonew': true + + // Disallows the use of dangling _ in the beginning of variables + 'nomen': true + + // Allows only one var statement per function + 'onevar': true + + // Requires all functions to run in ECMAScript 5's strict mode + 'strict': true + + // Warns when you define and never use your variables + 'unused': true +} diff --git a/README.md b/README.md index 834c388996..3dba3300ba 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript). - ## Table of Contents + 1. [JSHint](#jshint) 1. [Types](#types) 1. [Objects](#objects) 1. [Arrays](#arrays) @@ -37,6 +37,11 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. 1. [Contributors](#contributors) 1. [License](#license) +## JSHint + +Most of the rules documented here can be detected by [JSHint](http://jshint.com). +So running *JSHint*, with our [.jshintrc](.jshintrc), before adding code to this repository is the best way to start. + ## Types - **Primitives**: When you access a primitive type you work directly on its value @@ -84,7 +89,7 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. var item = {}; ``` - - Don't use [reserved words](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Reserved_Words) as keys. + - Wrap your object keys with single quotes and try to avoid [reserved words](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Reserved_Words). ```javascript // bad @@ -94,11 +99,18 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. private: true }; - // good + // better var superman = { - klass: 'superhero', - defaults: { clark: 'kent' }, - hidden: true + 'class': 'superhero', + 'default': { clark: 'kent' }, + 'private': true + }; + + // best + var superman = { + 'klass': 'superhero', + 'defaults': { clark: 'kent' }, + 'hidden': true }; ``` **[[⬆]](#TOC)** @@ -256,14 +268,14 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. }; // named function expression - var named = function named() { + function named() { return true; - }; + } // immediately-invoked function expression (IIFE) (function() { console.log('Welcome to the Internet. Please follow me.'); - })(); + }()); ``` - Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears. @@ -278,10 +290,8 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. } // good - if (currentUser) { - var test = function test() { - console.log('Yup.'); - }; + function test() { + console.log('Nope.'); } ``` @@ -340,6 +350,20 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. ## Variables + - Use `window` for global variables + + ```javascript + //bad + function foo() { + myGlobal = 1; + } + + //good + function foo() { + window.myGlobal = 1; + } + ``` + - 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 @@ -588,13 +612,16 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. ## Blocks - - Always use multiline blocks with braces. + - Always use braces. ```javascript // bad if (test) return false; + // bad + if (test) return false; + // good if (test) { return false; @@ -614,15 +641,12 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. ## Comments - - Use `/** ... */` for multiline comments. Include a description, specify types and values for all parameters and return values. + - Use `/** ... */` for multiline comments. ```javascript // bad // make() returns a new element // based on the passed in tag name - // - // @param tag - // @return element function make(tag) { // ...stuff... @@ -634,9 +658,6 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. /** * make() returns a new element * based on the passed in tag name - * - * @param tag - * @return element */ function make(tag) { @@ -676,32 +697,6 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. } ``` - - Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME -- need to figure this out` or `TODO -- need to implement`. - - - Use `// FIXME:` to annotate problems - - ```javascript - function Calculator() { - - // FIXME: shouldn't use a global here - total = 0; - - return this; - } - ``` - - - Use `// TODO:` to annotate solutions to problems - - ```javascript - function Calculator() { - - // TODO: total should be configurable by an options param - this.total = 0; - - return this; - } - ``` - **[[⬆]](#TOC)** @@ -756,14 +751,14 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. // bad (function(global) { // ...stuff... - })(this); + }(this)); ``` ```javascript // good (function(global) { // ...stuff... - })(this); + }(this)); ``` @@ -844,19 +839,13 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. (function() { var name = 'Skywalker' return name - })() + }()) // good (function() { var name = 'Skywalker'; return name; - })(); - - // good - ;(function() { - var name = 'Skywalker'; - return name; - })(); + }()); ``` **[[⬆]](#TOC)** @@ -884,7 +873,6 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. ``` - Use `parseInt` for Numbers and always with a radix for type casting. - - If for whatever reason you are doing something wild and `parseInt` is your bottleneck and need to use Bitshift for [performance reasons](http://jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you're doing. ```javascript var inputValue = '4'; @@ -906,14 +894,6 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. // good var val = parseInt(inputValue, 10); - - // good - /** - * parseInt was the reason my code was slow. - * Bitshifting the String to coerce it to a - * Number made it a lot faster. - */ - var val = inputValue >> 0; ``` - Booleans: @@ -992,18 +972,18 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. }); ``` - - Use a leading underscore `_` when naming private properties + - Never use a leading underscore `_` when naming private properties ```javascript // bad this.__firstName__ = 'Panda'; this.firstName_ = 'Panda'; - // good + // bad this._firstName = 'Panda'; ``` - - When saving a reference to `this` use `_this`. + - When saving a reference to `this` use `self`. ```javascript // bad @@ -1014,7 +994,7 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. }; } - // bad + // good function() { var that = this; return function() { @@ -1317,85 +1297,14 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. **[[⬆]](#TOC)** -## Resources - - -**Read This** +## [Resources](resources.md) - - [Annotated ECMAScript 5.1](http://es5.github.com/) - -**Other Styleguides** - - - [Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml) - - [jQuery Core Style Guidelines](http://docs.jquery.com/JQuery_Core_Style_Guidelines) - - [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwldrn/idiomatic.js/) - -**Other Styles** - - - [Naming this in nested functions](https://gist.github.com/4135065) - Christian Johansen - - [Conditional Callbacks](https://github.com/airbnb/javascript/issues/52) - -**Books** - - - [JavaScript: The Good Parts](http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742) - Douglas Crockford - - [JavaScript Patterns](http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752) - Stoyan Stefanov - - [Pro JavaScript Design Patterns](http://www.amazon.com/JavaScript-Design-Patterns-Recipes-Problem-Solution/dp/159059908X) - Ross Harmes and Dustin Diaz - - [High Performance Web Sites: Essential Knowledge for Front-End Engineers](http://www.amazon.com/High-Performance-Web-Sites-Essential/dp/0596529309) - Steve Souders - - [Maintainable JavaScript](http://www.amazon.com/Maintainable-JavaScript-Nicholas-C-Zakas/dp/1449327680) - Nicholas C. Zakas - - [JavaScript Web Applications](http://www.amazon.com/JavaScript-Web-Applications-Alex-MacCaw/dp/144930351X) - Alex MacCaw - - [Pro JavaScript Techniques](http://www.amazon.com/Pro-JavaScript-Techniques-John-Resig/dp/1590597273) - John Resig - - [Smashing Node.js: JavaScript Everywhere](http://www.amazon.com/Smashing-Node-js-JavaScript-Everywhere-Magazine/dp/1119962595) - Guillermo Rauch - -**Blogs** - - - [DailyJS](http://dailyjs.com/) - - [JavaScript Weekly](http://javascriptweekly.com/) - - [JavaScript, JavaScript...](http://javascriptweblog.wordpress.com/) - - [Bocoup Weblog](http://weblog.bocoup.com/) - - [Adequately Good](http://www.adequatelygood.com/) - - [NCZOnline](http://www.nczonline.net/) - - [Perfection Kills](http://perfectionkills.com/) - - [Ben Alman](http://benalman.com/) - - [Dmitry Baranovskiy](http://dmitry.baranovskiy.com/) - - [Dustin Diaz](http://dustindiaz.com/) - - [nettuts](http://net.tutsplus.com/?s=javascript) **[[⬆]](#TOC)** -## In the Wild - - This is a list of organizations that are using this style guide. Send us a pull request or open an issue and we'll add you to the list. - - - **Airbnb**: [airbnb/javascript](https://github.com/airbnb/javascript) - - **American Insitutes for Research**: [AIRAST/javascript](https://github.com/AIRAST/javascript) - - **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript) - - **GeneralElectric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript) - - **GoodData**: [gooddata/gdc-js-style](https://github.com/gooddata/gdc-js-style) - - **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript) - - **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript) - - **ModCloth**: [modcloth/javascript](https://github.com/modcloth/javascript) - - **National Geographic**: [natgeo/javascript](https://github.com/natgeo/javascript) - - **Razorfish**: [razorfish/javascript-style-guide](https://github.com/razorfish/javascript-style-guide) - - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript) - - **Userify**: [userify/javascript](https://github.com/userify/javascript) - - **Zillow**: [zillow/javascript](https://github.com/zillow/javascript) - -## Translation - - This style guide is also available in other languages: - - - :de: **German**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide) - - :jp: **Japanese**: [mitsuruog/javacript-style-guide](https://github.com/mitsuruog/javacript-style-guide) - - :br: **Portuguese**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide) - -## The JavaScript Style Guide Guide - - - [Reference](https://github.com/airbnb/javascript/wiki/The-JavaScript-Style-Guide-Guide) - ## Contributors - - [View Contributors](https://github.com/airbnb/javascript/graphs/contributors) - + - [View Contributors](https://github.com/apontador/javascript/graphs/contributors) ## License diff --git a/resources.md b/resources.md new file mode 100644 index 0000000000..026465e575 --- /dev/null +++ b/resources.md @@ -0,0 +1,49 @@ +Resources +========= + +Read This +--------- + + - [Annotated ECMAScript 5.1](http://es5.github.com/) + - [JavaScript Scoping and Hoisting](http://www.adequatelygood.com/JavaScript-Scoping-and-Hoisting.html) + +Other Styleguides +----------------- + + - [Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml) + - [jQuery Core Style Guidelines](http://docs.jquery.com/JQuery_Core_Style_Guidelines) + - [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwldrn/idiomatic.js/) + +Other Styles +------------ + + - [Naming this in nested functions](https://gist.github.com/4135065) - Christian Johansen + - [Conditional Callbacks](https://github.com/airbnb/javascript/issues/52) + +Books +----- + + - [JavaScript: The Good Parts](http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742) - Douglas Crockford + - [JavaScript Patterns](http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752) - Stoyan Stefanov + - [Pro JavaScript Design Patterns](http://www.amazon.com/JavaScript-Design-Patterns-Recipes-Problem-Solution/dp/159059908X) - Ross Harmes and Dustin Diaz + - [High Performance Web Sites: Essential Knowledge for Front-End Engineers](http://www.amazon.com/High-Performance-Web-Sites-Essential/dp/0596529309) - Steve Souders + - [Maintainable JavaScript](http://www.amazon.com/Maintainable-JavaScript-Nicholas-C-Zakas/dp/1449327680) - Nicholas C. Zakas + - [JavaScript Web Applications](http://www.amazon.com/JavaScript-Web-Applications-Alex-MacCaw/dp/144930351X) - Alex MacCaw + - [Pro JavaScript Techniques](http://www.amazon.com/Pro-JavaScript-Techniques-John-Resig/dp/1590597273) - John Resig + - [Smashing Node.js: JavaScript Everywhere](http://www.amazon.com/Smashing-Node-js-JavaScript-Everywhere-Magazine/dp/1119962595) - Guillermo Rauch + +Blogs +----- + + - [DailyJS](http://dailyjs.com/) + - [JavaScript Weekly](http://javascriptweekly.com/) + - [JavaScript, JavaScript...](http://javascriptweblog.wordpress.com/) + - [Bocoup Weblog](http://weblog.bocoup.com/) + - [Adequately Good](http://www.adequatelygood.com/) + - [NCZOnline](http://www.nczonline.net/) + - [Perfection Kills](http://perfectionkills.com/) + - [Ben Alman](http://benalman.com/) + - [Dmitry Baranovskiy](http://dmitry.baranovskiy.com/) + - [Dustin Diaz](http://dustindiaz.com/) + - [nettuts](http://net.tutsplus.com/?s=javascript) + From 06aabe1e503d6a0808367a6b3b61f61835e0052f Mon Sep 17 00:00:00 2001 From: Renan Ivo Date: Wed, 29 May 2013 17:12:58 -0300 Subject: [PATCH 06/17] modify rule for long strings --- README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3dba3300ba..454bc07343 100644 --- a/README.md +++ b/README.md @@ -186,7 +186,7 @@ So running *JSHint*, with our [.jshintrc](.jshintrc), before adding code to this var fullName = 'Bob ' + this.lastName; ``` - - Strings longer than 80 characters should be written across multiple lines using string concatenation. + - Strings longer than 80 characters should be written in array and concatenated with `join()`. - Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40) ```javascript @@ -203,12 +203,14 @@ So running *JSHint*, with our [.jshintrc](.jshintrc), before adding code to this // good - var errorMessage = 'This is a super long error that ' + - 'was thrown because of Batman.' + - 'When you stop to think about ' + - 'how Batman had anything to do ' + - 'with this, you would get nowhere ' + - 'fast.'; + var errorMessage = [ + 'This is a super long error that ', + 'was thrown because of Batman.', + 'When you stop to think about ', + 'how Batman had anything to do ', + 'with this, you would get nowhere ', + 'fast.' + ].join(''); ``` - When programatically building up a string, use Array#join instead of string concatenation. Mostly for IE: [jsPerf](http://jsperf.com/string-vs-array-concat/2). From bba0797f1af3fd41e9593a2fa4a473f7e537a69c Mon Sep 17 00:00:00 2001 From: Renan Ivo Date: Wed, 29 May 2013 17:14:05 -0300 Subject: [PATCH 07/17] add white option to jshintrc --- .jshintrc | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.jshintrc b/.jshintrc index 0d9ba6836c..44e0cd39cf 100644 --- a/.jshintrc +++ b/.jshintrc @@ -78,4 +78,7 @@ // Warns when you define and never use your variables 'unused': true + + // Code Style warnings + 'white': true } From ddcc3d876feb09f3a0ad265c9f3648a1d6398841 Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Wed, 29 May 2013 17:36:05 -0300 Subject: [PATCH 08/17] Avoid wrap object keys with quotes and reserved words --- README.md | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 454bc07343..22712802fc 100644 --- a/README.md +++ b/README.md @@ -89,7 +89,7 @@ So running *JSHint*, with our [.jshintrc](.jshintrc), before adding code to this var item = {}; ``` - - Wrap your object keys with single quotes and try to avoid [reserved words](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Reserved_Words). + - Avoid wrap object keys with quotes, avoid also the [reserved words](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Reserved_Words). ```javascript // bad @@ -99,18 +99,34 @@ So running *JSHint*, with our [.jshintrc](.jshintrc), before adding code to this private: true }; - // better + // bad for our conventions (doesn't include JSON callback) var superman = { - 'class': 'superhero', - 'default': { clark: 'kent' }, - 'private': true + 'foo': 'superhero', + 'bar': { clark: 'kent' } }; - // best + // good + var superman = { + around: 'superhero', + the: { clark: 'kent' }, + world: true + }; + + // bad var superman = { - 'klass': 'superhero', - 'defaults': { clark: 'kent' }, - 'hidden': true + around: 'superhero', + the: { clark: 'kent', lois: 'lane' }, + world: true + }; + + // good + var superman = { + around: 'superhero', + the: { + clark: 'kent', + lois: 'lane' + }, + world: true }; ``` **[[⬆]](#TOC)** From eded7db07e2f44dfa8eb25d0ef5add3221df6aa7 Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Wed, 29 May 2013 17:49:27 -0300 Subject: [PATCH 09/17] Move hoisting tutorial to resources.md --- README.md | 87 +------------------------------------------------------ 1 file changed, 1 insertion(+), 86 deletions(-) diff --git a/README.md b/README.md index 22712802fc..be63991541 100644 --- a/README.md +++ b/README.md @@ -489,92 +489,7 @@ So running *JSHint*, with our [.jshintrc](.jshintrc), before adding code to this **[[⬆]](#TOC)** -## Hoisting - - - Variable declarations get hoisted to the top of their scope, their assignment does not. - - ```javascript - // we know this wouldn't work (assuming there - // is no notDefined global variable) - function example() { - console.log(notDefined); // => throws a ReferenceError - } - - // creating a variable declaration after you - // reference the variable will work due to - // variable hoisting. Note: the assignment - // value of `true` is not hoisted. - function example() { - console.log(declaredButNotAssigned); // => undefined - var declaredButNotAssigned = true; - } - - // The interpreter is hoisting the variable - // declaration to the top of the scope. - // Which means our example could be rewritten as: - function example() { - var declaredButNotAssigned; - console.log(declaredButNotAssigned); // => undefined - declaredButNotAssigned = true; - } - ``` - - - Anonymous function expressions hoist their variable name, but not the function assignment. - - ```javascript - function example() { - console.log(anonymous); // => undefined - - anonymous(); // => TypeError anonymous is not a function - - var anonymous = function() { - console.log('anonymous function expression'); - }; - } - ``` - - - Named function expressions hoist the variable name, not the function name or the function body. - - ```javascript - function example() { - console.log(named); // => undefined - - named(); // => TypeError named is not a function - - superPower(); // => ReferenceError superPower is not defined - - var named = function superPower() { - console.log('Flying'); - }; - - - // the same is true when the function name - // is the same as the variable name. - function example() { - console.log(named); // => undefined - - named(); // => TypeError named is not a function - - var named = function named() { - console.log('named'); - }; - } - } - ``` - - - Function declarations hoist their name and the function body. - - ```javascript - function example() { - superPower(); // => Flying - - function superPower() { - console.log('Flying'); - } - } - ``` - - - For more information refer to [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting) by [Ben Cherry](http://www.adequatelygood.com/) +## [Hoisting](resources.md#read-this) **[[⬆]](#TOC)** From bcdf0dabe51153b910dbcd1e295d68d89de59d32 Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Wed, 29 May 2013 17:54:10 -0300 Subject: [PATCH 10/17] orgazine references to resources.md --- README.md | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index be63991541..00cf014ef5 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,6 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. 1. [Functions](#functions) 1. [Properties](#properties) 1. [Variables](#variables) - 1. [Hoisting](#hoisting) 1. [Conditional Expressions & Equality](#conditionals) 1. [Blocks](#blocks) 1. [Comments](#comments) @@ -30,6 +29,7 @@ Note: this guideline is based on [Airbnb JavaScript Style Guide](https://github. 1. [ES5 Compatibility](#es5) 1. [Testing](#testing) 1. [Performance](#performance) + 1. [Hoisting](#hoisting) 1. [Resources](#resources) 1. [In the Wild](#in-the-wild) 1. [Translation](#translation) @@ -488,13 +488,6 @@ So running *JSHint*, with our [.jshintrc](.jshintrc), before adding code to this **[[⬆]](#TOC)** - -## [Hoisting](resources.md#read-this) - - **[[⬆]](#TOC)** - - - ## Conditional Expressions & Equality - Use `===` and `!==` over `==` and `!=`. @@ -1229,11 +1222,10 @@ So running *JSHint*, with our [.jshintrc](.jshintrc), before adding code to this **[[⬆]](#TOC)** +You must take a look: +### [Hoisting](resources.md#read-this) +### [Resources](resources.md) -## [Resources](resources.md) - - - **[[⬆]](#TOC)** ## Contributors From f10f2c264095a7b065d6e7e5deb58511683dfe6e Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Wed, 29 May 2013 18:27:02 -0300 Subject: [PATCH 11/17] define indentations --- .editorconfig | 14 ++++++++++++++ .jshintrc | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000000..b4b33a8f89 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +; EditorConfig is awesome: http://EditorConfig.org + +; top-most EditorConfig file +root = true + +; Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true + +; Tab indentation (no size specified) +[*.js] +indent_style = space + diff --git a/.jshintrc b/.jshintrc index 44e0cd39cf..6df7f58b06 100644 --- a/.jshintrc +++ b/.jshintrc @@ -25,8 +25,8 @@ // Suppress warnings about == null comparisons. 'eqnull': true, - // Enforce tab width of 2 spaces. - 'indent': 2, + // Enforce tab width of 4 spaces. + 'indent': 4, // Prohibit use of a variable before it is defined. 'latedef': true, From a0f624bff9a550840d34837474ad41842ce2ef16 Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Wed, 29 May 2013 18:28:18 -0300 Subject: [PATCH 12/17] fix editor config --- .editorconfig | 1 + 1 file changed, 1 insertion(+) diff --git a/.editorconfig b/.editorconfig index b4b33a8f89..3743f789e8 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,4 +11,5 @@ insert_final_newline = true ; Tab indentation (no size specified) [*.js] indent_style = space +indent_size = 4 From 927c315c27e867a195bff5100f928246adcfc9a4 Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Wed, 29 May 2013 19:11:21 -0300 Subject: [PATCH 13/17] fix jshintrc missing commas --- .jshintrc | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/.jshintrc b/.jshintrc index 6df7f58b06..a9d90c27e5 100644 --- a/.jshintrc +++ b/.jshintrc @@ -47,37 +47,37 @@ 'unused': true, // Warns when you define and never use your variables - 'curly': true + 'curly': true, // Warns when you use eval - 'evil': true + 'evil': true, // Warns you to filter inherited properties out in a for..in loop - 'forin': true + 'forin': true, // Prohibits the use of immediate function invocations without wrapping them in parentheses - 'immed': true + 'immed': true, // Prohibits the use of arguments.caller and arguments.callee - 'noarg': true + 'noarg': true, // Prohibits empty blocks - 'noempty': true + 'noempty': true, // Prohibits the use of constructor functions for side-effects - 'nonew': true + 'nonew': true, // Disallows the use of dangling _ in the beginning of variables - 'nomen': true + 'nomen': true, // Allows only one var statement per function - 'onevar': true + 'onevar': true, // Requires all functions to run in ECMAScript 5's strict mode - 'strict': true + 'strict': true, // Warns when you define and never use your variables - 'unused': true + 'unused': true, // Code Style warnings 'white': true From 83a6725247fff5bb7d3b3261dd876991eeb305ab Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Fri, 31 May 2013 09:29:39 -0300 Subject: [PATCH 14/17] remove jshintrc comments --- .jshintrc | 106 +++++++++++++----------------------------------------- 1 file changed, 24 insertions(+), 82 deletions(-) diff --git a/.jshintrc b/.jshintrc index a9d90c27e5..b1ab648f6b 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,84 +1,26 @@ { - /* - * ENVIRONMENTS - * ================= - */ - - // Define globals exposed by modern browsers. - 'browser': true, - - // Define globals exposed by jQuery. - 'jquery': true, - - /* - * ENFORCING OPTIONS - * ================= - */ - - // Force all variable names to use either camelCase style or UPPER_CASE - // with underscores. - 'camelcase': true, - - // Prohibit use of == and != in favor of === and !==. - 'eqeqeq': true, - - // Suppress warnings about == null comparisons. - 'eqnull': true, - - // Enforce tab width of 4 spaces. - 'indent': 4, - - // Prohibit use of a variable before it is defined. - 'latedef': true, - - // Require capitalized names for constructor functions. - 'newcap': true, - - // Enforce use of single quotation marks for strings. - 'quotmark': "single", - - // Prohibit trailing whitespace. - 'trailing': true, - - // Prohibit use of explicitly undeclared variables. - 'undef': true, - - // Warn when variables are defined but never used. - 'unused': true, - - // Warns when you define and never use your variables - 'curly': true, - - // Warns when you use eval - 'evil': true, - - // Warns you to filter inherited properties out in a for..in loop - 'forin': true, - - // Prohibits the use of immediate function invocations without wrapping them in parentheses - 'immed': true, - - // Prohibits the use of arguments.caller and arguments.callee - 'noarg': true, - - // Prohibits empty blocks - 'noempty': true, - - // Prohibits the use of constructor functions for side-effects - 'nonew': true, - - // Disallows the use of dangling _ in the beginning of variables - 'nomen': true, - - // Allows only one var statement per function - 'onevar': true, - - // Requires all functions to run in ECMAScript 5's strict mode - 'strict': true, - - // Warns when you define and never use your variables - 'unused': true, - - // Code Style warnings - 'white': true + "browser": true, + "jquery": true, + "camelcase": true, + "eqeqeq": true, + "eqnull": true, + "indent": 4, + "latedef": true, + "newcap": true, + "quotmark": "single", + "trailing": true, + "undef": true, + "unused": true, + "curly": true, + "evil": true, + "forin": true, + "immed": true, + "noarg": true, + "noempty": true, + "nonew": true, + "nomen": true, + "onevar": true, + "strict": true, + "unused": true, + "white": true } From e5058abcbaeed8fd1b0275c20eafae1537f6a00a Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Fri, 31 May 2013 09:47:28 -0300 Subject: [PATCH 15/17] set jshintrc node true for gruntfiles --- .jshintrc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.jshintrc b/.jshintrc index b1ab648f6b..b35d54c79d 100644 --- a/.jshintrc +++ b/.jshintrc @@ -22,5 +22,6 @@ "onevar": true, "strict": true, "unused": true, - "white": true + "white": true, + "node": true } From 600a9bc08d2fb0ddf0d316cf9717a804150c75fd Mon Sep 17 00:00:00 2001 From: Helder Santana Date: Mon, 3 Jun 2013 11:27:36 -0300 Subject: [PATCH 16/17] use editor config for all files extension --- .editorconfig | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.editorconfig b/.editorconfig index 3743f789e8..51dfc8fe4d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,9 +7,5 @@ root = true [*] end_of_line = lf insert_final_newline = true - -; Tab indentation (no size specified) -[*.js] indent_style = space indent_size = 4 - From 8a73ee304a68c6f208f170446398dcf134dab88a Mon Sep 17 00:00:00 2001 From: Renan Ivo Date: Thu, 27 Jun 2013 20:29:56 -0300 Subject: [PATCH 17/17] remove weird function naming --- README.md | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/README.md b/README.md index 00cf014ef5..1c50a7d7ee 100644 --- a/README.md +++ b/README.md @@ -937,20 +937,6 @@ So running *JSHint*, with our [.jshintrc](.jshintrc), before adding code to this } ``` - - Name your functions. This is helpful for stack traces. - - ```javascript - // bad - var log = function(msg) { - console.log(msg); - }; - - // good - var log = function log(msg) { - console.log(msg); - }; - ``` - **[[⬆]](#TOC)**