From 4c2751a2a42613dd59468c935fb19f5d19562ded Mon Sep 17 00:00:00 2001 From: Amir Jafarian Date: Tue, 18 Oct 2016 18:48:59 -0400 Subject: [PATCH] Fix linting errors --- .eslintrc | 15 +++++++++++++-- index.js | 1 + lib/factory.js | 7 ++++--- lib/providers/filesystem/container.js | 1 + lib/providers/filesystem/file.js | 1 + lib/providers/filesystem/index.js | 4 ++++ lib/storage-connector.js | 1 + lib/storage-handler.js | 26 ++++++++++++++++++++------ lib/storage-service.js | 17 ++++++++++++++--- package.json | 2 +- test/fixtures/app.js | 5 +++-- test/fs.test.js | 1 + test/storage-service.test.js | 6 +++++- test/upload-download.test.js | 1 + 14 files changed, 70 insertions(+), 18 deletions(-) diff --git a/.eslintrc b/.eslintrc index 2ae2667..c221e63 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,3 +1,14 @@ { - "extends": "loopback" -} + "extends": "loopback", + "rules": { + "max-len": ["error", 90, 4, { + "ignoreComments": true, + "ignoreUrls": true, + "ignorePattern": "^\\s*var\\s.+=\\s*(require\\s*\\()|(/)" + }], + // NOTE we should eventually remove this override + // and fix all of those 100+ violations + "one-var": "off", + "no-unused-expressions": "off" + } +} diff --git a/index.js b/index.js index 64407e2..effcb58 100644 --- a/index.js +++ b/index.js @@ -2,6 +2,7 @@ // Node module: loopback-component-storage // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +'use strict'; var SG = require('strong-globalize'); SG.SetRootDir(__dirname); diff --git a/lib/factory.js b/lib/factory.js index 81b1b93..ec61410 100644 --- a/lib/factory.js +++ b/lib/factory.js @@ -2,6 +2,7 @@ // Node module: loopback-component-storage // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +'use strict'; var pkgcloud = require('pkgcloud'); @@ -13,9 +14,9 @@ function patchBaseClass(cls) { var proto = cls.prototype; var found = false; // Find the prototype that owns the _setProperties method - while (proto - && proto.constructor !== pkgcloud.storage.Container - && proto.constructor !== pkgcloud.storage.File) { + while (proto && + proto.constructor !== pkgcloud.storage.Container && + proto.constructor !== pkgcloud.storage.File) { if (proto.hasOwnProperty('_setProperties')) { found = true; break; diff --git a/lib/providers/filesystem/container.js b/lib/providers/filesystem/container.js index 050108c..326df34 100644 --- a/lib/providers/filesystem/container.js +++ b/lib/providers/filesystem/container.js @@ -2,6 +2,7 @@ // Node module: loopback-component-storage // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +'use strict'; var base = require('pkgcloud').storage; var util = require('util'); diff --git a/lib/providers/filesystem/file.js b/lib/providers/filesystem/file.js index 8baed88..c6d1b9b 100644 --- a/lib/providers/filesystem/file.js +++ b/lib/providers/filesystem/file.js @@ -2,6 +2,7 @@ // Node module: loopback-component-storage // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +'use strict'; var base = require('pkgcloud').storage; var util = require('util'); diff --git a/lib/providers/filesystem/index.js b/lib/providers/filesystem/index.js index 822c928..7a4d9ac 100644 --- a/lib/providers/filesystem/index.js +++ b/lib/providers/filesystem/index.js @@ -3,6 +3,10 @@ // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +// Turning on strict for this file breaks; +// disabling strict for this file +/* eslint-disable strict */ + // Globalization var g = require('strong-globalize')(); diff --git a/lib/storage-connector.js b/lib/storage-connector.js index d0fb44a..4941637 100644 --- a/lib/storage-connector.js +++ b/lib/storage-connector.js @@ -2,6 +2,7 @@ // Node module: loopback-component-storage // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +'use strict'; var StorageService = require('./storage-service'); /** diff --git a/lib/storage-handler.js b/lib/storage-handler.js index bdf3611..6b2df48 100644 --- a/lib/storage-handler.js +++ b/lib/storage-handler.js @@ -2,6 +2,7 @@ // Node module: loopback-component-storage // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +'use strict'; // Globalization var g = require('strong-globalize')(); @@ -35,18 +36,22 @@ exports.upload = function(provider, req, res, options, cb) { var form = new IncomingForm(options); var container = options.container || req.params.container; - var fields = {}, files = {}; + var fields = {}; + var files = {}; form.handlePart = function(part) { var self = this; if (part.filename === undefined) { - var value = '', - decoder = new StringDecoder(this.encoding); + var value = ''; + var decoder = new StringDecoder(this.encoding); part.on('data', function(buffer) { self._fieldsSize += buffer.length; if (self._fieldsSize > self.maxFieldsSize) { - self._error(new Error(g.f('{{maxFieldsSize}} exceeded, received %s bytes of field data', self._fieldsSize))); + self._error(new Error( + g.f('{{maxFieldsSize}} exceeded, received %s bytes of field data', + self._fieldsSize + ))); return; } value += decoder.write(buffer); @@ -91,7 +96,11 @@ exports.upload = function(provider, req, res, options, cb) { } if (Array.isArray(allowedContentTypes) && allowedContentTypes.length !== 0) { if (allowedContentTypes.indexOf(file.type) === -1) { - self._error(new Error(g.f('{{contentType}} "%s" is not allowed (Must be in [%s])', file.type, allowedContentTypes.join(', ')))); + self._error(new Error( + g.f('{{contentType}} "%s" is not allowed (Must be in [%s])', + file.type, + allowedContentTypes.join(', ') + ))); return; } } @@ -161,7 +170,11 @@ exports.upload = function(provider, req, res, options, cb) { // We are missing some way to tell the provider to cancel upload/multipart upload of the current file. // - s3-upload-stream doesn't provide a way to do this in it's public interface // - We could call provider.delete file but it would not delete multipart data - self._error(new Error(g.f('{{maxFileSize}} exceeded, received %s bytes of field data (max is %s)', fileSize, maxFileSize))); + self._error(new Error( + g.f('{{maxFileSize}} exceeded, received %s bytes of field data (max is %s)', + fileSize, + maxFileSize + ))); return; } }); @@ -177,6 +190,7 @@ exports.upload = function(provider, req, res, options, cb) { if (err) { console.error(err); } + // eslint-disable-next-line no-unused-expressions cb && cb(err, {files: files, fields: fields}); }); }; diff --git a/lib/storage-service.js b/lib/storage-service.js index 1351fc4..ef50b80 100644 --- a/lib/storage-service.js +++ b/lib/storage-service.js @@ -2,6 +2,7 @@ // Node module: loopback-component-storage // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +'use strict'; var factory = require('./factory'); var handler = require('./storage-handler'); @@ -259,7 +260,11 @@ StorageService.modelName = 'storage'; StorageService.prototype.getContainers.shared = true; StorageService.prototype.getContainers.accepts = []; -StorageService.prototype.getContainers.returns = {arg: 'containers', type: 'array', root: true}; +StorageService.prototype.getContainers.returns = { + arg: 'containers', + type: 'array', + root: true, +}; StorageService.prototype.getContainers.http = {verb: 'get', path: '/'}; @@ -267,7 +272,10 @@ StorageService.prototype.getContainer.shared = true; StorageService.prototype.getContainer.accepts = [ {arg: 'container', type: 'string'}, ]; -StorageService.prototype.getContainer.returns = {arg: 'container', type: 'object', root: true}; +StorageService.prototype.getContainer.returns = { + arg: 'container', + type: 'object', root: true, +}; StorageService.prototype.getContainer.http = {verb: 'get', path: '/:container'}; @@ -275,7 +283,10 @@ StorageService.prototype.createContainer.shared = true; StorageService.prototype.createContainer.accepts = [ {arg: 'options', type: 'object', http: {source: 'body'}}, ]; -StorageService.prototype.createContainer.returns = {arg: 'container', type: 'object', root: true}; +StorageService.prototype.createContainer.returns = { + arg: 'container', + type: 'object', root: true, +}; StorageService.prototype.createContainer.http = {verb: 'post', path: '/'}; diff --git a/package.json b/package.json index 6dee668..52dff3e 100644 --- a/package.json +++ b/package.json @@ -15,7 +15,7 @@ "strong-globalize": "^2.6.2" }, "devDependencies": { - "eslint": "^3.8.1", + "eslint": "^2.13.1", "eslint-config-loopback": "^4.0.0", "express": "^4.11.0", "loopback": "^2.10.0", diff --git a/test/fixtures/app.js b/test/fixtures/app.js index a4b94cd..9090deb 100644 --- a/test/fixtures/app.js +++ b/test/fixtures/app.js @@ -2,9 +2,10 @@ // Node module: loopback-component-storage // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +'use strict'; -var loopback = require('loopback'), - app = module.exports = loopback(); +var loopback = require('loopback'); +var app = module.exports = loopback(); var path = require('path'); diff --git a/test/fs.test.js b/test/fs.test.js index 12294ca..a9f8c4b 100644 --- a/test/fs.test.js +++ b/test/fs.test.js @@ -2,6 +2,7 @@ // Node module: loopback-component-storage // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +'use strict'; var FileSystemProvider = require('../lib/providers/filesystem/index.js').Client; diff --git a/test/storage-service.test.js b/test/storage-service.test.js index 3c5cae6..863a54a 100644 --- a/test/storage-service.test.js +++ b/test/storage-service.test.js @@ -2,13 +2,17 @@ // Node module: loopback-component-storage // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +'use strict'; var StorageService = require('../lib/storage-service.js'); var assert = require('assert'); var path = require('path'); -var storageService = new StorageService({root: path.join(__dirname, 'storage'), provider: 'filesystem'}); +var storageService = new StorageService({ + root: path.join(__dirname, 'storage'), + provider: 'filesystem', +}); describe('Storage service', function() { describe('container apis', function() { diff --git a/test/upload-download.test.js b/test/upload-download.test.js index 43be1d6..883311f 100644 --- a/test/upload-download.test.js +++ b/test/upload-download.test.js @@ -2,6 +2,7 @@ // Node module: loopback-component-storage // This file is licensed under the Artistic License 2.0. // License text available at https://opensource.org/licenses/Artistic-2.0 +'use strict'; var request = require('supertest'); var loopback = require('loopback');