From 6dd98c828f8740a69f90f6863c6bcedb4b5e0ed2 Mon Sep 17 00:00:00 2001 From: Valeri Karpov Date: Thu, 13 Sep 2018 17:56:44 -0400 Subject: [PATCH] style: fix lint --- lib/model.js | 6 +++--- lib/types/array.js | 4 ++-- lib/utils.js | 12 ++++++------ test/aggregate.test.js | 8 +++----- test/collection.capped.test.js | 11 +++++++---- test/collection.test.js | 4 ++-- test/colors.js | 9 ++++++++- test/webpack.test.js | 1 - 8 files changed, 31 insertions(+), 24 deletions(-) diff --git a/lib/model.js b/lib/model.js index aca9f9faf13..93f8df3c150 100644 --- a/lib/model.js +++ b/lib/model.js @@ -1027,12 +1027,12 @@ Model.init = function init(callback) { * schema. This function will drop any indexes that are not defined in * the model's schema except the `_id` index, and build any indexes that * are in your schema but not in MongoDB. - * + * * See the [introductory blog post](http://thecodebarbarian.com/whats-new-in-mongoose-5-2-syncindexes) * for more information. - * + * * ####Example: - * + * * const schema = new Schema({ name: { type: String, unique: true } }); * const Customer = mongoose.model('Customer', schema); * await Customer.createIndex({ age: 1 }); // Index is not in schema diff --git a/lib/types/array.js b/lib/types/array.js index 4781f83cbd1..dbe43d79da6 100644 --- a/lib/types/array.js +++ b/lib/types/array.js @@ -142,8 +142,8 @@ MongooseArray.mixin = { */ _markModified: function(elem, embeddedPath) { - let parent = this._parent, - dirtyPath; + const parent = this._parent; + let dirtyPath; if (parent) { dirtyPath = this._path; diff --git a/lib/utils.js b/lib/utils.js index d5a2c5cee7d..5e9c04e4605 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -296,9 +296,9 @@ function cloneArray(arr, options) { */ exports.options = function(defaults, options) { - let keys = Object.keys(defaults), - i = keys.length, - k; + const keys = Object.keys(defaults); + let i = keys.length; + let k; options = options || {}; @@ -670,9 +670,9 @@ exports.setValue = function(path, val, obj, map, _copying) { exports.object = {}; exports.object.vals = function vals(o) { - let keys = Object.keys(o), - i = keys.length, - ret = []; + const keys = Object.keys(o); + let i = keys.length; + const ret = []; while (i--) { ret.push(o[keys[i]]); diff --git a/test/aggregate.test.js b/test/aggregate.test.js index c064bf54756..a59f920f171 100644 --- a/test/aggregate.test.js +++ b/test/aggregate.test.js @@ -4,9 +4,9 @@ * Module dependencies */ +const assert = require('assert'); const co = require('co'); const start = require('./common'); -const assert = require('power-assert'); const mongoose = start.mongoose; const Schema = mongoose.Schema; @@ -635,11 +635,10 @@ describe('aggregate: ', function() { model(db.model('Employee')). group({ _id: '$dept' }). exec(function(err, docs) { - let depts; assert.ifError(err); assert.equal(docs.length, 2); - depts = docs.map(function(doc) { + const depts = docs.map(function(doc) { return doc._id; }); assert.notEqual(depts.indexOf('sales'), -1); @@ -918,10 +917,9 @@ describe('aggregate: ', function() { it('with a callback', function(done) { const aggregate = new Aggregate(); - let callback; aggregate.model(db.model('Employee')); - callback = function(err) { + const callback = function(err) { assert.ok(err); assert.equal(err.message, 'Aggregate has empty pipeline'); done(); diff --git a/test/collection.capped.test.js b/test/collection.capped.test.js index 961440ea6c1..06b48fc66a9 100644 --- a/test/collection.capped.test.js +++ b/test/collection.capped.test.js @@ -4,7 +4,12 @@ 'use strict'; -let start = require('./common'), mongoose = start.mongoose, assert = require('power-assert'), Schema = mongoose.Schema, random = require('../lib/utils').random; +const assert = require('assert'); +const random = require('../lib/utils').random; +const start = require('./common'); + +const mongoose = start.mongoose; +const Schema = mongoose.Schema; /** * setup @@ -71,8 +76,6 @@ describe('collections: capped:', function() { } assert.ifError(err); - let timer; - db.on('error', function(err1) { clearTimeout(timer); db.close(); @@ -81,7 +84,7 @@ describe('collections: capped:', function() { }); db.model('CappedExisting', capped, conn); - timer = setTimeout(function() { + const timer = setTimeout(function() { db.close(); throw new Error('capped test timeout'); }, 900); diff --git a/test/collection.test.js b/test/collection.test.js index 49e3aa65b9a..09408dd3c82 100644 --- a/test/collection.test.js +++ b/test/collection.test.js @@ -38,8 +38,8 @@ describe('collections:', function() { }); it('methods should that throw (unimplemented)', function(done) { - let collection = new Collection('test', mongoose.connection), - thrown = false; + const collection = new Collection('test', mongoose.connection); + let thrown = false; try { collection.getIndexes(); diff --git a/test/colors.js b/test/colors.js index dc4a295de5f..498e103cdbf 100644 --- a/test/colors.js +++ b/test/colors.js @@ -4,7 +4,14 @@ 'use strict'; -let start = require('./common'), mongoose = start.mongoose, assert = require('power-assert'), Schema = mongoose.Schema, MongooseDocumentArray = mongoose.Types.DocumentArray, EmbeddedDocument = require('../lib/types/embedded'), DocumentArray = require('../lib/types/documentarray'); +const DocumentArray = require('../lib/types/documentarray'); +const EmbeddedDocument = require('../lib/types/embedded'); +const assert = require('assert'); +const start = require('./common'); + +const mongoose = start.mongoose; +const Schema = mongoose.Schema; +const MongooseDocumentArray = mongoose.Types.DocumentArray; /** * setup diff --git a/test/webpack.test.js b/test/webpack.test.js index ca999a5dd76..6ea6b61e7ee 100644 --- a/test/webpack.test.js +++ b/test/webpack.test.js @@ -3,7 +3,6 @@ const acorn = require('acorn'); const assert = require('assert'); const fs = require('fs'); -const path = require('path'); const utils = require('../lib/utils'); const semver = require('semver');