From 48d4ed28d3e045247760a9c5320773dc53447069 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 4 Nov 2014 08:13:21 +0100 Subject: [PATCH] Coding style cleanup (Gruntfile, lib) - Gruntfile: add `jshint` and `jscs` as deps of `grunt test` - Gruntfile: temporarily disable checks of `test` scripts - .jscsrc: relax jsdoc validation - .jshintrc: relax the rule for property access via dot notation - lib: fix remaining style issues --- .jscsrc | 5 +++++ .jshintrc | 1 + Gruntfile.js | 18 ++++++++++++------ lib/application.js | 2 +- lib/loopback.js | 2 +- lib/model.js | 10 ++++++---- lib/persisted-model.js | 24 +++++++++++++----------- 7 files changed, 39 insertions(+), 23 deletions(-) diff --git a/.jscsrc b/.jscsrc index 9e6c0dc4..b2b3515a 100644 --- a/.jscsrc +++ b/.jscsrc @@ -13,5 +13,10 @@ "value": 150, "allowComments": true, "allowRegex": true + }, + "validateJSDoc": { + "checkParamNames": false, + "checkRedundantParams": true, + "requireParamTypes": true } } diff --git a/.jshintrc b/.jshintrc index 91fb46ef..361fd3ae 100644 --- a/.jshintrc +++ b/.jshintrc @@ -9,6 +9,7 @@ "trailing": true, "newcap": true, "nonew": true, +"sub": true, "laxcomma": true, "laxbreak": true } diff --git a/Gruntfile.js b/Gruntfile.js index 3a29068e..e3627b6f 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -33,12 +33,16 @@ module.exports = function(grunt) { lib: { src: ['lib/**/*.js'] }, - test: { - src: ['test/**/*.js'] - } + // TODO(bajtos) - common/**/*.js + // TODO tests don't pass yet + // test: { + // src: ['test/**/*.js'] + // } }, jscs: { - src: ['lib/**/*.js', 'test/**/*.js'] + gruntfile: 'Gruntfile.js', + lib: ['lib/**/*.js'] + // TODO(bajtos) - common/**/*.js }, watch: { gruntfile: { @@ -83,7 +87,7 @@ module.exports = function(grunt) { karma: { 'unit-once': { configFile: 'test/karma.conf.js', - browsers: [ 'PhantomJS' ], + browsers: ['PhantomJS'], singleRun: true, reporters: ['dots', 'junit'], @@ -185,7 +189,7 @@ module.exports = function(grunt) { grunt.loadNpmTasks('grunt-contrib-uglify'); grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-watch'); - grunt.loadNpmTasks("grunt-jscs"); + grunt.loadNpmTasks('grunt-jscs'); grunt.loadNpmTasks('grunt-karma'); grunt.registerTask('e2e-server', function() { @@ -200,6 +204,8 @@ module.exports = function(grunt) { grunt.registerTask('default', ['browserify']); grunt.registerTask('test', [ + 'jscs', + 'jshint', process.env.JENKINS_HOME ? 'mochaTest:unit-xml' : 'mochaTest:unit', 'karma:unit-once']); diff --git a/lib/application.js b/lib/application.js index 3f5e474f..c66dd80e 100644 --- a/lib/application.js +++ b/lib/application.js @@ -41,7 +41,7 @@ function App() { * 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). diff --git a/lib/loopback.js b/lib/loopback.js index b792b027..efc3f088 100644 --- a/lib/loopback.js +++ b/lib/loopback.js @@ -28,7 +28,7 @@ var assert = require('assert'); * @header loopback */ -var loopback = exports = module.exports = createApplication; +var loopback = module.exports = createApplication; /*! * Framework version. diff --git a/lib/model.js b/lib/model.js index f5ed9bb5..9423d75a 100644 --- a/lib/model.js +++ b/lib/model.js @@ -593,10 +593,12 @@ Model.nestRemoting = function(relationName, options, cb) { var paramName = options.paramName || 'nk'; var http = [].concat(sharedToClass.http || [])[0]; + var httpPath; + var acceptArgs; if (relation.multiple) { - var httpPath = pathName + '/:' + paramName; - var acceptArgs = [ + httpPath = pathName + '/:' + paramName; + acceptArgs = [ { arg: paramName, type: 'any', http: { source: 'path' }, description: 'Foreign key for ' + relation.name, @@ -604,8 +606,8 @@ Model.nestRemoting = function(relationName, options, cb) { } ]; } else { - var httpPath = pathName; - var acceptArgs = []; + httpPath = pathName; + acceptArgs = []; } // A method should return the method name to use, if it is to be diff --git a/lib/persisted-model.js b/lib/persisted-model.js index 816bdfc2..cd4480d0 100644 --- a/lib/persisted-model.js +++ b/lib/persisted-model.js @@ -850,7 +850,7 @@ PersistedModel.replicate = function(since, targetModel, options, callback) { sourceModel.emit('conflicts', conflicts); } - callback && callback(null, conflicts); + if (callback) callback(null, conflicts); } }; @@ -869,7 +869,7 @@ PersistedModel.createUpdates = function(deltas, cb) { var tasks = []; deltas.forEach(function(change) { - var change = new Change(change); + change = new Change(change); var type = change.type(); var update = {type: type, change: change}; switch (type) { @@ -1011,15 +1011,15 @@ PersistedModel.enableChangeTracking = function() { // cleanup setInterval(cleanup, cleanupInterval); + } - function cleanup() { - Model.rectifyAllChanges(function(err) { - if (err) { - console.error(Model.modelName + ' Change Cleanup Error:'); - console.error(err); - } - }); - } + function cleanup() { + Model.rectifyAllChanges(function(err) { + if (err) { + console.error(Model.modelName + ' Change Cleanup Error:'); + console.error(err); + } + }); } }; @@ -1028,12 +1028,14 @@ PersistedModel._defineChangeModel = function() { assert(BaseChangeModel, '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 } ); + + return this.Change; }; PersistedModel.rectifyAllChanges = function(callback) {