From fa7cc4129057a80b5e886dc730ba078b9ff12e1b Mon Sep 17 00:00:00 2001 From: Wendall Cada Date: Thu, 10 Apr 2014 09:01:13 -0700 Subject: [PATCH 1/2] Updated whitespace rules. --- README.md | 488 +++++++++++++++++++++++++++--------------------------- 1 file changed, 245 insertions(+), 243 deletions(-) diff --git a/README.md b/README.md index f8c0be49f2..4874a87ea0 100644 --- a/README.md +++ b/README.md @@ -88,14 +88,14 @@ ```javascript // bad var superman = { - default: { clark: 'kent' }, - private: true + default: { clark: 'kent' }, + private: true }; // good var superman = { - defaults: { clark: 'kent' }, - hidden: true + defaults: { clark: 'kent' }, + hidden: true }; ``` @@ -104,17 +104,17 @@ ```javascript // bad var superman = { - class: 'alien' + class: 'alien' }; // bad var superman = { - klass: 'alien' + klass: 'alien' }; // good var superman = { - type: 'alien' + type: 'alien' }; ``` @@ -154,7 +154,7 @@ // bad for (i = 0; i < len; i++) { - itemsCopy[i] = items[i]; + itemsCopy[i] = items[i]; } // good @@ -165,8 +165,8 @@ ```javascript function trigger() { - var args = Array.prototype.slice.call(arguments); - ... + var args = Array.prototype.slice.call(arguments); + ... } ``` @@ -219,38 +219,38 @@ i; messages = [{ - state: 'success', - message: 'This one worked.' + state: 'success', + message: 'This one worked.' }, { - state: 'success', - message: 'This one worked as well.' + state: 'success', + message: 'This one worked as well.' }, { - state: 'error', - message: 'This one did not work.' + state: 'error', + message: 'This one did not work.' }]; length = messages.length; // bad function inbox(messages) { - items = ''; } // good function inbox(messages) { - items = []; + items = []; - for (i = 0; i < length; i++) { - items[i] = messages[i].message; - } + for (i = 0; i < length; i++) { + items[i] = messages[i].message; + } - return ''; + return ''; } ``` @@ -264,17 +264,17 @@ ```javascript // anonymous function expression var anonymous = function() { - return true; + return true; }; // named function expression var named = function named() { - return true; + return true; }; // immediately-invoked function expression (IIFE) (function() { - console.log('Welcome to the Internet. Please follow me.'); + console.log('Welcome to the Internet. Please follow me.'); })(); ``` @@ -284,17 +284,17 @@ ```javascript // bad if (currentUser) { - function test() { - console.log('Nope.'); - } + function test() { + console.log('Nope.'); + } } // good var test; if (currentUser) { - test = function test() { - console.log('Yup.'); - }; + test = function test() { + console.log('Yup.'); + }; } ``` @@ -303,12 +303,12 @@ ```javascript // bad function nope(name, options, arguments) { - // ...stuff... + // ...stuff... } // good function yup(name, options, args) { - // ...stuff... + // ...stuff... } ``` @@ -322,8 +322,8 @@ ```javascript var luke = { - jedi: true, - age: 28 + jedi: true, + age: 28 }; // bad @@ -337,12 +337,12 @@ ```javascript var luke = { - jedi: true, - age: 28 + jedi: true, + age: 28 }; function getProp(prop) { - return luke[prop]; + return luke[prop]; } var isJedi = getProp('jedi'); @@ -404,56 +404,56 @@ ```javascript // bad function() { - test(); - console.log('doing stuff..'); + test(); + console.log('doing stuff..'); - //..other stuff.. + //..other stuff.. - var name = getName(); + var name = getName(); - if (name === 'test') { - return false; - } + if (name === 'test') { + return false; + } - return name; + return name; } // good function() { - var name = getName(); + var name = getName(); - test(); - console.log('doing stuff..'); + test(); + console.log('doing stuff..'); - //..other stuff.. + //..other stuff.. - if (name === 'test') { - return false; - } + if (name === 'test') { + return false; + } - return name; + return name; } // bad function() { - var name = getName(); + var name = getName(); - if (!arguments.length) { - return false; - } + if (!arguments.length) { + return false; + } - return true; + return true; } // good function() { - if (!arguments.length) { - return false; - } + if (!arguments.length) { + return false; + } - var name = getName(); + var name = getName(); - return true; + return true; } ``` @@ -468,7 +468,7 @@ // we know this wouldn't work (assuming there // is no notDefined global variable) function example() { - console.log(notDefined); // => throws a ReferenceError + console.log(notDefined); // => throws a ReferenceError } // creating a variable declaration after you @@ -476,17 +476,17 @@ // variable hoisting. Note: the assignment // value of `true` is not hoisted. function example() { - console.log(declaredButNotAssigned); // => undefined - var declaredButNotAssigned = true; + 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; + var declaredButNotAssigned; + console.log(declaredButNotAssigned); // => undefined + declaredButNotAssigned = true; } ``` @@ -494,13 +494,13 @@ ```javascript function example() { - console.log(anonymous); // => undefined + console.log(anonymous); // => undefined - anonymous(); // => TypeError anonymous is not a function + anonymous(); // => TypeError anonymous is not a function - var anonymous = function() { - console.log('anonymous function expression'); - }; + var anonymous = function() { + console.log('anonymous function expression'); + }; } ``` @@ -508,27 +508,27 @@ ```javascript function example() { - console.log(named); // => undefined + console.log(named); // => undefined - named(); // => TypeError named is not a function + named(); // => TypeError named is not a function - superPower(); // => ReferenceError superPower is not defined + superPower(); // => ReferenceError superPower is not defined - var named = function superPower() { - console.log('Flying'); - }; + 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 + console.log(named); // => undefined - named(); // => TypeError named is not a function + named(); // => TypeError named is not a function - var named = function named() { - console.log('named'); - } + var named = function named() { + console.log('named'); + } } ``` @@ -536,11 +536,11 @@ ```javascript function example() { - superPower(); // => Flying + superPower(); // => Flying - function superPower() { - console.log('Flying'); - } + function superPower() { + console.log('Flying'); + } } ``` @@ -564,8 +564,8 @@ ```javascript if ([0]) { - // true - // An array is an object, objects evaluate to true + // true + // An array is an object, objects evaluate to true } ``` @@ -574,22 +574,22 @@ ```javascript // bad if (name !== '') { - // ...stuff... + // ...stuff... } // good if (name) { - // ...stuff... + // ...stuff... } // bad if (collection.length > 0) { - // ...stuff... + // ...stuff... } // good if (collection.length) { - // ...stuff... + // ...stuff... } ``` @@ -605,14 +605,14 @@ ```javascript // bad if (test) - return false; + return false; // good if (test) return false; // good if (test) { - return false; + return false; } // bad @@ -620,7 +620,7 @@ // good function() { - return false; + return false; } ``` @@ -640,9 +640,9 @@ // @return element function make(tag) { - // ...stuff... + // ...stuff... - return element; + return element; } // good @@ -655,9 +655,9 @@ */ function make(tag) { - // ...stuff... + // ...stuff... - return element; + return element; } ``` @@ -673,21 +673,21 @@ // bad function getType() { - console.log('fetching type...'); - // set the default type to 'no type' - var type = this._type || 'no type'; + console.log('fetching type...'); + // set the default type to 'no type' + var type = this._type || 'no type'; - return type; + return type; } // good function getType() { - console.log('fetching type...'); + console.log('fetching type...'); - // set the default type to 'no type' - var type = this._type || 'no type'; + // set the default type to 'no type' + var type = this._type || 'no type'; - return type; + return type; } ``` @@ -698,10 +698,10 @@ ```javascript function Calculator() { - // FIXME: shouldn't use a global here - total = 0; + // FIXME: shouldn't use a global here + total = 0; - return this; + return this; } ``` @@ -710,10 +710,10 @@ ```javascript function Calculator() { - // TODO: total should be configurable by an options param - this.total = 0; + // TODO: total should be configurable by an options param + this.total = 0; - return this; + return this; } ``` @@ -722,12 +722,12 @@ ## Whitespace - - Use soft tabs set to 2 spaces + - Use soft tabs set to 4 spaces ```javascript // bad function() { - ∙∙∙∙var name; + ∙∙var name; } // bad @@ -737,7 +737,7 @@ // good function() { - ∙∙var name; + ∙∙∙∙var name; } ``` @@ -746,24 +746,24 @@ ```javascript // bad function test(){ - console.log('test'); + console.log('test'); } // good function test() { - console.log('test'); + console.log('test'); } // bad dog.set('attr',{ - age: '1 year', - breed: 'Bernese Mountain Dog' + age: '1 year', + breed: 'Bernese Mountain Dog' }); // good dog.set('attr', { - age: '1 year', - breed: 'Bernese Mountain Dog' + age: '1 year', + breed: 'Bernese Mountain Dog' }); ``` @@ -782,14 +782,14 @@ ```javascript // bad (function(global) { - // ...stuff... + // ...stuff... })(this); ``` ```javascript // good (function(global) { - // ...stuff... + // ...stuff... })(this); ``` @@ -802,11 +802,11 @@ // good $('#items') - .find('.selected') - .highlight() - .end() - .find('.open') - .updateCount(); + .find('.selected') + .highlight() + .end() + .find('.open') + .updateCount(); // bad var leds = stage.selectAll('.led').data(data).enter().append('svg:svg').class('led', true) @@ -816,13 +816,13 @@ // good var leds = stage.selectAll('.led') - .data(data) - .enter().append('svg:svg') - .class('led', true) - .attr('width', (radius + margin) * 2) - .append('svg:g') - .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')') - .call(tron.led); + .data(data) + .enter().append('svg:svg') + .class('led', true) + .attr('width', (radius + margin) * 2) + .append('svg:g') + .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')') + .call(tron.led); ``` **[⬆ back to top](#table-of-contents)** @@ -834,8 +834,8 @@ ```javascript // bad var once - , upon - , aTime; + , upon + , aTime; // good var once, @@ -844,18 +844,18 @@ // bad var hero = { - firstName: 'Bob' - , lastName: 'Parr' - , heroName: 'Mr. Incredible' - , superPower: 'strength' + firstName: 'Bob' + , lastName: 'Parr' + , heroName: 'Mr. Incredible' + , superPower: 'strength' }; // good var hero = { - firstName: 'Bob', - lastName: 'Parr', - heroName: 'Mr. Incredible', - superPower: 'strength' + firstName: 'Bob', + lastName: 'Parr', + heroName: 'Mr. Incredible', + superPower: 'strength' }; ``` @@ -866,24 +866,24 @@ ```javascript // bad var hero = { - firstName: 'Kevin', - lastName: 'Flynn', + firstName: 'Kevin', + lastName: 'Flynn', }; var heroes = [ - 'Batman', - 'Superman', + 'Batman', + 'Superman', ]; // good var hero = { - firstName: 'Kevin', - lastName: 'Flynn' + firstName: 'Kevin', + lastName: 'Flynn' }; var heroes = [ - 'Batman', - 'Superman' + 'Batman', + 'Superman' ]; ``` @@ -897,20 +897,20 @@ ```javascript // bad (function() { - var name = 'Skywalker' - return name + var name = 'Skywalker' + return name })() // good (function() { - var name = 'Skywalker'; - return name; + var name = 'Skywalker'; + return name; })(); // good ;(function() { - var name = 'Skywalker'; - return name; + var name = 'Skywalker'; + return name; })(); ``` @@ -1000,12 +1000,12 @@ ```javascript // bad function q() { - // ...stuff... + // ...stuff... } // good function query() { - // ..stuff.. + // ..stuff.. } ``` @@ -1017,14 +1017,14 @@ var this_is_my_object = {}; function c() {}; var u = new user({ - name: 'Bob Parr' + name: 'Bob Parr' }); // good var thisIsMyObject = {}; function thisIsMyFunction() {}; var user = new User({ - name: 'Bob Parr' + name: 'Bob Parr' }); ``` @@ -1033,20 +1033,20 @@ ```javascript // bad function user(options) { - this.name = options.name; + this.name = options.name; } var bad = new user({ - name: 'nope' + name: 'nope' }); // good function User(options) { - this.name = options.name; + this.name = options.name; } var good = new User({ - name: 'yup' + name: 'yup' }); ``` @@ -1066,26 +1066,26 @@ ```javascript // bad function() { - var self = this; - return function() { - console.log(self); - }; + var self = this; + return function() { + console.log(self); + }; } // bad function() { - var that = this; - return function() { - console.log(that); - }; + var that = this; + return function() { + console.log(that); + }; } // good function() { - var _this = this; - return function() { - console.log(_this); - }; + var _this = this; + return function() { + console.log(_this); + }; } ``` @@ -1094,12 +1094,12 @@ ```javascript // bad var log = function(msg) { - console.log(msg); + console.log(msg); }; // good var log = function log(msg) { - console.log(msg); + console.log(msg); }; ``` @@ -1130,12 +1130,12 @@ ```javascript // bad if (!dragon.age()) { - return false; + return false; } // good if (!dragon.hasAge()) { - return false; + return false; } ``` @@ -1143,17 +1143,17 @@ ```javascript function Jedi(options) { - options || (options = {}); - var lightsaber = options.lightsaber || 'blue'; - this.set('lightsaber', lightsaber); + options || (options = {}); + var lightsaber = options.lightsaber || 'blue'; + this.set('lightsaber', lightsaber); } Jedi.prototype.set = function(key, val) { - this[key] = val; + this[key] = val; }; Jedi.prototype.get = function(key) { - return this[key]; + return this[key]; }; ``` @@ -1166,27 +1166,27 @@ ```javascript function Jedi() { - console.log('new jedi'); + console.log('new jedi'); } // bad Jedi.prototype = { - fight: function fight() { - console.log('fighting'); - }, + fight: function fight() { + console.log('fighting'); + }, - block: function block() { - console.log('blocking'); - } + block: function block() { + console.log('blocking'); + } }; // good Jedi.prototype.fight = function fight() { - console.log('fighting'); + console.log('fighting'); }; Jedi.prototype.block = function block() { - console.log('blocking'); + console.log('blocking'); }; ``` @@ -1195,12 +1195,12 @@ ```javascript // bad Jedi.prototype.jump = function() { - this.jumping = true; - return true; + this.jumping = true; + return true; }; Jedi.prototype.setHeight = function(height) { - this.height = height; + this.height = height; }; var luke = new Jedi(); @@ -1209,19 +1209,19 @@ // good Jedi.prototype.jump = function() { - this.jumping = true; - return this; + this.jumping = true; + return this; }; Jedi.prototype.setHeight = function(height) { - this.height = height; - return this; + this.height = height; + return this; }; var luke = new Jedi(); luke.jump() - .setHeight(20); + .setHeight(20); ``` @@ -1229,16 +1229,16 @@ ```javascript function Jedi(options) { - options || (options = {}); - this.name = options.name || 'no name'; + options || (options = {}); + this.name = options.name || 'no name'; } Jedi.prototype.getName = function getName() { - return this.name; + return this.name; }; Jedi.prototype.toString = function toString() { - return 'Jedi - ' + this.getName(); + return 'Jedi - ' + this.getName(); }; ``` @@ -1256,7 +1256,7 @@ ... $(this).on('listingUpdated', function(e, listingId) { - // do something with listingId + // do something with listingId }); ``` @@ -1264,12 +1264,14 @@ ```js // good - $(this).trigger('listingUpdated', { listingId : listing.id }); + $(this).trigger('listingUpdated', { + 'listingId': listing.id + }); ... $(this).on('listingUpdated', function(e, data) { - // do something with data.listingId + // do something with data.listingId }); ``` @@ -1287,20 +1289,20 @@ // fancyInput/fancyInput.js !function(global) { - 'use strict'; + 'use strict'; - var previousFancyInput = global.FancyInput; + var previousFancyInput = global.FancyInput; - function FancyInput(options) { - this.options = options || {}; - } + function FancyInput(options) { + this.options = options || {}; + } - FancyInput.noConflict = function noConflict() { - global.FancyInput = previousFancyInput; - return FancyInput; - }; + FancyInput.noConflict = function noConflict() { + global.FancyInput = previousFancyInput; + return FancyInput; + }; - global.FancyInput = FancyInput; + global.FancyInput = FancyInput; }(this); ``` @@ -1324,25 +1326,25 @@ ```javascript // bad function setSidebar() { - $('.sidebar').hide(); + $('.sidebar').hide(); - // ...stuff... + // ...stuff... - $('.sidebar').css({ - 'background-color': 'pink' - }); + $('.sidebar').css({ + 'background-color': 'pink' + }); } // good function setSidebar() { - var $sidebar = $('.sidebar'); - $sidebar.hide(); + var $sidebar = $('.sidebar'); + $sidebar.hide(); - // ...stuff... + // ...stuff... - $sidebar.css({ - 'background-color': 'pink' - }); + $sidebar.css({ + 'background-color': 'pink' + }); } ``` @@ -1382,7 +1384,7 @@ ```javascript function() { - return true; + return true; } ``` From 6361b5d3ca9ea1882fa4cc96451b67a2551d98fa Mon Sep 17 00:00:00 2001 From: Wendall Cada Date: Thu, 10 Apr 2014 09:01:24 -0700 Subject: [PATCH 2/2] Updated linters with new whitespace rules. --- .../SublimeLinter.sublime-settings | 4 +- linters/jshintrc | 78 +++++++++---------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/linters/SublimeLinter/SublimeLinter.sublime-settings b/linters/SublimeLinter/SublimeLinter.sublime-settings index 12360f3f1c..0652de4a7b 100644 --- a/linters/SublimeLinter/SublimeLinter.sublime-settings +++ b/linters/SublimeLinter/SublimeLinter.sublime-settings @@ -43,8 +43,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, diff --git a/linters/jshintrc b/linters/jshintrc index d3b47148a8..1f38dfaea8 100644 --- a/linters/jshintrc +++ b/linters/jshintrc @@ -1,57 +1,57 @@ { - /* - * ENVIRONMENTS - * ================= - */ + /* + * ENVIRONMENTS + * ================= + */ - // Define globals exposed by modern browsers. - "browser": true, + // Define globals exposed by modern browsers. + "browser": true, - // Define globals exposed by jQuery. - "jquery": true, + // Define globals exposed by jQuery. + "jquery": true, - // Define globals exposed by Node.js. - "node": true, + // Define globals exposed by Node.js. + "node": true, - /* - * ENFORCING OPTIONS - * ================= - */ + /* + * ENFORCING OPTIONS + * ================= + */ - // Force all variable names to use either camelCase style or UPPER_CASE - // with underscores. - "camelcase": true, + // 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, + // Prohibit use of == and != in favor of === and !==. + "eqeqeq": true, - // Suppress warnings about == null comparisons. - "eqnull": true, + // 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, + // Prohibit use of a variable before it is defined. + "latedef": true, - // Require capitalized names for constructor functions. - "newcap": true, + // Require capitalized names for constructor functions. + "newcap": true, - // Enforce use of single quotation marks for strings. - "quotmark": "single", + // Enforce use of single quotation marks for strings. + "quotmark": "single", - // Prohibit trailing whitespace. - "trailing": true, + // Prohibit trailing whitespace. + "trailing": true, - // Prohibit use of explicitly undeclared variables. - "undef": true, + // Prohibit use of explicitly undeclared variables. + "undef": true, - // Warn when variables are defined but never used. - "unused": true, + // Warn when variables are defined but never used. + "unused": true, - // Enforce line length to 80 characters - "maxlen": 80, + // Enforce line length to 80 characters + "maxlen": 80, - // Enforce placing 'use strict' at the top function scope - "strict": true + // Enforce placing 'use strict' at the top function scope + "strict": true }