Fix linting errors

This commit is contained in:
Amir Jafarian 2016-10-18 18:48:59 -04:00
parent 7900d48126
commit 4c2751a2a4
14 changed files with 70 additions and 18 deletions

View File

@ -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"
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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');

View File

@ -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');

View File

@ -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')();

View File

@ -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');
/**

View File

@ -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});
});
};

View File

@ -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: '/'};

View File

@ -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",

View File

@ -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');

View File

@ -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;

View File

@ -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() {

View File

@ -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');