Skip to content

Commit

Permalink
manually fix remaining problems
Browse files Browse the repository at this point in the history
  • Loading branch information
bajtos committed Dec 7, 2018
1 parent 422ec9a commit 9e0f624
Show file tree
Hide file tree
Showing 25 changed files with 91 additions and 82 deletions.
11 changes: 5 additions & 6 deletions lib/connectors/kv-memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions lib/connectors/memory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, ' ');
Expand All @@ -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',
Expand Down
3 changes: 2 additions & 1 deletion lib/connectors/transient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
14 changes: 8 additions & 6 deletions lib/dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion lib/datasource.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions lib/geo.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -41,10 +45,6 @@ exports.nearFilter = function nearFilter(where) {
}
});
}
var nearResults = [];
nearSearch(where);

return (!nearResults.length ? false : nearResults);
};

/*!
Expand Down
6 changes: 4 additions & 2 deletions lib/include.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"',

This comment has been minimized.

Copy link
@3z3qu13l

3z3qu13l Dec 14, 2018

Template string would help

This comment has been minimized.

Copy link
@bajtos

bajtos Dec 14, 2018

Author Member

Unfortunately, template strings are not supported by strong-globalize yet. See strongloop/strong-globalize#112

Would you like to contribute support for template strings yourself?

modelToIdName
));
return next(err);
}
const objList = targetObjsMap[targetId.toString()];
Expand Down
23 changes: 10 additions & 13 deletions lib/model-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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() {
Expand All @@ -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++) {

This comment has been minimized.

Copy link
@3z3qu13l

3z3qu13l Dec 14, 2018

Why const l232 and let here ?
if iterator isn't modified inside the loop, const should be ok

This comment has been minimized.

Copy link
@bajtos

bajtos Dec 14, 2018

Author Member

Most likely an oversight on my side and/or eslint auto-fixer was not able to prove that i is constant. Feel free to send a pull request to fix this.

p = idNames[i];
compositeId[p] = this.__data[p];
}
Expand All @@ -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') {
Expand Down Expand Up @@ -624,16 +624,16 @@ 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);
}

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 = {};
Expand Down Expand Up @@ -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);
}
Expand Down
12 changes: 6 additions & 6 deletions lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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') {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions lib/relation-definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,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;
}

/**
Expand Down
7 changes: 4 additions & 3 deletions lib/scope.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions lib/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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 || {});

Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -894,7 +895,7 @@ function ValidationError(obj) {

util.inherits(ValidationError, Error);

var errorHasStackProperty = !!(new Error).stack;
const errorHasStackProperty = !!(new Error).stack;

ValidationError.maxPropertyStringLength = 32;

Expand Down
12 changes: 6 additions & 6 deletions test/datasource.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 9e0f624

Please sign in to comment.