From acdfb432d0e49c5c25632efc7e4ad87394a38b65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Bajto=C5=A1?= Date: Tue, 6 Dec 2016 15:40:42 +0100 Subject: [PATCH] Upgrade eslint config and grunt-eslint to latest - disable ES6 because PhantomJS does not support it yet - fix linter errors reported after the upgrade. --- .eslintrc | 3 +++ common/models/acl.js | 2 +- common/models/role.js | 2 +- example/mobile-models/app.js | 36 ++++++++++++++-------------- lib/model.js | 6 ++--- lib/persisted-model.js | 6 ++--- package.json | 4 ++-- test/model.application.test.js | 43 +++++++++++++++++----------------- test/rest.middleware.test.js | 6 ++--- 9 files changed, 56 insertions(+), 52 deletions(-) diff --git a/.eslintrc b/.eslintrc index f3fa72da..8e2160a9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,5 +1,8 @@ { "extends": "loopback", + "parserOptions": { + "ecmaVersion": 5 + }, "rules": { "max-len": ["error", 100, 4, { "ignoreComments": true, diff --git a/common/models/acl.js b/common/models/acl.js index d875f1b4..312bb517 100644 --- a/common/models/acl.js +++ b/common/models/acl.js @@ -347,7 +347,7 @@ module.exports = function(ACL) { var self = this; this.find({where: {principalType: principalType, principalId: principalId, - model: model, property: propertyQuery, accessType: accessTypeQuery}}, + model: model, property: propertyQuery, accessType: accessTypeQuery}}, function(err, dynACLs) { if (err) { if (callback) callback(err); diff --git a/common/models/role.js b/common/models/role.js index 04552f24..05638863 100644 --- a/common/models/role.js +++ b/common/models/role.js @@ -343,7 +343,7 @@ module.exports = function(Role) { if (principalType && principalId) { roleMappingModel.findOne({where: {roleId: roleId, - principalType: principalType, principalId: principalId}}, + principalType: principalType, principalId: principalId}}, function(err, result) { debug('Role mapping found: %j', result); done(!err && result); // The only arg is the result diff --git a/example/mobile-models/app.js b/example/mobile-models/app.js index 40a4f607..bd51c4ac 100644 --- a/example/mobile-models/app.js +++ b/example/mobile-models/app.js @@ -17,24 +17,26 @@ var Application = models.Application(dataSource); app.model(Application); -var data = {pushSettings: [ - {'platform': 'apns', - 'apns': { - 'pushOptions': { - 'gateway': 'gateway.sandbox.push.apple.com', - 'cert': 'credentials/apns_cert_dev.pem', - 'key': 'credentials/apns_key_dev.pem', - }, +var data = { + pushSettings: [{ + 'platform': 'apns', + 'apns': { + 'pushOptions': { + 'gateway': 'gateway.sandbox.push.apple.com', + 'cert': 'credentials/apns_cert_dev.pem', + 'key': 'credentials/apns_key_dev.pem', + }, - 'feedbackOptions': { - 'gateway': 'feedback.sandbox.push.apple.com', - 'cert': 'credentials/apns_cert_dev.pem', - 'key': 'credentials/apns_key_dev.pem', - 'batchFeedback': true, - 'interval': 300, - }, - }}, -]}; + 'feedbackOptions': { + 'gateway': 'feedback.sandbox.push.apple.com', + 'cert': 'credentials/apns_cert_dev.pem', + 'key': 'credentials/apns_key_dev.pem', + 'batchFeedback': true, + 'interval': 300, + }, + }, + }], +}; Application.create(data, function(err, data) { g.log('Created: %s', data.toObject()); diff --git a/lib/model.js b/lib/model.js index 465601b3..85e0917b 100644 --- a/lib/model.js +++ b/lib/model.js @@ -614,8 +614,8 @@ module.exports = function(registry) { isStatic: false, http: {verb: 'head', path: '/' + pathName + '/rel/:fk'}, accepts: {arg: 'fk', type: 'any', - description: format('Foreign key for %s', relationName), - required: true, + description: format('Foreign key for %s', relationName), + required: true, http: {source: 'path'}}, description: format('Check the existence of %s relation to an item by id.', relationName), accessType: 'READ', @@ -691,7 +691,7 @@ module.exports = function(registry) { isStatic: isStatic, http: {verb: 'get', path: '/' + pathName + '/count'}, accepts: {arg: 'where', type: 'object', - description: 'Criteria to match model instances'}, + description: 'Criteria to match model instances'}, description: format('Counts %s of %s.', scopeName, this.modelName), accessType: 'READ', returns: {arg: 'count', type: 'number'}, diff --git a/lib/persisted-model.js b/lib/persisted-model.js index d8ccf975..4adcc66c 100644 --- a/lib/persisted-model.js +++ b/lib/persisted-model.js @@ -750,7 +750,7 @@ module.exports = function(registry) { accepts: [ {arg: 'id', type: 'any', description: 'Model id', required: true, http: {source: 'path'}}, - {arg: 'data', type: 'object', model: typeName, http: {source: 'body'}, description: + {arg: 'data', type: 'object', model: typeName, http: {source: 'body'}, description: 'Model instance data'}, ], returns: {arg: 'data', type: typeName, root: true}, @@ -825,7 +825,7 @@ module.exports = function(registry) { description: 'Delete a model instance by {{id}} from the data source.', accessType: 'WRITE', accepts: {arg: 'id', type: 'any', description: 'Model id', required: true, - http: {source: 'path'}}, + http: {source: 'path'}}, http: {verb: 'del', path: '/:id'}, returns: {arg: 'count', type: 'object', root: true}, }); @@ -865,7 +865,7 @@ module.exports = function(registry) { accepts: [ {arg: 'since', type: 'number', description: 'Find deltas since this checkpoint'}, {arg: 'remoteChanges', type: 'array', description: 'an array of change objects', - http: {source: 'body'}}, + http: {source: 'body'}}, ], returns: {arg: 'result', type: 'object', root: true}, http: {verb: 'post', path: '/diff'}, diff --git a/package.json b/package.json index b42c4ee2..901514d6 100644 --- a/package.json +++ b/package.json @@ -68,14 +68,14 @@ "cookie-parser": "^1.3.4", "dirty-chai": "^1.2.2", "es5-shim": "^4.1.0", - "eslint-config-loopback": "^5.0.0", + "eslint-config-loopback": "^6.0.0", "express-session": "^1.14.0", "grunt": "^1.0.1", "grunt-browserify": "^5.0.0", "grunt-cli": "^1.2.0", "grunt-contrib-uglify": "^2.0.0", "grunt-contrib-watch": "^1.0.0", - "grunt-eslint": "^18.1.0", + "grunt-eslint": "^19.0.0", "grunt-karma": "^2.0.0", "grunt-mocha-test": "^0.12.7", "karma": "^1.1.2", diff --git a/test/model.application.test.js b/test/model.application.test.js index 3231ba1d..cde8c06d 100644 --- a/test/model.application.test.js +++ b/test/model.application.test.js @@ -65,29 +65,30 @@ describe('Application', function() { }); it('Create a new application with push settings', function(done) { - Application.create({owner: 'rfeng', - name: 'MyAppWithPush', - description: 'My push mobile application', - pushSettings: { - apns: { - production: false, - certData: 'cert', - keyData: 'key', - pushOptions: { - gateway: 'gateway.sandbox.push.apple.com', - port: 2195, - }, - feedbackOptions: { - gateway: 'feedback.sandbox.push.apple.com', - port: 2196, - interval: 300, - batchFeedback: true, - }, + Application.create({ + owner: 'rfeng', + name: 'MyAppWithPush', + description: 'My push mobile application', + pushSettings: { + apns: { + production: false, + certData: 'cert', + keyData: 'key', + pushOptions: { + gateway: 'gateway.sandbox.push.apple.com', + port: 2195, }, - gcm: { - serverApiKey: 'serverKey', + feedbackOptions: { + gateway: 'feedback.sandbox.push.apple.com', + port: 2196, + interval: 300, + batchFeedback: true, }, - }}, + }, + gcm: { + serverApiKey: 'serverKey', + }, + }}, function(err, result) { var app = result; assert.deepEqual(app.pushSettings.toObject(), { diff --git a/test/rest.middleware.test.js b/test/rest.middleware.test.js index e30101ca..ea64da03 100644 --- a/test/rest.middleware.test.js +++ b/test/rest.middleware.test.js @@ -139,8 +139,7 @@ describe('loopback.rest', function() { it('allows models to provide a custom HTTP path', function(done) { var CustomModel = app.registry.createModel('CustomModel', {name: String}, - {http: {'path': 'domain1/CustomModelPath'}, - }); + {http: {'path': 'domain1/CustomModelPath'}}); app.model(CustomModel, {dataSource: 'db'}); app.use(loopback.rest()); @@ -151,8 +150,7 @@ describe('loopback.rest', function() { it('should report 200 for url-encoded HTTP path', function(done) { var CustomModel = app.registry.createModel('CustomModel', {name: String}, - {http: {path: 'domain%20one/CustomModelPath'}, - }); + {http: {path: 'domain%20one/CustomModelPath'}}); app.model(CustomModel, {dataSource: 'db'}); app.use(loopback.rest());