[Pkg-javascript-commits] [backbone] 78/173: Add ESLint rule: key-spacing
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 07:44:05 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 2ae117a7cbf1a764dec1c46eb2892a6b31327b29
Author: Jordan Eldredge <jordan at jordaneldredge.com>
Date: Tue Dec 15 21:30:58 2015 -0800
Add ESLint rule: key-spacing
---
.eslintrc | 1 +
backbone.js | 4 +--
test/collection.js | 54 +++++++++++++++++------------------
test/model.js | 82 +++++++++++++++++++++++++++---------------------------
test/router.js | 40 +++++++++++++-------------
test/sync.js | 10 +++----
test/view.js | 6 ++--
7 files changed, 99 insertions(+), 98 deletions(-)
diff --git a/.eslintrc b/.eslintrc
index e5b520f..b92ad55 100644
--- a/.eslintrc
+++ b/.eslintrc
@@ -13,6 +13,7 @@
"computed-property-spacing": [2, "never"],
"eol-last": 2,
"indent": [2, 2, {"SwitchCase": 1, "VariableDeclarator": 2}],
+ "key-spacing": 1,
"linebreak-style": 2,
"max-depth": [1, 4],
"max-params": [1, 5],
diff --git a/backbone.js b/backbone.js
index 6a0c7f3..d5e82e7 100644
--- a/backbone.js
+++ b/backbone.js
@@ -1425,9 +1425,9 @@
var methodMap = {
'create': 'POST',
'update': 'PUT',
- 'patch': 'PATCH',
+ 'patch': 'PATCH',
'delete': 'DELETE',
- 'read': 'GET'
+ 'read': 'GET'
};
// Set the default implementation of `Backbone.ajax` to proxy through to `$`.
diff --git a/test/collection.js b/test/collection.js
index 811e8df..7c6a1dd 100644
--- a/test/collection.js
+++ b/test/collection.js
@@ -47,7 +47,7 @@
QUnit.test("new and parse", function(assert) {
assert.expect(3);
var Collection = Backbone.Collection.extend({
- parse : function(data) {
+ parse: function(data) {
return _.filter(data, function(datum) {
return datum.a % 2 === 0;
});
@@ -110,13 +110,13 @@
assert.expect(4);
var col = new Backbone.Collection();
col.add([
- {id : 0, name : 'one'},
- {id : 1, name : 'two'}
+ {id: 0, name: 'one'},
+ {id: 1, name: 'two'}
]);
var one = col.get(0);
assert.equal(one.get('name'), 'one');
col.on('change:name', function(model) { assert.ok(this.get(model)); });
- one.set({name: 'dalmatians', id : 101});
+ one.set({name: 'dalmatians', id: 101});
assert.equal(col.get(0), null);
assert.equal(col.get(101).get('name'), 'dalmatians');
});
@@ -136,7 +136,7 @@
assert.expect(14);
var added, opts, secondAdded;
added = opts = secondAdded = null;
- e = new Backbone.Model({id: 10, label : 'e'});
+ e = new Backbone.Model({id: 10, label: 'e'});
otherCol.add(e);
otherCol.on('add', function() {
secondAdded = true;
@@ -153,9 +153,9 @@
assert.equal(secondAdded, null);
assert.ok(opts.amazing);
- var f = new Backbone.Model({id: 20, label : 'f'});
- var g = new Backbone.Model({id: 21, label : 'g'});
- var h = new Backbone.Model({id: 22, label : 'h'});
+ var f = new Backbone.Model({id: 20, label: 'f'});
+ var g = new Backbone.Model({id: 21, label: 'g'});
+ var h = new Backbone.Model({id: 22, label: 'h'});
var atCol = new Backbone.Collection([f, g, h]);
assert.equal(atCol.length, 3);
atCol.add(e, {at: 1});
@@ -194,7 +194,7 @@
});
var col = new Col([{id: 2}, {id: 3}]);
- col.add(new Backbone.Model({id: 1}), {at: 1});
+ col.add(new Backbone.Model({id: 1}), {at: 1});
assert.equal(col.pluck('id').join(' '), '3 1 2');
});
@@ -202,7 +202,7 @@
QUnit.test("add; at should add to the end if the index is out of bounds", function(assert) {
assert.expect(1);
var col = new Backbone.Collection([{id: 2}, {id: 3}]);
- col.add(new Backbone.Model({id: 1}), {at: 5});
+ col.add(new Backbone.Model({id: 1}), {at: 5});
assert.equal(col.pluck('id').join(' '), '2 3 1');
});
@@ -235,7 +235,7 @@
QUnit.test("add model to multiple collections", function(assert) {
assert.expect(10);
var counter = 0;
- var e = new Backbone.Model({id: 10, label : 'e'});
+ var e = new Backbone.Model({id: 10, label: 'e'});
e.on('add', function(model, collection) {
counter++;
assert.equal(e, model);
@@ -407,19 +407,19 @@
var dj = new Backbone.Model();
var emcees = new Backbone.Collection([dj]);
emcees.on('change', function(){ counter++; });
- dj.set({name : 'Kool'});
+ dj.set({name: 'Kool'});
assert.equal(counter, 1);
emcees.reset([]);
assert.equal(dj.collection, undefined);
- dj.set({name : 'Shadow'});
+ dj.set({name: 'Shadow'});
assert.equal(counter, 1);
});
QUnit.test("remove in multiple collections", function(assert) {
assert.expect(7);
var modelData = {
- id : 5,
- title : 'Othello'
+ id: 5,
+ title: 'Othello'
};
var passed = false;
var e = new Backbone.Model(modelData);
@@ -578,7 +578,7 @@
assert.equal(error, "fail");
assert.equal(options.validationError, 'fail');
});
- assert.equal(col.create({"foo":"bar"}, {validate:true}), false);
+ assert.equal(col.create({"foo": "bar"}, {validate: true}), false);
});
QUnit.test("create will pass extra options to success callback", function(assert) {
@@ -630,7 +630,7 @@
model: ValidatingModel
});
var col = new ValidatingCollection();
- var m = col.create({"foo":"bar"});
+ var m = col.create({"foo": "bar"});
assert.equal(m.validationError, 'fail');
assert.equal(col.length, 1);
});
@@ -762,7 +762,7 @@
assert.equal(col.length, 0);
assert.equal(resetCount, 4);
- var f = new Backbone.Model({id: 20, label : 'f'});
+ var f = new Backbone.Model({id: 20, label: 'f'});
col.reset([undefined, f]);
assert.equal(col.length, 2);
assert.equal(resetCount, 5);
@@ -802,7 +802,7 @@
QUnit.test("reset does not alter options by reference", function(assert) {
assert.expect(2);
- var col = new Backbone.Collection([{id:1}]);
+ var col = new Backbone.Collection([{id: 1}]);
var origOpts = {};
col.on("reset", function(col, opts){
assert.equal(origOpts.previousModels, undefined);
@@ -868,7 +868,7 @@
var collection = new Collection;
collection.on("invalid", function() { assert.ok(true); });
- collection.add([{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, {id: 6}], {validate:true});
+ collection.add([{id: 1}, {id: 2}, {id: 3}, {id: 4}, {id: 5}, {id: 6}], {validate: true});
assert.deepEqual(collection.pluck("id"), [1, 2, 4, 5, 6]);
});
@@ -880,7 +880,7 @@
validate: function(attrs){ if (!attrs.valid) return 'invalid'; }
});
var model = new collection.model({id: 1, valid: true});
- collection.add([model, {id: 2}], {validate:true});
+ collection.add([model, {id: 2}], {validate: true});
model.trigger('test');
assert.ok(collection.get(model.cid));
assert.ok(collection.get(1));
@@ -942,7 +942,7 @@
QUnit.test("#1355 - `options` is passed to success callbacks", function(assert) {
assert.expect(2);
- var m = new Backbone.Model({x:1});
+ var m = new Backbone.Model({x: 1});
var col = new Backbone.Collection();
var opts = {
opts: true,
@@ -1091,7 +1091,7 @@
QUnit.test("#1407 parse option on constructor parses collection and models", function(assert) {
assert.expect(2);
var model = {
- namespace : [{id: 1}, {id:2}]
+ namespace: [{id: 1}, {id: 2}]
};
var Collection = Backbone.Collection.extend({
model: Backbone.Model.extend({
@@ -1104,7 +1104,7 @@
return model.namespace;
}
});
- var c = new Collection(model, {parse:true});
+ var c = new Collection(model, {parse: true});
assert.equal(c.length, 2);
assert.equal(c.at(0).get('name'), 'test');
@@ -1113,7 +1113,7 @@
QUnit.test("#1407 parse option on reset parses collection and models", function(assert) {
assert.expect(2);
var model = {
- namespace : [{id: 1}, {id:2}]
+ namespace: [{id: 1}, {id: 2}]
};
var Collection = Backbone.Collection.extend({
model: Backbone.Model.extend({
@@ -1127,7 +1127,7 @@
}
});
var c = new Collection();
- c.reset(model, {parse:true});
+ c.reset(model, {parse: true});
assert.equal(c.length, 2);
assert.equal(c.at(0).get('name'), 'test');
@@ -1352,7 +1352,7 @@
return data.data;
}
}));
- var res = {status: 'ok', data:[{id: 1}]};
+ var res = {status: 'ok', data: [{id: 1}]};
collection.set(res, {parse: true});
});
diff --git a/test/model.js b/test/model.js
index a558204..47a93a6 100644
--- a/test/model.js
+++ b/test/model.js
@@ -2,7 +2,7 @@
var proxy = Backbone.Model.extend();
var klass = Backbone.Collection.extend({
- url : function() { return '/collection'; }
+ url: function() { return '/collection'; }
});
var doc, collection;
@@ -10,10 +10,10 @@
beforeEach: function(assert) {
doc = new proxy({
- id : '1-the-tempest',
- title : "The Tempest",
- author : "Bill Shakespeare",
- length : 123
+ id: '1-the-tempest',
+ title: "The Tempest",
+ author: "Bill Shakespeare",
+ length: 123
});
collection = new klass();
collection.add(doc);
@@ -144,7 +144,7 @@
assert.equal(b.get('foo'), a.get('foo'), "Foo should be the same on the clone.");
assert.equal(b.get('bar'), a.get('bar'), "Bar should be the same on the clone.");
assert.equal(b.get('baz'), a.get('baz'), "Baz should be the same on the clone.");
- a.set({foo : 100});
+ a.set({foo: 100});
assert.equal(a.get('foo'), 100);
assert.equal(b.get('foo'), 1, "Changing a parent attribute does not change the clone.");
@@ -280,11 +280,11 @@
}
}
});
- var model = new Model({x:0});
+ var model = new Model({x: 0});
model.on('change:x', function() { attr++; });
model.on('change', function() { main++; });
- model.set({x:2}, {validate:true});
- model.set({x:1}, {validate:true});
+ model.set({x: 2}, {validate: true});
+ model.set({x: 1}, {validate: true});
assert.deepEqual([attr, main, error], [1, 1, 1]);
});
@@ -354,7 +354,7 @@
QUnit.test("using a non-default id attribute.", function(assert) {
assert.expect(5);
- var MongoModel = Backbone.Model.extend({idAttribute : '_id'});
+ var MongoModel = Backbone.Model.extend({idAttribute: '_id'});
var model = new MongoModel({id: 'eye-dee', _id: 25, title: 'Model'});
assert.equal(model.get('id'), 'eye-dee');
assert.equal(model.id, 25);
@@ -392,8 +392,8 @@
QUnit.test("set an empty string", function(assert) {
assert.expect(1);
- var model = new Backbone.Model({name : "Model"});
- model.set({name : ''});
+ var model = new Backbone.Model({name: "Model"});
+ model.set({name: ''});
assert.equal(model.get('name'), '');
});
@@ -416,7 +416,7 @@
QUnit.test("clear", function(assert) {
assert.expect(3);
var changed;
- var model = new Backbone.Model({id: 1, name : "Model"});
+ var model = new Backbone.Model({id: 1, name: "Model"});
model.on("change:name", function(){ changed = true; });
model.on("change", function() {
var changedAttrs = model.changedAttributes();
@@ -458,13 +458,13 @@
model.on('change', function() {
assert.ok(model.hasChanged('name'), 'name changed');
assert.ok(!model.hasChanged('age'), 'age did not');
- assert.ok(_.isEqual(model.changedAttributes(), {name : 'Rob'}), 'changedAttributes returns the changed attrs');
+ assert.ok(_.isEqual(model.changedAttributes(), {name: 'Rob'}), 'changedAttributes returns the changed attrs');
assert.equal(model.previous('name'), 'Tim');
- assert.ok(_.isEqual(model.previousAttributes(), {name : "Tim", age : 10}), 'previousAttributes is correct');
+ assert.ok(_.isEqual(model.previousAttributes(), {name: "Tim", age: 10}), 'previousAttributes is correct');
});
assert.equal(model.hasChanged(), false);
assert.equal(model.hasChanged(undefined), false);
- model.set({name : 'Rob'});
+ model.set({name: 'Rob'});
assert.equal(model.get('name'), 'Rob');
});
@@ -502,7 +502,7 @@
QUnit.test("save within change event", function(assert) {
assert.expect(1);
var env = this;
- var model = new Backbone.Model({firstName : "Taylor", lastName: "Swift"});
+ var model = new Backbone.Model({firstName: "Taylor", lastName: "Swift"});
model.url = '/test';
model.on('change', function() {
model.save();
@@ -531,7 +531,7 @@
QUnit.test("save", function(assert) {
assert.expect(2);
- doc.save({title : "Henry V"});
+ doc.save({title: "Henry V"});
assert.equal(this.syncArgs.method, 'update');
assert.ok(_.isEqual(this.syncArgs.model, doc));
});
@@ -641,9 +641,9 @@
options.success('', options);
options.success(null, options);
};
- model.save({testing:'empty'}, {
+ model.save({testing: 'empty'}, {
success: function(model) {
- assert.deepEqual(model.attributes, {testing:'empty'});
+ assert.deepEqual(model.attributes, {testing: 'empty'});
}
});
});
@@ -757,7 +757,7 @@
assert.equal(lastError, undefined);
result = model.set({admin: true});
assert.equal(model.get('admin'), true);
- result = model.set({a: 200, admin: false}, {validate:true});
+ result = model.set({a: 200, admin: false}, {validate: true});
assert.equal(lastError, "Can't change admin status.");
assert.equal(result, false);
assert.equal(model.get('a'), 100);
@@ -779,7 +779,7 @@
model.unset('name', {validate: true});
assert.equal(error, true);
assert.equal(model.get('name'), 'Two');
- model.clear({validate:true});
+ model.clear({validate: true});
assert.equal(model.get('name'), 'Two');
delete model.validate;
model.clear();
@@ -796,12 +796,12 @@
model.on('invalid', function(model, error) {
boundError = true;
});
- var result = model.set({a: 100}, {validate:true});
+ var result = model.set({a: 100}, {validate: true});
assert.equal(result, model);
assert.equal(model.get('a'), 100);
assert.equal(model.validationError, null);
assert.equal(boundError, undefined);
- result = model.set({a: 200, admin: true}, {validate:true});
+ result = model.set({a: 200, admin: true}, {validate: true});
assert.equal(result, false);
assert.equal(model.get('a'), 100);
assert.equal(model.validationError, "Can't change admin status.");
@@ -812,7 +812,7 @@
assert.expect(2);
var Defaulted = Backbone.Model.extend({
defaults: {one: 1},
- initialize : function(attrs, opts) {
+ initialize: function(attrs, opts) {
assert.equal(this.attributes.one, 1);
}
});
@@ -1049,7 +1049,7 @@
var model = new Backbone.Model();
model.on('all', function(event) { events.push(event); });
model.on('change', function() {
- model.set({z: true}, {silent:true});
+ model.set({z: true}, {silent: true});
});
model.on('change:x', function() {
model.set({y: true});
@@ -1259,7 +1259,7 @@
QUnit.test("#1545 - `undefined` can be passed to a model constructor without coersion", function(assert) {
var Model = Backbone.Model.extend({
defaults: {one: 1},
- initialize : function(attrs, opts) {
+ initialize: function(attrs, opts) {
assert.equal(attrs, undefined);
}
});
@@ -1285,11 +1285,11 @@
QUnit.test("#1664 - Changing from one value, silently to another, back to original triggers a change.", function(assert) {
assert.expect(1);
- var model = new Backbone.Model({x: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:1});
+ model.set({x: 2}, {silent: true});
+ model.set({x: 3}, {silent: true});
+ model.set({x: 1});
});
QUnit.test("#1664 - multiple silent changes nested inside a change event", function(assert) {
@@ -1297,12 +1297,12 @@
var changes = [];
var model = new Backbone.Model();
model.on('change', function() {
- model.set({a:'c'}, {silent:true});
- model.set({b:2}, {silent:true});
- model.unset('c', {silent:true});
+ model.set({a: 'c'}, {silent: true});
+ model.set({b: 2}, {silent: true});
+ model.unset('c', {silent: true});
});
model.on('change:a change:b change:c', function(model, val) { changes.push(val); });
- model.set({a:'a', b:1, c:'item'});
+ model.set({a: 'a', b: 1, c: 'item'});
assert.deepEqual(changes, ['a', 1, 'item']);
assert.deepEqual(model.attributes, {a: 'c', b: 2});
});
@@ -1321,17 +1321,17 @@
var model = new Backbone.Model();
model.on('change:a change:b change:c', function(model, val) { changes.push(val); });
model.on('change', function() {
- model.set({a:'c'}, {silent:true});
+ model.set({a: 'c'}, {silent: true});
});
- model.set({a:'a'});
+ model.set({a: 'a'});
assert.deepEqual(changes, ['a']);
- model.set({a:'a'});
+ model.set({a: 'a'});
assert.deepEqual(changes, ['a', 'a']);
});
QUnit.test("#1943 change calculations should use _.isEqual", function(assert) {
var model = new Backbone.Model({a: {key: 'value'}});
- model.set('a', {key:'value'}, {silent:true});
+ model.set('a', {key: 'value'}, {silent: true});
assert.equal(model.changedAttributes(), false);
});
@@ -1353,9 +1353,9 @@
if (!attrs.valid) return "invalid";
};
assert.equal(model.isValid(), true);
- assert.equal(model.set({valid: false}, {validate:true}), false);
+ assert.equal(model.set({valid: false}, {validate: true}), false);
assert.equal(model.isValid(), true);
- model.set({valid:false});
+ model.set({valid: false});
assert.equal(model.isValid(), false);
assert.ok(!model.set('valid', false, {validate: true}));
});
diff --git a/test/router.js b/test/router.js
index aab7a41..6a8f28e 100644
--- a/test/router.js
+++ b/test/router.js
@@ -74,28 +74,28 @@
count: 0,
routes: {
- "noCallback": "noCallback",
- "counter": "counter",
- "search/:query": "search",
- "search/:query/p:page": "search",
- "charñ": "charUTF",
- "char%C3%B1": "charEscaped",
- "contacts": "contacts",
- "contacts/new": "newContact",
- "contacts/:id": "loadContact",
- "route-event/:arg": "routeEvent",
- "optional(/:item)": "optionalItem",
- "named/optional/(y:z)": "namedOptional",
- "splat/*args/end": "splat",
- ":repo/compare/*from...*to": "github",
- "decode/:named/*splat": "decode",
+ "noCallback": "noCallback",
+ "counter": "counter",
+ "search/:query": "search",
+ "search/:query/p:page": "search",
+ "charñ": "charUTF",
+ "char%C3%B1": "charEscaped",
+ "contacts": "contacts",
+ "contacts/new": "newContact",
+ "contacts/:id": "loadContact",
+ "route-event/:arg": "routeEvent",
+ "optional(/:item)": "optionalItem",
+ "named/optional/(y:z)": "namedOptional",
+ "splat/*args/end": "splat",
+ ":repo/compare/*from...*to": "github",
+ "decode/:named/*splat": "decode",
"*first/complex-*part/*rest": "complex",
- "query/:entity": "query",
- "function/:value": ExternalObject.routingFunction,
- "*anything": "anything"
+ "query/:entity": "query",
+ "function/:value": ExternalObject.routingFunction,
+ "*anything": "anything"
},
- initialize : function(options) {
+ initialize: function(options) {
this.testing = options.testing;
this.route('implicit', 'implicit');
},
@@ -685,7 +685,7 @@
var RouterBase = Backbone.Router.extend({
routes: function() {
return {
- home: "root",
+ home: "root",
index: "index.html"
};
}
diff --git a/test/sync.js b/test/sync.js
index 9907a89..29b0b9f 100644
--- a/test/sync.js
+++ b/test/sync.js
@@ -1,19 +1,19 @@
(function() {
var Library = Backbone.Collection.extend({
- url : function() { return '/library'; }
+ url: function() { return '/library'; }
});
var library;
var attrs = {
- title : "The Tempest",
- author : "Bill Shakespeare",
- length : 123
+ title: "The Tempest",
+ author: "Bill Shakespeare",
+ length: 123
};
QUnit.module("Backbone.sync", {
- beforeEach : function(assert) {
+ beforeEach: function(assert) {
library = new Library;
library.create(attrs, {wait: false});
},
diff --git a/test/view.js b/test/view.js
index 0bfd84f..4298a85 100644
--- a/test/view.js
+++ b/test/view.js
@@ -10,9 +10,9 @@
);
view = new Backbone.View({
- id : 'test-view',
- className : 'test-view',
- other : 'non-special-option'
+ id: 'test-view',
+ className: 'test-view',
+ other: 'non-special-option'
});
}
--
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