Merge pull request #734 from strongloop/feature/jscs-style-check-and-cleanup

jscs style check and cleanup
This commit is contained in:
Miroslav Bajtoš 2014-11-04 13:16:52 +01:00
commit 2f1a1bcd7a
18 changed files with 254 additions and 222 deletions

22
.jscsrc Normal file
View File

@ -0,0 +1,22 @@
{
"preset": "google",
"requireCurlyBraces": [
"else",
"for",
"while",
"do",
"try",
"catch"
],
"disallowSpacesInsideObjectBrackets": null,
"maximumLineLength": {
"value": 150,
"allowComments": true,
"allowRegex": true
},
"validateJSDoc": {
"checkParamNames": false,
"checkRedundantParams": true,
"requireParamTypes": true
}
}

View File

@ -9,6 +9,7 @@
"trailing": true, "trailing": true,
"newcap": true, "newcap": true,
"nonew": true, "nonew": true,
"sub": true,
"laxcomma": true, "laxcomma": true,
"laxbreak": true "laxbreak": true
} }

View File

@ -33,9 +33,16 @@ module.exports = function(grunt) {
lib: { lib: {
src: ['lib/**/*.js'] src: ['lib/**/*.js']
}, },
test: { // TODO(bajtos) - common/**/*.js
src: ['test/**/*.js'] // TODO tests don't pass yet
} // test: {
// src: ['test/**/*.js']
// }
},
jscs: {
gruntfile: 'Gruntfile.js',
lib: ['lib/**/*.js']
// TODO(bajtos) - common/**/*.js
}, },
watch: { watch: {
gruntfile: { gruntfile: {
@ -182,6 +189,7 @@ module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-jscs');
grunt.loadNpmTasks('grunt-karma'); grunt.loadNpmTasks('grunt-karma');
grunt.registerTask('e2e-server', function() { grunt.registerTask('e2e-server', function() {
@ -196,6 +204,8 @@ module.exports = function(grunt) {
grunt.registerTask('default', ['browserify']); grunt.registerTask('default', ['browserify']);
grunt.registerTask('test', [ grunt.registerTask('test', [
'jscs',
'jshint',
process.env.JENKINS_HOME ? 'mochaTest:unit-xml' : 'mochaTest:unit', process.env.JENKINS_HOME ? 'mochaTest:unit-xml' : 'mochaTest:unit',
'karma:unit-once']); 'karma:unit-once']);

View File

@ -126,7 +126,6 @@ AccessContext.prototype.getUserId = function() {
return null; return null;
}; };
/** /**
* Get the application id * Get the application id
* @returns {*} * @returns {*}
@ -206,7 +205,7 @@ Principal.SCOPE = 'SCOPE';
/** /**
* Compare if two principals are equal * Compare if two principals are equal
* Returns true if argument principal is equal to this principal. * Returns true if argument principal is equal to this principal.
* @param {Object} principal The other principal * @param {Object} p The other principal
*/ */
Principal.prototype.equals = function(p) { Principal.prototype.equals = function(p) {
if (p instanceof Principal) { if (p instanceof Principal) {
@ -300,6 +299,3 @@ AccessRequest.prototype.debug = function() {
module.exports.AccessContext = AccessContext; module.exports.AccessContext = AccessContext;
module.exports.Principal = Principal; module.exports.Principal = Principal;
module.exports.AccessRequest = AccessRequest; module.exports.AccessRequest = AccessRequest;

View File

@ -2,15 +2,15 @@
* Module dependencies. * Module dependencies.
*/ */
var DataSource = require('loopback-datasource-juggler').DataSource var DataSource = require('loopback-datasource-juggler').DataSource;
, registry = require('./registry') var registry = require('./registry');
, assert = require('assert') var assert = require('assert');
, fs = require('fs') var fs = require('fs');
, extend = require('util')._extend var extend = require('util')._extend;
, _ = require('underscore') var _ = require('underscore');
, RemoteObjects = require('strong-remoting') var RemoteObjects = require('strong-remoting');
, stringUtils = require('underscore.string') var stringUtils = require('underscore.string');
, path = require('path'); var path = require('path');
/** /**
* The `App` object represents a Loopback application. * The `App` object represents a Loopback application.
@ -41,7 +41,7 @@ function App() {
* Export the app prototype. * Export the app prototype.
*/ */
var app = exports = module.exports = {}; var app = module.exports = {};
/** /**
* Lazily load a set of [remote objects](http://apidocs.strongloop.com/strong-remoting/#remoteobjectsoptions). * Lazily load a set of [remote objects](http://apidocs.strongloop.com/strong-remoting/#remoteobjectsoptions).
@ -385,9 +385,11 @@ function configureModel(ModelCtor, config, app) {
dataSource = app.dataSources[dataSource]; dataSource = app.dataSources[dataSource];
} }
assert(dataSource instanceof DataSource, assert(
dataSource instanceof DataSource,
ModelCtor.modelName + ' is referencing a dataSource that does not exist: "' + ModelCtor.modelName + ' is referencing a dataSource that does not exist: "' +
config.dataSource +'"'); config.dataSource + '"'
);
} }
config = extend({}, config); config = extend({}, config);

View File

@ -8,11 +8,11 @@ module.exports = Connector;
* Module dependencies. * Module dependencies.
*/ */
var EventEmitter = require('events').EventEmitter var EventEmitter = require('events').EventEmitter;
, debug = require('debug')('connector') var debug = require('debug')('connector');
, util = require('util') var util = require('util');
, inherits = util.inherits var inherits = util.inherits;
, assert = require('assert'); var assert = require('assert');
/** /**
* Create a new `Connector` with the given `options`. * Create a new `Connector` with the given `options`.

View File

@ -2,10 +2,10 @@
* Dependencies. * Dependencies.
*/ */
var mailer = require('nodemailer') var mailer = require('nodemailer');
, assert = require('assert') var assert = require('assert');
, debug = require('debug')('loopback:connector:mail') var debug = require('debug')('loopback:connector:mail');
, loopback = require('../loopback'); var loopback = require('../loopback');
/** /**
* Export the MailConnector class. * Export the MailConnector class.
@ -48,7 +48,6 @@ MailConnector.initialize = function(dataSource, callback) {
MailConnector.prototype.DataAccessObject = Mailer; MailConnector.prototype.DataAccessObject = Mailer;
/** /**
* Add a transport to the available transports. See https://github.com/andris9/Nodemailer#setting-up-a-transport-method. * Add a transport to the available transports. See https://github.com/andris9/Nodemailer#setting-up-a-transport-method.
* *
@ -160,8 +159,8 @@ Mailer.send = function (options, fn) {
assert(transport.sendMail, 'You must supply an Email.settings.transports containing a valid transport'); assert(transport.sendMail, 'You must supply an Email.settings.transports containing a valid transport');
transport.sendMail(options, fn); transport.sendMail(options, fn);
} else { } else {
console.warn('Warning: No email transport specified for sending email.' console.warn('Warning: No email transport specified for sending email.' +
+ ' Setup a transport to send mail messages.'); ' Setup a transport to send mail messages.');
process.nextTick(function() { process.nextTick(function() {
fn(null, options); fn(null, options);
}); });

View File

@ -8,12 +8,12 @@ module.exports = Memory;
* Module dependencies. * Module dependencies.
*/ */
var Connector = require('./base-connector') var Connector = require('./base-connector');
, debug = require('debug')('memory') var debug = require('debug')('memory');
, util = require('util') var util = require('util');
, inherits = util.inherits var inherits = util.inherits;
, assert = require('assert') var assert = require('assert');
, JdbMemory = require('loopback-datasource-juggler/lib/connectors/memory'); var JdbMemory = require('loopback-datasource-juggler/lib/connectors/memory');
/** /**
* Create a new `Memory` connector with the given `options`. * Create a new `Memory` connector with the given `options`.

View File

@ -2,13 +2,13 @@
* Module dependencies. * Module dependencies.
*/ */
var express = require('express') var express = require('express');
, proto = require('./application') var proto = require('./application');
, fs = require('fs') var fs = require('fs');
, ejs = require('ejs') var ejs = require('ejs');
, path = require('path') var path = require('path');
, merge = require('util')._extend var merge = require('util')._extend;
, assert = require('assert'); var assert = require('assert');
/** /**
* LoopBack core module. It provides static properties and * LoopBack core module. It provides static properties and
@ -28,7 +28,7 @@ var express = require('express')
* @header loopback * @header loopback
*/ */
var loopback = exports = module.exports = createApplication; var loopback = module.exports = createApplication;
/*! /*!
* Framework version. * Framework version.
@ -183,7 +183,6 @@ loopback.template = function (file) {
return ejs.compile(str); return ejs.compile(str);
}; };
/*! /*!
* Built in models / services * Built in models / services
*/ */

View File

@ -55,4 +55,3 @@ function rest() {
} }
}; };
} }

View File

@ -27,4 +27,3 @@ function status() {
}); });
}; };
} }

View File

@ -56,4 +56,3 @@ function token(options) {
}); });
}; };
} }

View File

@ -536,8 +536,9 @@ Model.hasManyRemoting = function (relationName, relation, define) {
}; };
Model.scopeRemoting = function(scopeName, scope, define) { Model.scopeRemoting = function(scopeName, scope, define) {
var pathName = (scope.options && scope.options.http && scope.options.http.path) var pathName =
|| scopeName; (scope.options && scope.options.http && scope.options.http.path) || scopeName;
var isStatic = scope.isStatic; var isStatic = scope.isStatic;
var toModelName = scope.modelTo.modelName; var toModelName = scope.modelTo.modelName;
@ -592,10 +593,12 @@ Model.nestRemoting = function(relationName, options, cb) {
var paramName = options.paramName || 'nk'; var paramName = options.paramName || 'nk';
var http = [].concat(sharedToClass.http || [])[0]; var http = [].concat(sharedToClass.http || [])[0];
var httpPath;
var acceptArgs;
if (relation.multiple) { if (relation.multiple) {
var httpPath = pathName + '/:' + paramName; httpPath = pathName + '/:' + paramName;
var acceptArgs = [ acceptArgs = [
{ {
arg: paramName, type: 'any', http: { source: 'path' }, arg: paramName, type: 'any', http: { source: 'path' },
description: 'Foreign key for ' + relation.name, description: 'Foreign key for ' + relation.name,
@ -603,8 +606,8 @@ Model.nestRemoting = function(relationName, options, cb) {
} }
]; ];
} else { } else {
var httpPath = pathName; httpPath = pathName;
var acceptArgs = []; acceptArgs = [];
} }
// A method should return the method name to use, if it is to be // A method should return the method name to use, if it is to be
@ -721,4 +724,3 @@ Model.ValidationError = require('loopback-datasource-juggler').ValidationError;
// setup the initial model // setup the initial model
Model.setup(); Model.setup();

View File

@ -53,9 +53,9 @@ PersistedModel.setup = function setupPersistedModel() {
function throwNotAttached(modelName, methodName) { function throwNotAttached(modelName, methodName) {
throw new Error( throw new Error(
'Cannot call ' + modelName + '.'+ methodName + '().' 'Cannot call ' + modelName + '.' + methodName + '().' +
+ ' The ' + methodName + ' method has not been setup.' ' The ' + methodName + ' method has not been setup.' +
+ ' The PersistedModel has not been correctly attached to a DataSource!' ' The PersistedModel has not been correctly attached to a DataSource!'
); );
} }
@ -607,8 +607,8 @@ PersistedModel.setupRemoting = function() {
}); });
setRemoting(PersistedModel, 'changes', { setRemoting(PersistedModel, 'changes', {
description: 'Get the changes to a model since a given checkpoint.' description: 'Get the changes to a model since a given checkpoint.' +
+ 'Provide a filter object to reduce the number of results returned.', 'Provide a filter object to reduce the number of results returned.',
accepts: [ accepts: [
{arg: 'since', type: 'number', description: 'Only return changes since this checkpoint'}, {arg: 'since', type: 'number', description: 'Only return changes since this checkpoint'},
{arg: 'filter', type: 'object', description: 'Only include changes that match this filter'} {arg: 'filter', type: 'object', description: 'Only include changes that match this filter'}
@ -850,7 +850,7 @@ PersistedModel.replicate = function(since, targetModel, options, callback) {
sourceModel.emit('conflicts', conflicts); sourceModel.emit('conflicts', conflicts);
} }
callback && callback(null, conflicts); if (callback) callback(null, conflicts);
} }
}; };
@ -869,7 +869,7 @@ PersistedModel.createUpdates = function(deltas, cb) {
var tasks = []; var tasks = [];
deltas.forEach(function(change) { deltas.forEach(function(change) {
var change = new Change(change); change = new Change(change);
var type = change.type(); var type = change.type();
var update = {type: type, change: change}; var update = {type: type, change: change};
switch (type) { switch (type) {
@ -880,8 +880,8 @@ PersistedModel.createUpdates = function(deltas, cb) {
if (err) return cb(err); if (err) return cb(err);
if (!inst) { if (!inst) {
console.error('missing data for change:', change); console.error('missing data for change:', change);
return cb && cb(new Error('missing data for change: ' return cb &&
+ change.modelId)); cb(new Error('missing data for change: ' + change.modelId));
} }
if (inst.toObject) { if (inst.toObject) {
update.data = inst.toObject(); update.data = inst.toObject();
@ -1011,6 +1011,7 @@ PersistedModel.enableChangeTracking = function() {
// cleanup // cleanup
setInterval(cleanup, cleanupInterval); setInterval(cleanup, cleanupInterval);
}
function cleanup() { function cleanup() {
Model.rectifyAllChanges(function(err) { Model.rectifyAllChanges(function(err) {
@ -1020,7 +1021,6 @@ PersistedModel.enableChangeTracking = function() {
} }
}); });
} }
}
}; };
PersistedModel._defineChangeModel = function() { PersistedModel._defineChangeModel = function() {
@ -1028,12 +1028,14 @@ PersistedModel._defineChangeModel = function() {
assert(BaseChangeModel, assert(BaseChangeModel,
'Change model must be defined before enabling change replication'); 'Change model must be defined before enabling change replication');
return this.Change = BaseChangeModel.extend(this.modelName + '-change', this.Change = BaseChangeModel.extend(this.modelName + '-change',
{}, {},
{ {
trackModel: this trackModel: this
} }
); );
return this.Change;
}; };
PersistedModel.rectifyAllChanges = function(callback) { PersistedModel.rectifyAllChanges = function(callback) {

View File

@ -356,9 +356,11 @@ registry.autoAttachModel = function(ModelCtor) {
if (ModelCtor.autoAttach) { if (ModelCtor.autoAttach) {
var ds = this.getDefaultDataSourceForType(ModelCtor.autoAttach); var ds = this.getDefaultDataSourceForType(ModelCtor.autoAttach);
assert(ds instanceof DataSource, 'cannot autoAttach model "' assert(
+ ModelCtor.modelName ds instanceof DataSource,
+ '". No dataSource found of type ' + ModelCtor.autoAttach); 'cannot autoAttach model "' + ModelCtor.modelName +
'". No dataSource found of type ' + ModelCtor.autoAttach
);
ModelCtor.attachTo(ds); ModelCtor.attachTo(ds);
} }

View File

@ -19,4 +19,3 @@ runtime.isBrowser = typeof window !== 'undefined';
*/ */
runtime.isServer = !runtime.isBrowser; runtime.isServer = !runtime.isBrowser;

View File

@ -57,14 +57,16 @@
"cookie-parser": "~1.3.3", "cookie-parser": "~1.3.3",
"errorhandler": "~1.2.0", "errorhandler": "~1.2.0",
"es5-shim": "^4.0.3", "es5-shim": "^4.0.3",
"grunt": "~0.4.5", "grunt": "^0.4.5",
"grunt-browserify": "~3.0.1", "grunt-browserify": "~3.0.1",
"grunt-cli": "^0.1.13", "grunt-cli": "^0.1.13",
"grunt-contrib-jshint": "~0.10.0", "grunt-contrib-jshint": "~0.10.0",
"grunt-contrib-uglify": "~0.5.1", "grunt-contrib-uglify": "~0.5.1",
"grunt-contrib-watch": "~0.6.1", "grunt-contrib-watch": "~0.6.1",
"grunt-jscs": "^0.8.1",
"grunt-karma": "~0.9.0", "grunt-karma": "~0.9.0",
"grunt-mocha-test": "^0.11.0", "grunt-mocha-test": "^0.11.0",
"karma": "~0.12.23",
"karma-browserify": "~0.2.1", "karma-browserify": "~0.2.1",
"karma-chrome-launcher": "~0.1.4", "karma-chrome-launcher": "~0.1.4",
"karma-firefox-launcher": "~0.1.3", "karma-firefox-launcher": "~0.1.3",
@ -79,8 +81,7 @@
"mocha": "~1.21.4", "mocha": "~1.21.4",
"serve-favicon": "~2.1.3", "serve-favicon": "~2.1.3",
"strong-task-emitter": "0.0.x", "strong-task-emitter": "0.0.x",
"supertest": "~0.13.0", "supertest": "~0.13.0"
"karma": "~0.12.23"
}, },
"repository": { "repository": {
"type": "git", "type": "git",