eslint: manually fix remaining problems

This commit is contained in:
Miroslav Bajtoš 2018-12-07 16:22:36 +01:00
parent 481ad566d2
commit b03ee61d37
No known key found for this signature in database
GPG Key ID: 6F2304BA9361C7E3
25 changed files with 94 additions and 85 deletions

View File

@ -33,14 +33,13 @@ KeyValueMemoryConnector.prototype._setupRegularCleanup = function() {
// in order to release memory. Note that GET operation checks
// key expiration too, the scheduled cleanup is merely a performance
// optimization.
const self = this;
var timer = this._cleanupTimer = setInterval(
function() {
if (self && self._removeExpiredItems) {
self._removeExpiredItems();
this._cleanupTimer = setInterval(
() => {
if (this && this._removeExpiredItems) {
this._removeExpiredItems();
} else {
// The datasource/connector was destroyed - cancel the timer
clearInterval(timer);
clearInterval(this._cleanupTimer);
}
},
1000

View File

@ -119,7 +119,7 @@ Memory.prototype.setupFileQueue = function() {
const file = self.settings.file;
if (task.operation === 'write') {
// Flush out the models/ids
var data = JSON.stringify({
const data = JSON.stringify({
ids: self.ids,
models: self.cache,
}, null, ' ');
@ -130,7 +130,7 @@ Memory.prototype.setupFileQueue = function() {
callback(err, task.data);
});
} else if (task.operation === 'read') {
debug('Reading cache from %s: %s', file, data);
debug('Reading cache from %s', file);
fs.readFile(file, {
encoding: 'utf8',
flag: 'r',

View File

@ -91,8 +91,9 @@ Transient.prototype.count = function count(model, callback, where) {
Transient.prototype.create = function create(model, data, callback) {
const props = this._models[model].properties;
const idName = this.idName(model);
let id = undefined;
if (idName && props[idName]) {
var id = this.getIdValue(model, data) || this.generateId(model, data, idName);
id = this.getIdValue(model, data) || this.generateId(model, data, idName);
id = (props[idName] && props[idName].type && props[idName].type(id)) || id;
this.setIdValue(model, data, id);
}

View File

@ -89,9 +89,9 @@ function convertSubsetOfPropertiesByType(inst, data) {
function applyStrictCheck(model, strict, data, inst, cb) {
const props = model.definition.properties;
const keys = Object.keys(data);
let result = {}, key;
const result = {};
for (let i = 0; i < keys.length; i++) {
key = keys[i];
const key = keys[i];
if (props[key]) {
result[key] = data[key];
} else if (strict && strict !== 'filter') {
@ -1105,7 +1105,8 @@ DataAccessObject.findOrCreate = function findOrCreate(query, data, options, cb)
if (err) return cb(err);
data = ctx.data;
let obj, Model = self.lookupModel(data);
const Model = self.lookupModel(data);
let obj;
if (data) {
obj = new Model(data, {fields: query.fields, applySetters: false,
@ -2594,9 +2595,10 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
const pkName = idName(this);
if (!data[pkName]) data[pkName] = id;
let Model = this;
let inst;
try {
var Model = this;
var inst = new Model(data, {persisted: true});
inst = new Model(data, {persisted: true});
const enforced = {};
this.applyProperties(enforced, inst);
@ -2808,7 +2810,7 @@ function(data, options, cb) {
for (let i = 0, n = idNames.length; i < n; i++) {
const idName = idNames[i];
if (data[idName] !== undefined && !idEquals(data[idName], inst[idName])) {
var err = new Error(g.f('{{id}} cannot be updated from ' +
const err = new Error(g.f('{{id}} cannot be updated from ' +
'%s to %s when {{forceId}} is set to true',
inst[idName], data[idName]));
err.statusCode = 400;

View File

@ -2275,7 +2275,7 @@ DataSource.prototype.transaction = function(execute, options, cb) {
});
});
var done = function(err) {
let done = function(err) {
if (err) {
transaction.rollback(function(error) {
cb(err || error);

View File

@ -12,6 +12,10 @@ const assert = require('assert');
*/
exports.nearFilter = function nearFilter(where) {
const nearResults = [];
nearSearch(where);
return (!nearResults.length ? false : nearResults);
function nearSearch(clause, parentKeys) {
if (typeof clause !== 'object') {
return false;
@ -41,10 +45,6 @@ exports.nearFilter = function nearFilter(where) {
}
});
}
var nearResults = [];
nearSearch(where);
return (!nearResults.length ? false : nearResults);
};
/*!

View File

@ -505,8 +505,10 @@ Inclusion.include = function(objects, include, options, cb) {
function linkManyToMany(target, next) {
const targetId = target[modelToIdName];
if (!targetId) {
const err = new Error(g.f('LinkManyToMany received target that doesn\'t contain required "%s"',
modelToIdName));
const err = new Error(g.f(
'LinkManyToMany received target that doesn\'t contain required "%s"',
modelToIdName
));
return next(err);
}
const objList = targetObjsMap[targetId.toString()];

View File

@ -229,7 +229,7 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
hiddenProperty(ModelClass, '_warned', {});
// inherit ModelBaseClass static methods
for (var i in ModelBaseClass) {
for (const i in ModelBaseClass) {
// We need to skip properties that are already in the subclass, for example, the event emitter methods
if (i !== '_mixins' && !(i in ModelClass)) {
ModelClass[i] = ModelBaseClass[i];
@ -306,7 +306,7 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
idNames = modelDefinition.idNames(); // Reload it after rebuild
// Create a virtual property 'id'
if (idNames.length === 1) {
var idProp = idNames[0];
const idProp = idNames[0];
if (idProp !== 'id') {
Object.defineProperty(ModelClass.prototype, 'id', {
get: function() {
@ -323,7 +323,7 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
get: function() {
const compositeId = {};
const idNames = ModelClass.definition.idNames();
for (var i = 0, p; i < idNames.length; i++) {
for (let i = 0, p; i < idNames.length; i++) {
p = idNames[i];
compositeId[p] = this.__data[p];
}
@ -339,7 +339,7 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
let forceId = ModelClass.settings.forceId;
if (idNames.length > 0) {
const idName = modelDefinition.idName();
idProp = ModelClass.definition.rawProperties[idName];
const idProp = ModelClass.definition.rawProperties[idName];
if (idProp.generated && forceId !== false) {
forceId = 'auto';
} else if (!idProp.generated && forceId === 'auto') {
@ -624,7 +624,7 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
const props = ModelClass.definition.properties;
let keys = Object.keys(props);
let size = keys.length;
for (i = 0; i < size; i++) {
for (let i = 0; i < size; i++) {
const propertyName = keys[i];
ModelClass.registerProperty(propertyName);
}
@ -632,8 +632,8 @@ ModelBuilder.prototype.define = function defineClass(className, properties, sett
const mixinSettings = settings.mixins || {};
keys = Object.keys(mixinSettings);
size = keys.length;
for (i = 0; i < size; i++) {
var name = keys[i];
for (let i = 0; i < size; i++) {
const name = keys[i];
let mixin = mixinSettings[name];
if (mixin === true) {
mixin = {};
@ -929,12 +929,9 @@ ModelBuilder.prototype.buildModels = function(schemas, createModel) {
for (let s = 0, n = schemas.length; s < n; s++) {
const name = this.getSchemaName(schemas[s].name);
schemas[s].name = name;
var model;
if (typeof createModel === 'function') {
model = createModel(schemas[s].name, schemas[s].properties, schemas[s].options);
} else {
model = this.define(schemas[s].name, schemas[s].properties, schemas[s].options);
}
const model = typeof createModel === 'function' ?
createModel(schemas[s].name, schemas[s].properties, schemas[s].options) :
this.define(schemas[s].name, schemas[s].properties, schemas[s].options);
models[name] = model;
relations = relations.concat(model.definition.relations);
}

View File

@ -187,7 +187,7 @@ ModelBaseClass.prototype._initProperties = function(data, options) {
let size = keys.length;
let p, propVal;
for (var k = 0; k < size; k++) {
for (let k = 0; k < size; k++) {
p = keys[k];
propVal = data[p];
if (typeof propVal === 'function') {
@ -208,7 +208,7 @@ ModelBaseClass.prototype._initProperties = function(data, options) {
} else if (ctor.relations[p]) {
const relationType = ctor.relations[p].type;
var modelTo;
let modelTo;
if (!properties[p]) {
modelTo = ctor.relations[p].modelTo || ModelBaseClass;
const multiple = ctor.relations[p].multiple;
@ -272,7 +272,7 @@ ModelBaseClass.prototype._initProperties = function(data, options) {
size = keys.length;
for (k = 0; k < size; k++) {
for (let k = 0; k < size; k++) {
p = keys[k];
propVal = self.__data[p];
const type = properties[p].type;
@ -446,7 +446,7 @@ ModelBaseClass.prototype.toObject = function(onlySchema, removeHidden, removePro
let keys = Object.keys(props);
let propertyName, val;
for (var i = 0; i < keys.length; i++) {
for (let i = 0; i < keys.length; i++) {
propertyName = keys[i];
val = self[propertyName];
@ -483,7 +483,7 @@ ModelBaseClass.prototype.toObject = function(onlySchema, removeHidden, removePro
// triggered to add it to __data
keys = Object.keys(self);
let size = keys.length;
for (i = 0; i < size; i++) {
for (let i = 0; i < size; i++) {
propertyName = keys[i];
if (props[propertyName]) {
continue;
@ -517,7 +517,7 @@ ModelBaseClass.prototype.toObject = function(onlySchema, removeHidden, removePro
// Now continue to check __data
keys = Object.keys(self.__data);
size = keys.length;
for (i = 0; i < size; i++) {
for (let i = 0; i < size; i++) {
propertyName = keys[i];
if (propertyName.indexOf('__') === 0) {
continue;

View File

@ -110,14 +110,13 @@ function bindRelationMethods(relation, relationMethod, definition) {
function preventFkOverride(inst, data, fkProp) {
if (!fkProp) return undefined;
if (data[fkProp] !== undefined && !idEquals(data[fkProp], inst[fkProp])) {
var err = new Error(g.f(
return new Error(g.f(
'Cannot override foreign key %s from %s to %s',
fkProp,
inst[fkProp],
data[fkProp]
));
}
return err;
}
/**

View File

@ -99,10 +99,11 @@ ScopeDefinition.prototype.related = function(receiver, scopeParams, condOrRefres
const scopeOnRelatedModel = params.collect &&
params.include.scope !== null &&
typeof params.include.scope === 'object';
let filter, queryRelated;
if (scopeOnRelatedModel) {
var filter = params.include;
filter = params.include;
// The filter applied on relatedModel
var queryRelated = filter.scope;
queryRelated = filter.scope;
delete params.include.scope;
}
@ -239,7 +240,7 @@ function defineScope(cls, targetClass, name, params, methods, options) {
const targetModel = definition.targetModel(this);
const self = this;
var f = function(condOrRefresh, options, cb) {
const f = function(condOrRefresh, options, cb) {
if (arguments.length === 0) {
if (typeof f.value === 'function') {
return f.value(self);

View File

@ -513,7 +513,8 @@ function getConfigurator(name, opts) {
*/
Validatable.prototype.isValid = function(callback, data, options) {
options = options || {};
let valid = true, inst = this, wait = 0, async = false;
let valid = true, wait = 0, async = false;
const inst = this;
const validations = this.constructor.validations;
const reportDiscardedProperties = this.__strict &&
@ -539,8 +540,8 @@ Validatable.prototype.isValid = function(callback, data, options) {
});
this.trigger('validate', function(validationsDone) {
let inst = this,
asyncFail = false;
const inst = this;
let asyncFail = false;
const attrs = Object.keys(validations || {});
@ -687,7 +688,7 @@ function skipValidation(inst, conf, kind) {
return !doValidate;
}
var defaultMessages = {
const defaultMessages = {
presence: 'can\'t be blank',
absence: 'can\'t be set',
'unknown-property': 'is not defined in the model',
@ -894,7 +895,7 @@ function ValidationError(obj) {
util.inherits(ValidationError, Error);
var errorHasStackProperty = !!(new Error).stack;
const errorHasStackProperty = !!(new Error).stack;
ValidationError.maxPropertyStringLength = 32;

View File

@ -108,7 +108,7 @@ describe('DataSource', function() {
* new DataSource(connectorInstance)
*/
it('should accept resolved connector', function() {
var mockConnector = {
const mockConnector = {
name: 'loopback-connector-mock',
initialize: function(ds, cb) {
ds.connector = mockConnector;
@ -125,7 +125,7 @@ describe('DataSource', function() {
* new DataSource(dsName, connectorInstance)
*/
it('should accept dsName and resolved connector', function() {
var mockConnector = {
const mockConnector = {
name: 'loopback-connector-mock',
initialize: function(ds, cb) {
ds.connector = mockConnector;
@ -142,7 +142,7 @@ describe('DataSource', function() {
* new DataSource(connectorInstance, settings)
*/
it('should accept resolved connector and settings', function() {
var mockConnector = {
const mockConnector = {
name: 'loopback-connector-mock',
initialize: function(ds, cb) {
ds.connector = mockConnector;
@ -156,7 +156,7 @@ describe('DataSource', function() {
});
it('should set states correctly with eager connect', function(done) {
var mockConnector = {
const mockConnector = {
name: 'loopback-connector-mock',
initialize: function(ds, cb) {
ds.connector = mockConnector;
@ -211,7 +211,7 @@ describe('DataSource', function() {
});
it('should set states correctly with deferred connect', function(done) {
var mockConnector = {
const mockConnector = {
name: 'loopback-connector-mock',
initialize: function(ds, cb) {
ds.connector = mockConnector;
@ -267,7 +267,7 @@ describe('DataSource', function() {
});
it('should set states correctly with lazyConnect = true', function(done) {
var mockConnector = {
const mockConnector = {
name: 'loopback-connector-mock',
initialize: function(ds, cb) {
ds.connector = mockConnector;

View File

@ -53,7 +53,8 @@ describe('datatypes', function() {
});
it('should keep types when get read data from db', function(done) {
let d = new Date('2015-01-01T12:00:00'), id;
const d = new Date('2015-01-01T12:00:00');
let id;
Model.create({
str: 'hello', date: d, num: '3', bool: 1, list: ['test'], arr: [1, 'str'],
@ -101,7 +102,8 @@ describe('datatypes', function() {
});
it('should respect data types when updating attributes', function(done) {
const d = new Date, id;
const d = new Date;
let id;
Model.create({
str: 'hello', date: d, num: '3', bool: 1}, function(err, m) {

View File

@ -632,7 +632,8 @@ describe('Mock connector', function() {
});
describe('Default memory connector', function() {
let ds, nonExistantError = 'Table \'NONEXISTENT\' does not exist.';
const nonExistantError = 'Table \'NONEXISTENT\' does not exist.';
let ds;
before(function() {
ds = new DataSource({connector: 'memory'});

View File

@ -9,12 +9,12 @@
/* global getSchema:false */
const should = require('./init.js');
let j = require('../'),
const j = require('../'),
Schema = j.Schema,
AbstractClass = j.AbstractClass,
Hookable = j.Hookable,
Hookable = j.Hookable;
db, User;
let db, User;
describe('hooks', function() {
before(function(done) {
@ -436,7 +436,8 @@ describe('hooks', function() {
});
function addHooks(name, done) {
let called = false, random = String(Math.floor(Math.random() * 1000));
const random = String(Math.floor(Math.random() * 1000));
let called = false;
User['before' + name] = function(next, data) {
called = true;
data.email = random;

View File

@ -1493,10 +1493,10 @@ describe('include', function() {
});
});
var createdUsers = [];
var createdPassports = [];
var createdProfiles = [];
var createdPosts = [];
let createdUsers = [];
let createdPassports = [];
let createdProfiles = [];
let createdPosts = [];
function setup(done) {
db = getSchema();
City = db.define('City');

View File

@ -615,8 +615,7 @@ describe('DataSource define model', function() {
it('updates instances with unknown properties in non-strict mode', function(done) {
const ds = new DataSource('memory');// define models
let Post;
Post = ds.define('Post', {
const Post = ds.define('Post', {
title: {type: String, length: 255, index: true},
content: {type: String},
});

View File

@ -137,7 +137,7 @@ describe('manipulation', function() {
});
it('should not return instance of object', function(done) {
var person = Person.create(function(err, p) {
const person = Person.create(function(err, p) {
if (err) return done(err);
should.exist(p.id);
if (person) person.should.not.be.an.instanceOf(Person);
@ -254,7 +254,7 @@ describe('manipulation', function() {
{name: 'Boltay'},
{},
];
var res = Person.create(batch, function(e, ps) {
const res = Person.create(batch, function(e, ps) {
if (res) res.should.not.be.instanceOf(Array);
should.not.exist(e);
should.exist(ps);

View File

@ -923,7 +923,8 @@ describe('Unoptimized connector', function() {
});
describe('Memory connector with options', function() {
let ds, savedOptions = {}, Post;
const savedOptions = {};
let ds, Post;
before(function() {
ds = new DataSource({connector: 'memory'});

View File

@ -143,8 +143,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
it('triggers the loaded hook multiple times when multiple instances exist when near filter is used',
function(done) {
let hookMonitorGeoModel;
hookMonitorGeoModel = new HookMonitor({includeModelName: false});
const hookMonitorGeoModel = new HookMonitor({includeModelName: false});
function monitorHookExecutionGeoModel(hookNames) {
hookMonitorGeoModel.install(GeoModel, hookNames);

View File

@ -2784,7 +2784,8 @@ describe('relations', function() {
scope4.should.have.property('include', 'imageable');
});
let article, employee, pictures = [];
let article, employee;
const pictures = [];
it('should create polymorphic relation - article', function(done) {
Article.create({name: 'Article 1'}, function(err, a) {
if (err) return done(err);

View File

@ -9,7 +9,9 @@
/* global getSchema:false */
const should = require('./init.js');
let db = getSchema(), slave = getSchema(), Model, SlaveModel;
const db = getSchema();
const slave = getSchema();
let Model, SlaveModel;
describe('dataSource', function() {
it('should define Model', function() {

View File

@ -284,13 +284,13 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
verify();
});
var verify = function() {
function verify() {
Station.flagged.count(function(err, count) {
if (err) return done(err);
count.should.equal(2);
done();
});
};
}
});
it('should allow filtered updateAll', function(done) {
@ -300,13 +300,13 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
verify();
});
var verify = function() {
function verify() {
Station.flagged.count(function(err, count) {
if (err) return done(err);
count.should.equal(2);
done();
});
};
}
});
it('should allow filtered destroyAll', function(done) {
@ -315,7 +315,7 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
verify();
});
var verify = function() {
function verify() {
Station.ordered.count(function(err, count) {
if (err) return done(err);
count.should.equal(2);
@ -325,7 +325,7 @@ describe('scope - filtered count, updateAll and destroyAll', function() {
done();
});
});
};
}
});
});

View File

@ -10,7 +10,8 @@
const should = require('./init.js');
const async = require('async');
let j = require('../'), db, User;
const j = require('../');
let db, User;
const ValidationError = j.ValidationError;
function getValidAttributes() {
@ -1521,7 +1522,7 @@ describe('validations', function() {
});
});
var empData = [{
const empData = [{
id: 1,
name: 'Foo',
age: 1,