Permalink
Browse files

[lib] fix some jshint errors

  • Loading branch information...
1 parent cdec9de commit 34cf303a9d48098a3ebd840f6e55bc212d9c9cf4 @indutny indutny committed Oct 22, 2011
View
@@ -7,7 +7,7 @@ exports.caches = {
return this.stores.push(store);
},
clear: function () {
- this.stores.forEach(function (s) { s.clear() });
+ this.stores.forEach(function (s) { s.clear(); });
return this;
}
};
@@ -21,8 +21,8 @@ exports.Cache = function (options) {
exports.Cache.prototype.get = function (id) {
var that = this;
- if (!resourceful.cache) { return }
- if (!id) { return }
+ if (!resourceful.cache) return;
+ if (!id) { return; }
else if (Array.isArray(id)) {
return id.map(function (k) {
return that.store[k.toString()];
@@ -34,13 +34,13 @@ exports.Cache.prototype.get = function (id) {
};
exports.Cache.prototype.put = function (id, obj) {
- if (!resourceful.cache) { return }
- if (!this.has(id)) { this.size++ }
+ if (!resourceful.cache) return;
+ if (!this.has(id)) this.size++;
this.store[id] = obj;
};
exports.Cache.prototype.update = function (id, obj) {
- if (!resourceful.cache) { return }
+ if (!resourceful.cache) return;
if (id in this.store) {
for (var k in obj) {
try { this.store[id][k] = obj[k]; }
@@ -50,7 +50,7 @@ exports.Cache.prototype.update = function (id, obj) {
};
exports.Cache.prototype.clear = function (id) {
- if (!resourceful.cache) { return }
+ if (!resourceful.cache) return;
if (id) {
this.size --;
delete(this.store[id]);
@@ -62,6 +62,6 @@ exports.Cache.prototype.clear = function (id) {
};
exports.Cache.prototype.has = function (id) {
- if (!resourceful.cache) { return }
+ if (!resourceful.cache) return;
return id in this.store;
-};
+};
@@ -55,7 +55,7 @@ common.typeOf = function (value) {
return 'array';
}
else if (derived === 'object') {
- return derived ? 'object' : 'null'
+ return derived ? 'object' : 'null';
}
else if (derived === 'function') {
return derived instanceof RegExp ? 'regexp' : 'function';
@@ -69,5 +69,5 @@ common.capitalize = function (str) {
};
common.pluralize = function (s) {
- return s + 's'
+ return s + 's';
};
View
@@ -1,4 +1,4 @@
-var sys = require('sys'),
+var util = require('util'),
events = require('events'),
common = require('./common');
@@ -46,7 +46,7 @@ resourceful.connect = function (/* [uri], [port], [options] */) {
args.forEach(function (a) {
switch (typeof(a)) {
- case 'number': options.port = parseInt(a); break;
+ case 'number': options.port = parseInt(a, 10); break;
case 'string': options.uri = a; break;
case 'object': options = a; break;
}
@@ -61,8 +61,8 @@ resourceful.connect = function (/* [uri], [port], [options] */) {
if (protocol) {
engine = resourceful.engines[common.capitalize(protocol)];
} else {
- engine = resourceful.engine || this.engine
- };
+ engine = resourceful.engine || this.engine;
+ }
this.connection = new(engine)(options);
@@ -99,7 +99,7 @@ resourceful.define = function (name, definition) {
});
Object.keys(Factory.properties).forEach(function (k) {
- self._properties[k] = Factory.properties[k].default;
+ self._properties[k] = Factory.properties[k]['default'];
});
this._properties.resource = name;
@@ -118,7 +118,7 @@ resourceful.define = function (name, definition) {
//
// Setup inheritance
//
- Factory.__proto__ = resourceful.Resource;
+ Factory.__proto__ = resourceful.Resource;
Factory.prototype.__proto__ = resourceful.Resource.prototype;
//
@@ -153,7 +153,7 @@ resourceful.define = function (name, definition) {
Object.keys(events.EventEmitter.prototype).forEach(function (k) {
Factory[k] = function () {
- return Factory['emitter'][k].apply(Factory['emitter'], arguments);
+ return Factory.emitter[k].apply(Factory.emitter, arguments);
};
});
@@ -179,7 +179,7 @@ resourceful.define = function (name, definition) {
};
resourceful.defineProperty = function (obj, property, schema) {
- schema || (schema = {});
+ schema = schema || {};
// Sanitize defaults and per-creation properties
if (schema.sanitize) {
@@ -229,9 +229,9 @@ resourceful.instantiate = function (obj) {
if (Factory) {
// Don't instantiate an already instantiated object
- if (obj instanceof Factory) { return obj }
- else { return new(Factory)(obj) }
+ if (obj instanceof Factory) { return obj; }
+ else { return new Factory(obj); }
} else {
- throw new(Error)("unrecognised resource '" + obj.resource + "'");
+ throw new Error("unrecognised resource '" + obj.resource + "'");
}
};
@@ -17,8 +17,8 @@ module.exports = {
options = args[0] || {};
}
- if (options.message) { this.property.messages[attr] = options.message }
- if (options.condition) { this.property.conditions[attr] = condition }
+ if (options.message) this.property.messages[attr] = options.message;
+ if (options.condition) this.property.conditions[attr] = condition;
return this;
},
@@ -36,15 +36,15 @@ module.exports = {
valid = (Array.isArray(val) ? val : [val]).every(function (val) {
return valid.indexOf(val) !== -1;
- })
+ });
if (!valid) {
throw new(TypeError)("invalid type.");
}
this.property.type = val;
return this;
},
- default: function (val, condition, options) {
+ 'default': function (val, condition, options) {
if (this.property.type) {
enforceType(val, this.property.type);
}
@@ -87,7 +87,7 @@ module.exports = {
'phone', 'uri', 'email',
'ip-address', 'ipv6', 'street-adress',
'country', 'region', 'postal-code',
- 'locality', 'date-time',
+ 'locality', 'date-time'
];
if (valid.indexOf(val) === -1) {
throw new(Error)({name:"ArgumentError"});
@@ -108,7 +108,7 @@ module.exports = {
lazy: function (val, condition, options) {
enforceType(val, "boolean");
return this.define("lazy", val, condition, options);
- },
+ }
},
string: {
//
@@ -50,17 +50,18 @@ Couchdb.prototype.head = function (id, callback) {
Couchdb.prototype.get = function (id, callback) {
return this.request.call(this, 'get', id, function (e, res) {
- if (e) { return callback(e) }
+ if (e) return callback(e);
- return Array.isArray(id)
- ? callback(null, res.rows.map(function (r) { return r.doc }))
- : callback(null, res);
+ return Array.isArray(id) ?
+ callback(null, res.rows.map(function (r) { return r.doc; }))
+ :
+ callback(null, res);
});
};
Couchdb.prototype.put = function (id, doc, callback) {
return this.request('put', id, doc, function (e, res) {
- if (e) { return callback(e) }
+ if (e) return callback(e);
res.status = 201;
callback(null, res);
@@ -72,9 +73,10 @@ Couchdb.prototype.save = function () {
};
Couchdb.prototype.update = function (id, doc, callback) {
- return this.cache.has(id)
- ? this.put(id, resourceful.mixin({}, this.cache.get(id).toJSON(), doc), callback)
- : this.request('merge', id, doc, callback);
+ return this.cache.has(id) ?
+ this.put(id, resourceful.mixin({}, this.cache.get(id).toJSON(), doc), callback)
+ :
+ this.request('merge', id, doc, callback);
};
Couchdb.prototype.destroy = function () {
@@ -106,7 +108,7 @@ Couchdb.prototype.destroy = function () {
Couchdb.prototype.view = function (path, opts, callback) {
return this.request.call(this, 'view', path, opts, function (e, res) {
- if (e) { return callback(e) }
+ if (e) return callback(e);
callback(null, res.rows.map(function (r) {
// With `include_docs=true`, the 'doc' attribute is set instead of 'value'.
@@ -120,9 +122,10 @@ Couchdb.prototype.view = function (path, opts, callback) {
Couchdb.prototype.all = function (callback) {
return this.request.call(this, 'all', { include_docs: 'true' }, function (e, res) {
- return e
- ? callback(e)
- : callback(null, res.rows.map(function (r) { return r.doc }));
+ return e ?
+ callback(e)
+ :
+ callback(null, res.rows.map(function (r) { return r.doc; }));
});
};
@@ -136,7 +139,7 @@ Couchdb.prototype.sync = function (factory, callback) {
factory._design = factory._design || {};
factory._design._id = id;
- if (factory._design._rev) { return callback(null) }
+ if (factory._design._rev) return callback(null);
this.connection.head(id, function (e, headers, status) {
if (!e && headers.etag) {
@@ -185,4 +188,4 @@ Couchdb._byParent = function (factory, parent, rfactory) {
resource: JSON.stringify(parent),
children: factory.resource + '_ids'
}));
-};
+};
@@ -36,10 +36,10 @@ exports.filter = function (name /* [options], filter */) {
if (doc.resource === $resource) {
if (function () {
for (var k in object) {
- if (object[k] !== doc[k]) { return false }
+ if (object[k] !== doc[k]) return false;
}
return true;
- }()) { emit(doc._id, doc) }
+ }()) { emit(doc._id, doc); }
}
}
}, { object: filter, resource: JSON.stringify(R.resource) });
@@ -53,7 +53,7 @@ exports.filter = function (name /* [options], filter */) {
}
}, { key: "doc." + Object.keys(filter("$key"))[0],
resource: JSON.stringify(R.resource) });
- } else { throw new(TypeError)("last argument must be an object or function") }
+ } else { throw new TypeError("last argument must be an object or function"); }
// Here we create the named filter method on the Resource
//
@@ -63,7 +63,7 @@ exports.filter = function (name /* [options], filter */) {
//
R[name] = function (/* [param], callback */) {
var that = this,
- promise = new(events.EventEmitter),
+ promise = new events.EventEmitter(),
args = Array.prototype.slice.call(arguments),
callback = args.pop(),
param = args.pop() || {},
@@ -50,7 +50,7 @@ Memory.prototype.request = function (fn) {
Memory.prototype.save = function (key, val, callback) {
if (!key) {
- throw new Error("key is undefined")
+ throw new Error("key is undefined");
}
this.request(function () {
@@ -71,9 +71,10 @@ Memory.prototype.update = function (key, obj, callback) {
Memory.prototype.get = function (key, callback) {
this.request(function () {
key = key.toString();
- return key in this.store
- ? callback(null, this.store[key])
- : callback({ status: 404 });
+ return key in this.store ?
+ callback(null, this.store[key])
+ :
+ callback({ status: 404 });
});
};
@@ -105,5 +106,5 @@ Memory.prototype.filter = function (filter, callback) {
};
Memory.prototype.sync = function (factory, callback) {
- process.nextTick(function () { callback() });
+ process.nextTick(function () { callback(); });
};
Oops, something went wrong.

0 comments on commit 34cf303

Please sign in to comment.