[Pkg-javascript-commits] [backbone] 76/173: Non-controversial ESLint whitespace rules

Jonas Smedegaard dr at jones.dk
Wed Aug 31 07:44:04 UTC 2016


This is an automated email from the git hooks/post-receive script.

js pushed a commit to branch master
in repository backbone.

commit b0a627429057c27a73463b00e65e395b7e3ccc65
Author: Jordan Eldredge <jordan at jordaneldredge.com>
Date:   Tue Dec 15 21:11:40 2015 -0800

    Non-controversial ESLint whitespace rules
    
    In an attempt to bring our ESLint rules closer to those in Underscore, I've
    started by adding some whitespace rules which don't involve any significantly
    opinionated changes.
---
 .eslintrc          |   4 ++
 backbone.js        |  40 +++++++++----------
 test/collection.js |  78 ++++++++++++++++++-------------------
 test/events.js     |  56 +++++++++++++--------------
 test/model.js      | 110 ++++++++++++++++++++++++++---------------------------
 test/router.js     |   6 +--
 6 files changed, 148 insertions(+), 146 deletions(-)

diff --git a/.eslintrc b/.eslintrc
index 378ed32..e5b520f 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -12,6 +12,7 @@
     "comma-spacing": 2,
     "computed-property-spacing": [2, "never"],
     "eol-last": 2,
+    "indent": [2, 2, {"SwitchCase": 1, "VariableDeclarator": 2}],
     "linebreak-style": 2,
     "max-depth": [1, 4],
     "max-params": [1, 5],
@@ -59,9 +60,12 @@
     "no-unneeded-ternary": 2,
     "no-unreachable": 2,
     "no-with": 2,
+    "object-curly-spacing": [2, "never"],
     "quotes": [2, "single", "avoid-escape"],
     "radix": 2,
     "semi": 2,
+    "space-after-keywords": [2, "always"],
+    "space-before-function-paren": [2, {"anonymous": "never", "named": "never"}],
     "space-infix-ops": 2,
     "space-return-throw-case": 2,
     "space-unary-ops": [2, { "words": true, "nonwords": false }],
diff --git a/backbone.js b/backbone.js
index 1909c46..6a0c7f3 100644
--- a/backbone.js
+++ b/backbone.js
@@ -23,7 +23,7 @@
   // Next for Node.js or CommonJS. jQuery may not be needed as a module.
   } else if (typeof exports !== 'undefined') {
     var _ = require('underscore'), $;
-    try { $ = require('jquery'); } catch(e) {}
+    try { $ = require('jquery'); } catch (e) {}
     factory(root, exports, _, $);
 
   // Finally, as a browser global.
@@ -166,9 +166,9 @@
   // Guard the `listening` argument from the public API.
   var internalOn = function(obj, name, callback, context, listening) {
     obj._events = eventsApi(onApi, obj._events || {}, name, callback, {
-        context: context,
-        ctx: obj,
-        listening: listening
+      context: context,
+      ctx: obj,
+      listening: listening
     });
 
     if (listening) {
@@ -182,7 +182,7 @@
   // Inversion-of-control versions of `on`. Tell *this* object to listen to
   // an event in another object... keeping track of what it's listening to
   // for easier unbinding later.
-  Events.listenTo =  function(obj, name, callback) {
+  Events.listenTo = function(obj, name, callback) {
     if (!obj) return this;
     var id = obj._listenId || (obj._listenId = _.uniqueId('l'));
     var listeningTo = this._listeningTo || (this._listeningTo = {});
@@ -207,7 +207,7 @@
       var context = options.context, ctx = options.ctx, listening = options.listening;
       if (listening) listening.count++;
 
-      handlers.push({ callback: callback, context: context, ctx: context || ctx, listening: listening });
+      handlers.push({callback: callback, context: context, ctx: context || ctx, listening: listening});
     }
     return events;
   };
@@ -216,18 +216,18 @@
   // callbacks with that function. If `callback` is null, removes all
   // callbacks for the event. If `name` is null, removes all bound
   // callbacks for all events.
-  Events.off =  function(name, callback, context) {
+  Events.off = function(name, callback, context) {
     if (!this._events) return this;
     this._events = eventsApi(offApi, this._events, name, callback, {
-        context: context,
-        listeners: this._listeners
+      context: context,
+      listeners: this._listeners
     });
     return this;
   };
 
   // Tell this object to stop listening to either specific events ... or
   // to every object it's currently listening to.
-  Events.stopListening =  function(obj, name, callback) {
+  Events.stopListening = function(obj, name, callback) {
     var listeningTo = this._listeningTo;
     if (!listeningTo) return this;
 
@@ -306,14 +306,14 @@
   // the callback is invoked, its listener will be removed. If multiple events
   // are passed in using the space-separated syntax, the handler will fire
   // once for each event, not once for a combination of all events.
-  Events.once =  function(name, callback, context) {
+  Events.once = function(name, callback, context) {
     // Map the event into a `{event: once}` object.
     var events = eventsApi(onceMap, {}, name, callback, _.bind(this.off, this));
     return this.on(events, void 0, context);
   };
 
   // Inversion-of-control versions of `once`.
-  Events.listenToOnce =  function(obj, name, callback) {
+  Events.listenToOnce = function(obj, name, callback) {
     // Map the event into a `{event: once}` object.
     var events = eventsApi(onceMap, {}, name, callback, _.bind(this.stopListening, this, obj));
     return this.listenTo(obj, events);
@@ -336,7 +336,7 @@
   // passed the same arguments as `trigger` is, apart from the event name
   // (unless you're listening on `"all"`, which will cause your callback to
   // receive the true name of the event as the first argument).
-  Events.trigger =  function(name) {
+  Events.trigger = function(name) {
     if (!this._events) return this;
 
     var length = Math.max(0, arguments.length - 1);
@@ -732,8 +732,8 @@
 
   // Underscore methods that we want to implement on the Model, mapped to the
   // number of arguments they take.
-  var modelMethods = { keys: 1, values: 1, pairs: 1, invert: 1, pick: 0,
-      omit: 0, chain: 1, isEmpty: 1 };
+  var modelMethods = {keys: 1, values: 1, pairs: 1, invert: 1, pick: 0,
+      omit: 0, chain: 1, isEmpty: 1};
 
   // Mix in each Underscore method as a proxy to `Model#attributes`.
   addUnderscoreMethods(Model, modelMethods, 'attributes');
@@ -1065,7 +1065,7 @@
     },
 
     // Define how to uniquely identify models in the collection.
-    modelId: function (attrs) {
+    modelId: function(attrs) {
       return attrs[this.model.prototype.idAttribute || 'id'];
     },
 
@@ -1122,7 +1122,7 @@
 
     // Method for checking whether an object should be considered a model for
     // the purposes of adding to the collection.
-    _isModel: function (model) {
+    _isModel: function(model) {
       return model instanceof Model;
     },
 
@@ -1168,7 +1168,7 @@
   // Underscore methods that we want to implement on the Collection.
   // 90% of the core usefulness of Backbone Collections is actually implemented
   // right here:
-  var collectionMethods = { forEach: 3, each: 3, map: 3, collect: 3, reduce: 0,
+  var collectionMethods = {forEach: 3, each: 3, map: 3, collect: 3, reduce: 0,
       foldl: 0, inject: 0, reduceRight: 0, foldr: 0, find: 3, detect: 3, filter: 3,
       select: 3, reject: 3, every: 3, all: 3, some: 3, any: 3, include: 3, includes: 3,
       contains: 3, invoke: 0, max: 3, min: 3, toArray: 1, size: 1, first: 3,
@@ -1687,7 +1687,7 @@
       }
 
       // Add a cross-platform `addEventListener` shim for older browsers.
-      var addEventListener = window.addEventListener || function (eventName, listener) {
+      var addEventListener = window.addEventListener || function(eventName, listener) {
         return attachEvent('on' + eventName, listener);
       };
 
@@ -1708,7 +1708,7 @@
     // but possibly useful for unit testing Routers.
     stop: function() {
       // Add a cross-platform `removeEventListener` shim for older browsers.
-      var removeEventListener = window.removeEventListener || function (eventName, listener) {
+      var removeEventListener = window.removeEventListener || function(eventName, listener) {
         return detachEvent('on' + eventName, listener);
       };
 
diff --git a/test/collection.js b/test/collection.js
index c154566..811e8df 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -10,7 +10,7 @@
       c         = new Backbone.Model({id: 1, label: 'c'});
       d         = new Backbone.Model({id: 0, label: 'd'});
       e         = null;
-      col       = new Backbone.Collection([a,b,c,d]);
+      col       = new Backbone.Collection([a, b, c, d]);
       otherCol  = new Backbone.Collection();
     }
 
@@ -115,7 +115,7 @@
     ]);
     var one = col.get(0);
     assert.equal(one.get('name'), 'one');
-    col.on('change:name', function (model) { assert.ok(this.get(model)); });
+    col.on('change:name', function(model) { assert.ok(this.get(model)); });
     one.set({name: 'dalmatians', id : 101});
     assert.equal(col.get(0), null);
     assert.equal(col.get(101).get('name'), 'dalmatians');
@@ -188,7 +188,7 @@
   QUnit.test("add; at should have preference over comparator", function(assert) {
     assert.expect(1);
     var Col = Backbone.Collection.extend({
-      comparator: function(a,b) {
+      comparator: function(a, b) {
         return a.id > b.id ? -1 : 1;
       }
     });
@@ -515,10 +515,10 @@
   QUnit.test("fetch with an error response triggers an error event", function(assert) {
     assert.expect(1);
     var collection = new Backbone.Collection();
-    collection.on('error', function () {
+    collection.on('error', function() {
       assert.ok(true);
     });
-    collection.sync = function (method, model, options) { options.error(); };
+    collection.sync = function(method, model, options) { options.error(); };
     collection.fetch();
   });
 
@@ -532,7 +532,7 @@
         assert.equal(this, obj);
       }
     };
-    collection.sync = function (method, model, options) {
+    collection.sync = function(method, model, options) {
       options.error.call(options.context);
     };
     collection.fetch(options);
@@ -574,7 +574,7 @@
       model: ValidatingModel
     });
     var col = new ValidatingCollection();
-    col.on('invalid', function (collection, error, options) {
+    col.on('invalid', function(collection, error, options) {
       assert.equal(error, "fail");
       assert.equal(options.validationError, 'fail');
     });
@@ -584,7 +584,7 @@
   QUnit.test("create will pass extra options to success callback", function(assert) {
     assert.expect(1);
     var Model = Backbone.Model.extend({
-      sync: function (method, model, options) {
+      sync: function(method, model, options) {
         _.extend(options, {specialSync: true});
         return Backbone.Model.prototype.sync.call(this, method, model, options);
       }
@@ -597,7 +597,7 @@
 
     var collection = new Collection;
 
-    var success = function (model, response, options) {
+    var success = function(model, response, options) {
       assert.ok(options.specialSync, "Options were passed correctly to callback");
     };
 
@@ -609,7 +609,7 @@
     assert.expect(0);
     var Collection = Backbone.Collection.extend({
       url: '/test',
-      parse: function () {
+      parse: function() {
         assert.ok(false);
       }
     });
@@ -772,7 +772,7 @@
     assert.equal(resetCount, 6);
   });
 
-  QUnit.test ("reset with different values", function(assert) {
+  QUnit.test("reset with different values", function(assert) {
     var col = new Backbone.Collection({id: 1});
     col.reset({id: 1, a: 1});
     assert.equal(col.get(1).get('a'), 1);
@@ -792,8 +792,8 @@
         this.model_parameter = options.model_parameter;
       }
     });
-    var col = new (Backbone.Collection.extend({ model: Model }))();
-    col.reset([{ astring: "green", anumber: 1 }, { astring: "blue", anumber: 2 }], { model_parameter: 'model parameter' });
+    var col = new (Backbone.Collection.extend({model: Model}))();
+    col.reset([{astring: "green", anumber: 1}, {astring: "blue", anumber: 2}], {model_parameter: 'model parameter'});
     assert.equal(col.length, 2);
     col.each(function(model) {
       assert.equal(model.model_parameter, 'model parameter');
@@ -1212,8 +1212,8 @@
 
   QUnit.test("set with only idAttribute", function(assert) {
     assert.expect(3);
-    var m1 = { _id: 1 };
-    var m2 = { _id: 2 };
+    var m1 = {_id: 1};
+    var m2 = {_id: 2};
     var col = Backbone.Collection.extend({
       model: Backbone.Model.extend({
         idAttribute: '_id'
@@ -1248,7 +1248,7 @@
 
   QUnit.test('merge without mutation', function(assert) {
     var Model = Backbone.Model.extend({
-      initialize: function (attrs, options) {
+      initialize: function(attrs, options) {
         if (attrs.child) {
           this.set('child', new Model(attrs.child, options), options);
         }
@@ -1268,7 +1268,7 @@
     var Model = Backbone.Model.extend({});
     var Collection = Backbone.Collection.extend({
       model: Model,
-      parse: function (res) { return _.map(res.models, 'model'); }
+      parse: function(res) { return _.map(res.models, 'model'); }
     });
     var model = new Model({id: 1});
     var collection = new Collection(model);
@@ -1282,7 +1282,7 @@
   QUnit.test("`set` data is only parsed once", function(assert) {
     var collection = new Backbone.Collection();
     collection.model = Backbone.Model.extend({
-      parse: function (data) {
+      parse: function(data) {
         assert.equal(data.parsed, void 0);
         data.parsed = true;
         return data;
@@ -1347,7 +1347,7 @@
 
   QUnit.test("#1915 - `parse` data in the right order in `set`", function(assert) {
     var collection = new (Backbone.Collection.extend({
-      parse: function (data) {
+      parse: function(data) {
         assert.strictEqual(data.status, 'ok');
         return data.data;
       }
@@ -1361,18 +1361,18 @@
     assert.expect(1);
     var collection = new (Backbone.Collection.extend({
       url: '/',
-      parse: function (data, options) {
+      parse: function(data, options) {
         assert.strictEqual(options.xhr.someHeader, 'headerValue');
         return data;
       }
     }));
     var ajax = Backbone.ajax;
-    Backbone.ajax = function (params) {
+    Backbone.ajax = function(params) {
       _.defer(params.success, []);
       return {someHeader: 'headerValue'};
     };
     collection.fetch({
-      success: function () { done(); }
+      success: function() { done(); }
     });
     Backbone.ajax = ajax;
   });
@@ -1381,19 +1381,19 @@
     assert.expect(1);
     var SpecialSyncCollection = Backbone.Collection.extend({
       url: '/test',
-      sync: function (method, collection, options) {
-        _.extend(options, { specialSync: true });
+      sync: function(method, collection, options) {
+        _.extend(options, {specialSync: true});
         return Backbone.Collection.prototype.sync.call(this, method, collection, options);
       }
     });
 
     var collection = new SpecialSyncCollection();
 
-    var onSuccess = function (collection, resp, options) {
+    var onSuccess = function(collection, resp, options) {
       assert.ok(options.specialSync, "Options were passed correctly to callback");
     };
 
-    collection.fetch({ success: onSuccess });
+    collection.fetch({success: onSuccess});
     this.ajaxSettings.success();
   });
 
@@ -1402,7 +1402,7 @@
     var collection = new (Backbone.Collection.extend({
       comparator: 'a'
     }))([{id: 1}, {id: 2}, {id: 3}]);
-    collection.on('sort', function () { ok(true); });
+    collection.on('sort', function() { ok(true); });
     collection.add({id: 4}); // do sort, new model
     collection.add({id: 1, a: 1}, {merge: true}); // do sort, comparator change
     collection.add({id: 1, b: 1}, {merge: true}); // don't sort, no comparator change
@@ -1418,7 +1418,7 @@
         return a.get('a') > b.get('a') ? 1 : (a.get('a') < b.get('a') ? -1 : 0);
       }
     }))([{id: 1}, {id: 2}, {id: 3}]);
-    collection.on('sort', function () { ok(true); });
+    collection.on('sort', function() { ok(true); });
     collection.add({id: 4}); // do sort, new model
     collection.add({id: 1, a: 1}, {merge: true}); // do sort, model change
     collection.add({id: 1, b: 1}, {merge: true}); // do sort, model change
@@ -1459,7 +1459,7 @@
 
   QUnit.test("`add` overrides `set` flags", function(assert) {
     var collection = new Backbone.Collection();
-    collection.once('add', function (model, collection, options) {
+    collection.once('add', function(model, collection, options) {
       collection.add({id: 2}, options);
     });
     collection.set({id: 1});
@@ -1533,15 +1533,15 @@
         id: 1,
         name: 'NewSub1',
         subItems: [
-          {id: 1,subName: 'NewOne'},
-          {id: 2,subName: 'NewTwo'}
+          {id: 1, subName: 'NewOne'},
+          {id: 2, subName: 'NewTwo'}
         ]
       }, {
         id: 2,
         name: 'NewSub2',
         subItems: [
-          {id: 3,subName: 'NewThree'},
-          {id: 4,subName: 'NewFour'}
+          {id: 3, subName: 'NewThree'},
+          {id: 4, subName: 'NewFour'}
         ]
       }]
     };
@@ -1638,7 +1638,7 @@
     var A = Backbone.Model.extend();
     var B = Backbone.Model.extend();
     var C = Backbone.Collection.extend({
-      model: function (attrs) {
+      model: function(attrs) {
         return attrs.type === 'a' ? new A(attrs) : new B(attrs);
       }
     });
@@ -1655,7 +1655,7 @@
     var B = Backbone.Model.extend({idAttribute: '_id'});
     var C = Backbone.Collection.extend({
       model: Backbone.Model.extend({
-        constructor: function (attrs) {
+        constructor: function(attrs) {
           return attrs.type === 'a' ? new A(attrs) : new B(attrs);
         },
 
@@ -1670,11 +1670,11 @@
     assert.equal(collection.at(1), collection.get(2));
 
     C = Backbone.Collection.extend({
-      model: function (attrs) {
+      model: function(attrs) {
         return attrs.type === 'a' ? new A(attrs) : new B(attrs);
       },
 
-      modelId: function (attrs) {
+      modelId: function(attrs) {
         return attrs.type + '-' + attrs.id;
       }
     });
@@ -1819,9 +1819,9 @@
 
   QUnit.test('#3871 - falsy parse result creates empty collection', function(assert) {
     var collection = new (Backbone.Collection.extend({
-      parse: function (data, options) {}
+      parse: function(data, options) {}
     }));
-    collection.set('', { parse: true });
+    collection.set('', {parse: true});
     assert.equal(collection.length, 0);
   });
 
diff --git a/test/events.js b/test/events.js
index 07ee7ee..e10e7dd 100644
--- a/test/events.js
+++ b/test/events.js
@@ -4,8 +4,8 @@
 
   QUnit.test("on and trigger", function(assert) {
     assert.expect(2);
-    var obj = { counter: 0 };
-    _.extend(obj,Backbone.Events);
+    var obj = {counter: 0};
+    _.extend(obj, Backbone.Events);
     obj.on('event', function() { obj.counter += 1; });
     obj.trigger('event');
     assert.equal(obj.counter, 1, 'counter should be incremented.');
@@ -18,7 +18,7 @@
 
   QUnit.test("binding and triggering multiple events", function(assert) {
     assert.expect(4);
-    var obj = { counter: 0 };
+    var obj = {counter: 0};
     _.extend(obj, Backbone.Events);
 
     obj.on('a b c', function() { obj.counter += 1; });
@@ -38,7 +38,7 @@
   });
 
   QUnit.test("binding and triggering with event maps", function(assert) {
-    var obj = { counter: 0 };
+    var obj = {counter: 0};
     _.extend(obj, Backbone.Events);
 
     var increment = function() {
@@ -69,7 +69,7 @@
   });
 
   QUnit.test("binding and triggering multiple event names with event maps", function(assert) {
-    var obj = { counter: 0 };
+    var obj = {counter: 0};
     _.extend(obj, Backbone.Events);
 
     var increment = function() {
@@ -98,20 +98,20 @@
 
   QUnit.test("binding and trigger with event maps context", function(assert) {
     assert.expect(2);
-    var obj = { counter: 0 };
+    var obj = {counter: 0};
     var context = {};
     _.extend(obj, Backbone.Events);
 
     obj.on({
-        a: function() {
-            assert.strictEqual(this, context, 'defaults `context` to `callback` param');
-        }
+      a: function() {
+        assert.strictEqual(this, context, 'defaults `context` to `callback` param');
+      }
     }, context).trigger('a');
 
     obj.off().on({
-        a: function() {
-            strictEqual(this, context, 'will not override explicit `context` param');
-        }
+      a: function() {
+        strictEqual(this, context, 'will not override explicit `context` param');
+      }
     }, this, context).trigger('a');
   });
 
@@ -145,7 +145,7 @@
     assert.expect(2);
     var a = _.extend({}, Backbone.Events);
     var b = _.extend({}, Backbone.Events);
-    var cb = function () { assert.ok(true); };
+    var cb = function() { assert.ok(true); };
     a.listenTo(b, 'event', cb);
     b.on('event', cb);
     a.listenTo(b, 'event2', cb);
@@ -161,7 +161,7 @@
   QUnit.test("listenToOnce", function(assert) {
     assert.expect(2);
     // Same as the previous test, but we use once rather than having to explicitly unbind
-    var obj = { counterA: 0, counterB: 0 };
+    var obj = {counterA: 0, counterB: 0};
     _.extend(obj, Backbone.Events);
     var incrA = function(){ obj.counterA += 1; obj.trigger('event'); };
     var incrB = function(){ obj.counterB += 1; };
@@ -348,7 +348,7 @@
 
   QUnit.test("trigger all for each event", function(assert) {
     assert.expect(3);
-    var a, b, obj = { counter: 0 };
+    var a, b, obj = {counter: 0};
     _.extend(obj, Backbone.Events);
     obj.on('all', function(event) {
       obj.counter++;
@@ -363,8 +363,8 @@
 
   QUnit.test("on, then unbind all functions", function(assert) {
     assert.expect(1);
-    var obj = { counter: 0 };
-    _.extend(obj,Backbone.Events);
+    var obj = {counter: 0};
+    _.extend(obj, Backbone.Events);
     var callback = function() { obj.counter += 1; };
     obj.on('event', callback);
     obj.trigger('event');
@@ -375,8 +375,8 @@
 
   QUnit.test("bind two callbacks, unbind only one", function(assert) {
     assert.expect(2);
-    var obj = { counterA: 0, counterB: 0 };
-    _.extend(obj,Backbone.Events);
+    var obj = {counterA: 0, counterB: 0};
+    _.extend(obj, Backbone.Events);
     var callback = function() { obj.counterA += 1; };
     obj.on('event', callback);
     obj.on('event', function() { obj.counterB += 1; });
@@ -404,8 +404,8 @@
 
   QUnit.test("two binds that unbind themeselves", function(assert) {
     assert.expect(2);
-    var obj = { counterA: 0, counterB: 0 };
-    _.extend(obj,Backbone.Events);
+    var obj = {counterA: 0, counterB: 0};
+    _.extend(obj, Backbone.Events);
     var incrA = function(){ obj.counterA += 1; obj.off('event', incrA); };
     var incrB = function(){ obj.counterB += 1; obj.off('event', incrB); };
     obj.on('event', incrA);
@@ -419,21 +419,21 @@
 
   QUnit.test("bind a callback with a supplied context", function(assert) {
     assert.expect(1);
-    var TestClass = function () {
+    var TestClass = function() {
       return this;
     };
-    TestClass.prototype.assertTrue = function () {
+    TestClass.prototype.assertTrue = function() {
       assert.ok(true, '`this` was bound to the callback');
     };
 
-    var obj = _.extend({},Backbone.Events);
-    obj.on('event', function () { this.assertTrue(); }, (new TestClass));
+    var obj = _.extend({}, Backbone.Events);
+    obj.on('event', function() { this.assertTrue(); }, (new TestClass));
     obj.trigger('event');
   });
 
   QUnit.test("nested trigger with unbind", function(assert) {
     assert.expect(1);
-    var obj = { counter: 0 };
+    var obj = {counter: 0};
     _.extend(obj, Backbone.Events);
     var incr1 = function(){ obj.counter += 1; obj.off('event', incr1); obj.trigger('event'); };
     var incr2 = function(){ obj.counter += 1; };
@@ -514,7 +514,7 @@
   QUnit.test("once", function(assert) {
     assert.expect(2);
     // Same as the previous test, but we use once rather than having to explicitly unbind
-    var obj = { counterA: 0, counterB: 0 };
+    var obj = {counterA: 0, counterB: 0};
     _.extend(obj, Backbone.Events);
     var incrA = function(){ obj.counterA += 1; obj.trigger('event'); };
     var incrB = function(){ obj.counterB += 1; };
@@ -561,7 +561,7 @@
   });
 
   QUnit.test("once with event maps", function(assert) {
-    var obj = { counter: 0 };
+    var obj = {counter: 0};
     _.extend(obj, Backbone.Events);
 
     var increment = function() {
diff --git a/test/model.js b/test/model.js
index e095652..a558204 100644
--- a/test/model.js
+++ b/test/model.js
@@ -120,23 +120,23 @@
 
   QUnit.test("underscore methods", function(assert) {
     assert.expect(5);
-    var model = new Backbone.Model({ 'foo': 'a', 'bar': 'b', 'baz': 'c' });
+    var model = new Backbone.Model({'foo': 'a', 'bar': 'b', 'baz': 'c'});
     var model2 = model.clone();
     assert.deepEqual(model.keys(), ['foo', 'bar', 'baz']);
     assert.deepEqual(model.values(), ['a', 'b', 'c']);
-    assert.deepEqual(model.invert(), { 'a': 'foo', 'b': 'bar', 'c': 'baz' });
+    assert.deepEqual(model.invert(), {'a': 'foo', 'b': 'bar', 'c': 'baz'});
     assert.deepEqual(model.pick('foo', 'baz'), {'foo': 'a', 'baz': 'c'});
     assert.deepEqual(model.omit('foo', 'bar'), {'baz': 'c'});
   });
 
   QUnit.test("chain", function(assert) {
-    var model = new Backbone.Model({ a: 0, b: 1, c: 2 });
+    var model = new Backbone.Model({a: 0, b: 1, c: 2});
     assert.deepEqual(model.chain().pick("a", "b", "c").values().compact().value(), [1, 2]);
   });
 
   QUnit.test("clone", function(assert) {
     assert.expect(10);
-    var a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3});
+    var a = new Backbone.Model({'foo': 1, 'bar': 2, 'baz': 3});
     var b = a.clone();
     assert.equal(a.get('foo'), 1);
     assert.equal(a.get('bar'), 2);
@@ -157,15 +157,15 @@
 
   QUnit.test("isNew", function(assert) {
     assert.expect(6);
-    var a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3});
+    var a = new Backbone.Model({'foo': 1, 'bar': 2, 'baz': 3});
     assert.ok(a.isNew(), "it should be new");
-    a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3, 'id': -5 });
+    a = new Backbone.Model({'foo': 1, 'bar': 2, 'baz': 3, 'id': -5});
     assert.ok(!a.isNew(), "any defined ID is legal, negative or positive");
-    a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3, 'id': 0 });
+    a = new Backbone.Model({'foo': 1, 'bar': 2, 'baz': 3, 'id': 0});
     assert.ok(!a.isNew(), "any defined ID is legal, including zero");
     assert.ok( new Backbone.Model({          }).isNew(), "is true when there is no id");
-    assert.ok(!new Backbone.Model({ 'id': 2  }).isNew(), "is false for a positive integer");
-    assert.ok(!new Backbone.Model({ 'id': -5 }).isNew(), "is false for a negative integer");
+    assert.ok(!new Backbone.Model({'id': 2}).isNew(), "is false for a positive integer");
+    assert.ok(!new Backbone.Model({'id': -5}).isNew(), "is false for a negative integer");
   });
 
   QUnit.test("get", function(assert) {
@@ -273,7 +273,7 @@
   QUnit.test("#2030 - set with failed validate, followed by another set triggers change", function(assert) {
     var attr = 0, main = 0, error = 0;
     var Model = Backbone.Model.extend({
-      validate: function (attr) {
+      validate: function(attr) {
         if (attr.x > 1) {
           error++;
           return "this is an error";
@@ -281,8 +281,8 @@
       }
     });
     var model = new Model({x:0});
-    model.on('change:x', function () { attr++; });
-    model.on('change', function () { main++; });
+    model.on('change:x', function() { attr++; });
+    model.on('change', function() { main++; });
     model.set({x:2}, {validate:true});
     model.set({x:1}, {validate:true});
     assert.deepEqual([attr, main, error], [1, 1, 1]);
@@ -318,14 +318,14 @@
     var o3 = {};
     model.on('change', function(__, options) {
       switch (model.get('a')) {
-      case 1:
-        assert.equal(options, o1);
-        return model.set('a', 2, o2);
-      case 2:
-        assert.equal(options, o2);
-        return model.set('a', 3, o3);
-      case 3:
-        assert.equal(options, o3);
+        case 1:
+          assert.equal(options, o1);
+          return model.set('a', 2, o2);
+        case 2:
+          assert.equal(options, o2);
+          return model.set('a', 3, o3);
+        case 3:
+          assert.equal(options, o3);
       }
     });
     model.set('a', 1, o1);
@@ -400,16 +400,16 @@
   QUnit.test("setting an object", function(assert) {
     assert.expect(1);
     var model = new Backbone.Model({
-      custom: { foo: 1 }
+      custom: {foo: 1}
     });
     model.on('change', function() {
       assert.ok(1);
     });
     model.set({
-      custom: { foo: 1 } // no change should be fired
+      custom: {foo: 1} // no change should be fired
     });
     model.set({
-      custom: { foo: 2 } // change event should be fired
+      custom: {foo: 2} // change event should be fired
     });
   });
 
@@ -504,7 +504,7 @@
     var env = this;
     var model = new Backbone.Model({firstName : "Taylor", lastName: "Swift"});
     model.url = '/test';
-    model.on('change', function () {
+    model.on('change', function() {
       model.save();
       assert.ok(_.isEqual(env.syncArgs.model, model));
     });
@@ -539,10 +539,10 @@
   QUnit.test("save, fetch, destroy triggers error event when an error occurs", function(assert) {
     assert.expect(3);
     var model = new Backbone.Model();
-    model.on('error', function () {
+    model.on('error', function() {
       assert.ok(true);
     });
-    model.sync = function (method, model, options) {
+    model.sync = function(method, model, options) {
       options.error();
     };
     model.save({data: 2, id: 1});
@@ -560,7 +560,7 @@
         assert.equal(this, obj);
       }
     };
-    model.sync = function (method, model, options) {
+    model.sync = function(method, model, options) {
       options.success.call(options.context);
     };
     model.save({data: 2, id: 1}, options);
@@ -578,7 +578,7 @@
         assert.equal(this, obj);
       }
     };
-    model.sync = function (method, model, options) {
+    model.sync = function(method, model, options) {
       options.error.call(options.context);
     };
     model.save({data: 2, id: 1}, options);
@@ -642,7 +642,7 @@
       options.success(null, options);
     };
     model.save({testing:'empty'}, {
-      success: function (model) {
+      success: function(model) {
         assert.deepEqual(model.attributes, {testing:'empty'});
       }
     });
@@ -660,8 +660,8 @@
   QUnit.test("save will pass extra options to success callback", function(assert) {
     assert.expect(1);
     var SpecialSyncModel = Backbone.Model.extend({
-      sync: function (method, model, options) {
-        _.extend(options, { specialSync: true });
+      sync: function(method, model, options) {
+        _.extend(options, {specialSync: true});
         return Backbone.Model.prototype.sync.call(this, method, model, options);
       },
       urlRoot: '/test'
@@ -669,11 +669,11 @@
 
     var model = new SpecialSyncModel();
 
-    var onSuccess = function (model, response, options) {
+    var onSuccess = function(model, response, options) {
       assert.ok(options.specialSync, "Options were passed correctly to callback");
     };
 
-    model.save(null, { success: onSuccess });
+    model.save(null, {success: onSuccess});
     this.ajaxSettings.success();
   });
 
@@ -687,8 +687,8 @@
   QUnit.test("fetch will pass extra options to success callback", function(assert) {
     assert.expect(1);
     var SpecialSyncModel = Backbone.Model.extend({
-      sync: function (method, model, options) {
-        _.extend(options, { specialSync: true });
+      sync: function(method, model, options) {
+        _.extend(options, {specialSync: true});
         return Backbone.Model.prototype.sync.call(this, method, model, options);
       },
       urlRoot: '/test'
@@ -696,11 +696,11 @@
 
     var model = new SpecialSyncModel();
 
-    var onSuccess = function (model, response, options) {
+    var onSuccess = function(model, response, options) {
       assert.ok(options.specialSync, "Options were passed correctly to callback");
     };
 
-    model.fetch({ success: onSuccess });
+    model.fetch({success: onSuccess});
     this.ajaxSettings.success();
   });
 
@@ -717,26 +717,26 @@
   QUnit.test("destroy will pass extra options to success callback", function(assert) {
     assert.expect(1);
     var SpecialSyncModel = Backbone.Model.extend({
-      sync: function (method, model, options) {
-        _.extend(options, { specialSync: true });
+      sync: function(method, model, options) {
+        _.extend(options, {specialSync: true});
         return Backbone.Model.prototype.sync.call(this, method, model, options);
       },
       urlRoot: '/test'
     });
 
-    var model = new SpecialSyncModel({ id: 'id' });
+    var model = new SpecialSyncModel({id: 'id'});
 
-    var onSuccess = function (model, response, options) {
+    var onSuccess = function(model, response, options) {
       assert.ok(options.specialSync, "Options were passed correctly to callback");
     };
 
-    model.destroy({ success: onSuccess });
+    model.destroy({success: onSuccess});
     this.ajaxSettings.success();
   });
 
   QUnit.test("non-persisted destroy", function(assert) {
     assert.expect(1);
-    var a = new Backbone.Model({ 'foo': 1, 'bar': 2, 'baz': 3});
+    var a = new Backbone.Model({'foo': 1, 'bar': 2, 'baz': 3});
     a.sync = function() { throw "should not be called"; };
     a.destroy();
     assert.ok(true, "non-persisted model should not call sync");
@@ -965,7 +965,7 @@
 
   QUnit.test("save without `wait` doesn't set invalid attributes", function(assert) {
     var model = new Backbone.Model();
-    model.validate = function () { return 1; };
+    model.validate = function() { return 1; };
     model.save({a: 1});
     assert.equal(model.get('a'), void 0);
   });
@@ -973,8 +973,8 @@
   QUnit.test("save doesn't validate twice", function(assert) {
     var model = new Backbone.Model();
     var times = 0;
-    model.sync = function () {};
-    model.validate = function () { ++times; };
+    model.sync = function() {};
+    model.validate = function() { ++times; };
     model.save({});
     assert.equal(times, 1);
   });
@@ -1076,7 +1076,7 @@
     var count = 0;
     var model = new Backbone.Model();
     model.on('change', function() {
-      switch(count++) {
+      switch (count++) {
         case 0:
           assert.deepEqual(this.changedAttributes(), {x: true});
           assert.equal(model.previous('x'), undefined);
@@ -1104,7 +1104,7 @@
     var model = new Backbone.Model();
     model.on('change:y', function() { assert.ok(false); });
     model.on('change', function() {
-      switch(count++) {
+      switch (count++) {
         case 0:
           assert.deepEqual(this.changedAttributes(), {x: true});
           model.set({y: true}, {silent: true});
@@ -1217,7 +1217,7 @@
   QUnit.test("#1412 - Trigger 'sync' event.", function(assert) {
     assert.expect(3);
     var model = new Backbone.Model({id: 1});
-    model.sync = function (method, model, options) { options.success(); };
+    model.sync = function(method, model, options) { options.success(); };
     model.on('sync', function(){ assert.ok(true); });
     model.fetch();
     model.save();
@@ -1230,7 +1230,7 @@
     new Backbone.Model()
     .on('sync', function() { assert.ok(false); })
     .on('destroy', function(){ assert.ok(true); })
-    .destroy({ success: function(){
+    .destroy({success: function(){
       assert.ok(true);
       done();
     }});
@@ -1258,7 +1258,7 @@
 
   QUnit.test("#1545 - `undefined` can be passed to a model constructor without coersion", function(assert) {
     var Model = Backbone.Model.extend({
-      defaults: { one: 1 },
+      defaults: {one: 1},
       initialize : function(attrs, opts) {
         assert.equal(attrs, undefined);
       }
@@ -1287,8 +1287,8 @@
     assert.expect(1);
     var model = new Backbone.Model({x:1});
     model.on('change:x', function() { assert.ok(true); });
-    model.set({x:2},{silent:true});
-    model.set({x:3},{silent:true});
+    model.set({x:2}, {silent:true});
+    model.set({x:3}, {silent:true});
     model.set({x:1});
   });
 
@@ -1303,7 +1303,7 @@
     });
     model.on('change:a change:b change:c', function(model, val) { changes.push(val); });
     model.set({a:'a', b:1, c:'item'});
-    assert.deepEqual(changes, ['a',1,'item']);
+    assert.deepEqual(changes, ['a', 1, 'item']);
     assert.deepEqual(model.attributes, {a: 'c', b: 2});
   });
 
@@ -1369,7 +1369,7 @@
 
   QUnit.test("#1961 - Creating a model with {validate:true} will call validate and use the error callback", function(assert) {
     var Model = Backbone.Model.extend({
-      validate: function (attrs) {
+      validate: function(attrs) {
         if (attrs.id === 1) return "This shouldn't happen";
       }
     });
diff --git a/test/router.js b/test/router.js
index 891d1e8..aab7a41 100644
--- a/test/router.js
+++ b/test/router.js
@@ -237,7 +237,7 @@
   QUnit.test("route precedence via navigate", function(assert){
     assert.expect(6);
     // check both 0.9.x and backwards-compatibility options
-    _.each([ { trigger: true }, true ], function( options ){
+    _.each([{trigger: true}, true], function( options ){
       Backbone.history.navigate('contacts', options);
       assert.equal(router.contact, 'index');
       Backbone.history.navigate('contacts/new', options);
@@ -694,9 +694,7 @@
     var RouterExtended = RouterBase.extend({
       routes: function() {
         var _super = RouterExtended.__super__.routes;
-        return _.extend(_super(),
-          { show:   "show",
-            search: "search" });
+        return _.extend(_super(), {show: "show", search: "search"});
       }
     });
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list