Merge pull request #1242 from strongloop/upgrade/eslint-config

Upgrade eslint-config, fix new violations
This commit is contained in:
Miroslav Bajtoš 2017-02-01 16:34:32 +01:00 committed by GitHub
commit c509a9f7fe
14 changed files with 54 additions and 57 deletions

View File

@ -41,5 +41,5 @@ console.log(modelBuilder.models);
console.log(modelBuilder.definitions); console.log(modelBuilder.definitions);
User.mixin(Group); User.mixin(Group);
var user = new User({name: 'Ray', group: 'Admin'}); user = new User({name: 'Ray', group: 'Admin'});
console.log(user); console.log(user);

View File

@ -28,13 +28,13 @@ function loadSchemasSync(schemaFile, dataSource) {
var models = loadSchemasSync(path.join(__dirname, 'jdb-schemas.json')); var models = loadSchemasSync(path.join(__dirname, 'jdb-schemas.json'));
for (var s in models) { for (const s in models) {
var m = models[s]; const m = models[s];
console.log(m.modelName, new m()); console.log(m.modelName, new m());
} }
models = loadSchemasSync(path.join(__dirname, 'schemas.json')); models = loadSchemasSync(path.join(__dirname, 'schemas.json'));
for (var s in models) { for (const s in models) {
var m = models[s]; const m = models[s];
console.log(m.modelName, new m()); console.log(m.modelName, new m());
} }

View File

@ -104,7 +104,6 @@ function(modelName, key, options, callback) {
KeyValueMemoryConnector.prototype.set = KeyValueMemoryConnector.prototype.set =
function(modelName, key, value, options, callback) { function(modelName, key, value, options, callback) {
var store = this._getStoreForModel(modelName); var store = this._getStoreForModel(modelName);
var value;
if (Buffer.isBuffer(value)) { if (Buffer.isBuffer(value)) {
value = 'buffer:' + value.toString('base64'); value = 'buffer:' + value.toString('base64');
} else if (value instanceof Date) { } else if (value instanceof Date) {

View File

@ -589,9 +589,10 @@ function applyFilter(filter) {
return true; return true;
} }
var i;
if (example.inq) { if (example.inq) {
// if (!value) return false; // if (!value) return false;
for (var i = 0; i < example.inq.length; i++) { for (i = 0; i < example.inq.length; i++) {
if (example.inq[i] == value) { if (example.inq[i] == value) {
return true; return true;
} }
@ -600,7 +601,7 @@ function applyFilter(filter) {
} }
if (example.nin) { if (example.nin) {
for (var i = 0; i < example.nin.length; i++) { for (i = 0; i < example.nin.length; i++) {
if (example.nin[i] == value) { if (example.nin[i] == value) {
return false; return false;
} }

View File

@ -2176,13 +2176,6 @@ DataAccessObject.destroyAll = function destroyAll(where, options, cb) {
this.applyScope(query); this.applyScope(query);
where = query.where; where = query.where;
var context = {
Model: Model,
where: whereIsEmpty(where) ? {} : where,
hookState: hookState,
options: options,
};
if (options.notify === false) { if (options.notify === false) {
doDelete(where); doDelete(where);
} else { } else {
@ -2209,6 +2202,13 @@ DataAccessObject.destroyAll = function destroyAll(where, options, cb) {
} }
function doDelete(where) { function doDelete(where) {
var context = {
Model: Model,
where: whereIsEmpty(where) ? {} : where,
hookState: hookState,
options: options,
};
if (whereIsEmpty(where)) { if (whereIsEmpty(where)) {
if (connector.destroyAll.length === 4) { if (connector.destroyAll.length === 4) {
connector.destroyAll(Model.modelName, {}, options, done); connector.destroyAll(Model.modelName, {}, options, done);
@ -2918,8 +2918,9 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
var connector = this.getConnector(); var connector = this.getConnector();
var err;
if (typeof connector.replaceById !== 'function') { if (typeof connector.replaceById !== 'function') {
var err = new Error(g.f( err = new Error(g.f(
'The connector %s does not support {{replaceById}} operation. This is not a bug in LoopBack. ' + 'The connector %s does not support {{replaceById}} operation. This is not a bug in LoopBack. ' +
'Please contact the authors of the connector, preferably via GitHub issues.', 'Please contact the authors of the connector, preferably via GitHub issues.',
connector.name)); connector.name));
@ -2945,7 +2946,7 @@ DataAccessObject.replaceById = function(id, data, options, cb) {
var hookState = {}; var hookState = {};
if (id !== data[pkName]) { if (id !== data[pkName]) {
var err = new Error(g.f('{{id}} property (%s) ' + err = new Error(g.f('{{id}} property (%s) ' +
'cannot be updated from %s to %s', pkName, id, data[pkName])); 'cannot be updated from %s to %s', pkName, id, data[pkName]));
err.statusCode = 400; err.statusCode = 400;
process.nextTick(function() { cb(err); }); process.nextTick(function() { cb(err); });

View File

@ -21,7 +21,7 @@ function List(items, itemType, parent) {
try { try {
items = JSON.parse(items); items = JSON.parse(items);
} catch (e) { } catch (e) {
var err = new Error(g.f('could not create List from JSON string: %j', items)); const err = new Error(g.f('could not create List from JSON string: %j', items));
err.statusCode = 400; err.statusCode = 400;
throw err; throw err;
} }
@ -32,7 +32,7 @@ function List(items, itemType, parent) {
items = items || []; items = items || [];
if (!Array.isArray(items)) { if (!Array.isArray(items)) {
var err = new Error(g.f('Items must be an array: %j', items)); const err = new Error(g.f('Items must be an array: %j', items));
err.statusCode = 400; err.statusCode = 400;
throw err; throw err;
} }

View File

@ -3,9 +3,7 @@
// This file is licensed under the MIT License. // This file is licensed under the MIT License.
// License text available at https://opensource.org/licenses/MIT // License text available at https://opensource.org/licenses/MIT
// Turning on strict for this file breaks lots of test cases; 'use strict';
// disabling strict for this file
/* eslint-disable strict */
/*! /*!
* Dependencies * Dependencies
@ -888,12 +886,13 @@ var throughKeys = function(definition) {
var modelThrough = definition.modelThrough; var modelThrough = definition.modelThrough;
var pk2 = definition.modelTo.definition.idName(); var pk2 = definition.modelTo.definition.idName();
let fk1, fk2;
if (typeof definition.polymorphic === 'object') { // polymorphic if (typeof definition.polymorphic === 'object') { // polymorphic
var fk1 = definition.keyTo; fk1 = definition.keyTo;
if (definition.polymorphic.invert) { if (definition.polymorphic.invert) {
var fk2 = definition.polymorphic.foreignKey; fk2 = definition.polymorphic.foreignKey;
} else { } else {
var fk2 = definition.keyThrough; fk2 = definition.keyThrough;
} }
} else if (definition.modelFrom === definition.modelTo) { } else if (definition.modelFrom === definition.modelTo) {
return findBelongsTo(modelThrough, definition.modelTo, pk2). return findBelongsTo(modelThrough, definition.modelTo, pk2).
@ -904,9 +903,9 @@ var throughKeys = function(definition) {
return (definition.keyTo === fk1) ? -1 : 1; return (definition.keyTo === fk1) ? -1 : 1;
}); });
} else { } else {
var fk1 = findBelongsTo(modelThrough, definition.modelFrom, fk1 = findBelongsTo(modelThrough, definition.modelFrom,
definition.keyFrom)[0]; definition.keyFrom)[0];
var fk2 = findBelongsTo(modelThrough, definition.modelTo, pk2)[0]; fk2 = findBelongsTo(modelThrough, definition.modelTo, pk2)[0];
} }
return [fk1, fk2]; return [fk1, fk2];
}; };
@ -2192,7 +2191,7 @@ EmbedsOne.prototype.create = function(targetModelData, options, cb) {
}); });
} }
var err = inst.isValid() ? null : new ValidationError(inst); err = inst.isValid() ? null : new ValidationError(inst);
if (err) { if (err) {
process.nextTick(function() { process.nextTick(function() {
cb(err); cb(err);
@ -2411,11 +2410,9 @@ RelationDefinition.embedsMany = function embedsMany(modelFrom, modelTo, params)
hasErrors = true; hasErrors = true;
var id = item[idName]; var id = item[idName];
var first = Object.keys(item.errors)[0]; var first = Object.keys(item.errors)[0];
if (id) { let msg = id ?
var msg = 'contains invalid item: `' + id + '`'; 'contains invalid item: `' + id + '`' :
} else { 'contains invalid item at index `' + idx + '`';
var msg = 'contains invalid item at index `' + idx + '`';
}
msg += ' (`' + first + '` ' + item.errors[first] + ')'; msg += ' (`' + first + '` ' + item.errors[first] + ')';
self.errors.add(propertyName, msg, 'invalid'); self.errors.add(propertyName, msg, 'invalid');
} }
@ -2659,7 +2656,7 @@ EmbedsMany.prototype.updateById = function(fkId, data, options, cb) {
inst.setAttributes(data); inst.setAttributes(data);
var err = inst.isValid() ? null : new ValidationError(inst); err = inst.isValid() ? null : new ValidationError(inst);
if (err && typeof cb === 'function') { if (err && typeof cb === 'function') {
return process.nextTick(function() { return process.nextTick(function() {
cb(err, inst); cb(err, inst);
@ -2836,7 +2833,7 @@ EmbedsMany.prototype.create = function(targetModelData, options, cb) {
updateEmbedded(cb); updateEmbedded(cb);
}); });
} else { } else {
var err = inst.isValid() ? null : new ValidationError(inst); const err = inst.isValid() ? null : new ValidationError(inst);
if (err) { if (err) {
process.nextTick(function() { process.nextTick(function() {
cb(err); cb(err);
@ -2931,11 +2928,11 @@ EmbedsMany.prototype.add = function(acInst, data, options, cb) {
var modelTo = this.definition.modelTo; var modelTo = this.definition.modelTo;
var modelInstance = this.modelInstance; var modelInstance = this.modelInstance;
var options = definition.options; var defOpts = definition.options;
var belongsTo = options.belongsTo && modelTo.relations[options.belongsTo]; var belongsTo = defOpts.belongsTo && modelTo.relations[defOpts.belongsTo];
if (!belongsTo) { if (!belongsTo) {
throw new Error('Invalid reference: ' + options.belongsTo || '(none)'); throw new Error('Invalid reference: ' + defOpts.belongsTo || '(none)');
} }
var fk2 = belongsTo.keyTo; var fk2 = belongsTo.keyTo;
@ -2952,7 +2949,7 @@ EmbedsMany.prototype.add = function(acInst, data, options, cb) {
belongsTo.modelTo.findOne(filter, options, function(err, ref) { belongsTo.modelTo.findOne(filter, options, function(err, ref) {
if (ref instanceof belongsTo.modelTo) { if (ref instanceof belongsTo.modelTo) {
var inst = self.build(data || {}); var inst = self.build(data || {});
inst[options.belongsTo](ref); inst[defOpts.belongsTo](ref);
modelInstance.save(function(err) { modelInstance.save(function(err) {
cb(err, err ? null : inst); cb(err, err ? null : inst);
}); });
@ -2978,11 +2975,11 @@ EmbedsMany.prototype.remove = function(acInst, options, cb) {
var modelTo = this.definition.modelTo; var modelTo = this.definition.modelTo;
var modelInstance = this.modelInstance; var modelInstance = this.modelInstance;
var options = definition.options; var defOpts = definition.options;
var belongsTo = options.belongsTo && modelTo.relations[options.belongsTo]; var belongsTo = defOpts.belongsTo && modelTo.relations[defOpts.belongsTo];
if (!belongsTo) { if (!belongsTo) {
throw new Error('Invalid reference: ' + options.belongsTo || '(none)'); throw new Error('Invalid reference: ' + defOpts.belongsTo || '(none)');
} }
var fk2 = belongsTo.keyTo; var fk2 = belongsTo.keyTo;

View File

@ -116,7 +116,7 @@ function mergeIncludes(destination, source) {
*/ */
function convertToArray(include) { function convertToArray(include) {
if (typeof include === 'string') { if (typeof include === 'string') {
var obj = {}; const obj = {};
obj[include] = true; obj[include] = true;
return [obj]; return [obj];
} else if (isPlainObject(include)) { } else if (isPlainObject(include)) {
@ -127,7 +127,7 @@ function convertToArray(include) {
// Build an array of key/value pairs // Build an array of key/value pairs
var newInclude = []; var newInclude = [];
for (var key in include) { for (var key in include) {
var obj = {}; const obj = {};
obj[key] = include[key]; obj[key] = include[key];
newInclude.push(obj); newInclude.push(obj);
} }
@ -137,7 +137,7 @@ function convertToArray(include) {
for (var i in include) { for (var i in include) {
var includeEntry = include[i]; var includeEntry = include[i];
if (typeof includeEntry === 'string') { if (typeof includeEntry === 'string') {
var obj = {}; const obj = {};
obj[includeEntry] = true; obj[includeEntry] = true;
normalized.push(obj); normalized.push(obj);
} else { } else {

View File

@ -33,7 +33,7 @@
"devDependencies": { "devDependencies": {
"async-iterators": "^0.2.2", "async-iterators": "^0.2.2",
"eslint": "^3.12.2", "eslint": "^3.12.2",
"eslint-config-loopback": "^7.0.1", "eslint-config-loopback": "^8.0.0",
"mocha": "^3.2.0", "mocha": "^3.2.0",
"should": "^8.4.0" "should": "^8.4.0"
}, },

View File

@ -561,7 +561,7 @@ describe('include', function() {
posts[1].title.should.equal('Post B'); posts[1].title.should.equal('Post B');
posts[2].title.should.equal('Post A'); posts[2].title.should.equal('Post A');
var posts = users[1].posts(); posts = users[1].posts();
posts.should.be.an.array; posts.should.be.an.array;
posts.should.have.length(1); posts.should.have.length(1);
posts[0].title.should.equal('Post D'); posts[0].title.should.equal('Post D');

View File

@ -48,7 +48,7 @@ module.exports = function(dataSource, should, connectorCapabilities) {
} }
}); });
var ownerInstance, existingInstance, existingItem, existingItem; var ownerInstance, existingInstance, existingItem;
beforeEach(function setupData() { beforeEach(function setupData() {
return Owner.create({}) return Owner.create({})
.then(function(inst) { .then(function(inst) {

View File

@ -2512,7 +2512,6 @@ module.exports = function(dataSource, should, connectorCapabilities) {
var expectedContext = aCtxForModel(TestModel, expected); var expectedContext = aCtxForModel(TestModel, expected);
var expectedContext;
if (!dataSource.connector.replaceOrCreate) { if (!dataSource.connector.replaceOrCreate) {
expectedContext.isNewInstance = false; expectedContext.isNewInstance = false;
} }

View File

@ -3729,7 +3729,7 @@ describe('relations', function() {
Person.findById(personId, function(err, p) { Person.findById(personId, function(err, p) {
p.passportItem.update({name: 'Freddy'}, function(err, passport) { p.passportItem.update({name: 'Freddy'}, function(err, passport) {
should.not.exist(err); should.not.exist(err);
var passport = p.passportItem(); passport = p.passportItem();
passport.toObject().should.eql({name: 'Freddy'}); passport.toObject().should.eql({name: 'Freddy'});
passport.should.be.an.instanceOf(Passport); passport.should.be.an.instanceOf(Passport);
passport.should.equal(p.passport); passport.should.equal(p.passport);
@ -3841,7 +3841,7 @@ describe('relations', function() {
.then(function(p) { .then(function(p) {
return p.passportItem.update({name: 'Jason'}) return p.passportItem.update({name: 'Jason'})
.then(function(passport) { .then(function(passport) {
var passport = p.passportItem(); passport = p.passportItem();
passport.toObject().should.eql({name: 'Jason'}); passport.toObject().should.eql({name: 'Jason'});
passport.should.be.an.instanceOf(Passport); passport.should.be.an.instanceOf(Passport);
passport.should.equal(p.passport); passport.should.equal(p.passport);
@ -4622,7 +4622,7 @@ describe('relations', function() {
if (err) return done(err); if (err) return done(err);
var link = cat.items.build(); var link = cat.items.build();
link.job(job1); link.job(job1);
var link = cat.items.build(); link = cat.items.build();
link.job(job2); link.job(job2);
cat.save(function(err, cat) { cat.save(function(err, cat) {
if (err) return done(err); if (err) return done(err);
@ -4631,7 +4631,7 @@ describe('relations', function() {
job.should.not.have.property('jobId'); job.should.not.have.property('jobId');
job.id.should.eql(job1.id); job.id.should.eql(job1.id);
job.name.should.equal(job1.name); job.name.should.equal(job1.name);
var job = cat.items.at(1); job = cat.items.at(1);
job.id.should.eql(job2.id); job.id.should.eql(job2.id);
job.name.should.equal(job2.name); job.name.should.equal(job2.name);
done(); done();
@ -4882,7 +4882,7 @@ describe('relations', function() {
Book.create({name: 'Book'}, function(err, book) { Book.create({name: 'Book'}, function(err, book) {
var link = book.people.build({notes: 'Something ...'}); var link = book.people.build({notes: 'Something ...'});
link.linked(person1); link.linked(person1);
var link = book.people.build(); link = book.people.build();
link.linked(person2); link.linked(person2);
book.save(function(err, book) { book.save(function(err, book) {
should.not.exist(err); should.not.exist(err);
@ -4894,7 +4894,7 @@ describe('relations', function() {
link.linkedType.should.equal('Author'); link.linkedType.should.equal('Author');
link.name.should.equal('Author 1'); link.name.should.equal('Author 1');
var link = book.people.at(1); link = book.people.at(1);
link.should.be.instanceof(Link); link.should.be.instanceof(Link);
link.id.should.equal(2); link.id.should.equal(2);
link.linkedId.should.eql(person2.id); link.linkedId.should.eql(person2.id);
@ -4917,7 +4917,7 @@ describe('relations', function() {
link.linkedType.should.equal('Author'); link.linkedType.should.equal('Author');
link.notes.should.equal('Something ...'); link.notes.should.equal('Something ...');
var link = book.people.at(1); link = book.people.at(1);
link.should.be.instanceof(Link); link.should.be.instanceof(Link);
link.id.should.equal(2); link.id.should.equal(2);
link.linkedId.should.eql(person2.id); link.linkedId.should.eql(person2.id);

View File

@ -399,7 +399,7 @@ describe('validations', function() {
u.isValid().should.not.be.true; u.isValid().should.not.be.true;
u.reserved = null; u.reserved = null;
u.isValid().should.be.true; u.isValid().should.be.true;
var u = new User({reserved: 'foo', locked: false}); u = new User({reserved: 'foo', locked: false});
u.isValid().should.be.true; u.isValid().should.be.true;
}); });
}); });