From e5d2cd0322fb38b13e6e3d588601cb1c29a823bd Mon Sep 17 00:00:00 2001 From: simon Date: Mon, 21 Dec 2020 10:25:06 +0100 Subject: [PATCH] lint: lint all test files --- test/docs/custom-casting.test.js | 6 +- test/docs/date.test.js | 6 +- test/docs/defaults.test.js | 10 ++-- test/docs/discriminators.test.js | 85 +++++++++++++++-------------- test/docs/promises.test.js | 46 ++++++++-------- test/docs/schemas.test.js | 4 +- test/docs/schematypes.test.js | 4 +- test/docs/validation.test.js | 12 ++-- test/typescript/aggregate.ts | 8 +-- test/typescript/base.ts | 8 +-- test/typescript/collection.ts | 10 ++-- test/typescript/connectSyntax.ts | 4 +- test/typescript/discriminator.ts | 28 +++++----- test/typescript/methods.ts | 6 +- test/typescript/middleware.ts | 3 +- test/typescript/modelInheritance.ts | 4 +- test/typescript/models.ts | 22 ++++---- test/typescript/queries.ts | 4 +- test/typescript/querycursor.ts | 4 +- test/typescript/subdocuments.ts | 8 +-- 20 files changed, 142 insertions(+), 140 deletions(-) diff --git a/test/docs/custom-casting.test.js b/test/docs/custom-casting.test.js index e55d02da9bf..bd9d8484702 100644 --- a/test/docs/custom-casting.test.js +++ b/test/docs/custom-casting.test.js @@ -10,7 +10,7 @@ describe('custom casting', function() { beforeEach(function() { originalCast = mongoose.Number.cast(); - }) + }); afterEach(function() { mongoose.deleteModel('Test'); @@ -60,5 +60,5 @@ describe('custom casting', function() { assert.ifError(err); assert.equal(doc.age, 2); // acquit:ignore:end - }); -}); \ No newline at end of file + }); +}); diff --git a/test/docs/date.test.js b/test/docs/date.test.js index 14ffdbca98b..de689f69ce2 100644 --- a/test/docs/date.test.js +++ b/test/docs/date.test.js @@ -6,7 +6,7 @@ const start = require('../common'); describe('Date Tutorial', function() { let User; - let db; + // let db; const mongoose = new start.mongoose.Mongoose(); @@ -43,7 +43,7 @@ describe('Date Tutorial', function() { user.validateSync().errors['lastActiveAt']; // CastError // acquit:ignore:start assert.ok(!(user.lastActiveAt instanceof Date)); - assert.equal(user.validateSync().errors['lastActiveAt'].name, 'CastError') + assert.equal(user.validateSync().errors['lastActiveAt'].name, 'CastError'); // acquit:ignore:end }); @@ -159,4 +159,4 @@ describe('Date Tutorial', function() { assert.equal(user.lastActiveAt.toISOString(), '2019-03-10T23:44:56.289Z'); // acquit:ignore:end }); -}); \ No newline at end of file +}); diff --git a/test/docs/defaults.test.js b/test/docs/defaults.test.js index b92cf4cf307..05c4bba9dff 100644 --- a/test/docs/defaults.test.js +++ b/test/docs/defaults.test.js @@ -3,7 +3,7 @@ const assert = require('assert'); const mongoose = require('../../'); -describe('defaults docs', function () { +describe('defaults docs', function() { let db; const Schema = mongoose.Schema; @@ -76,7 +76,7 @@ describe('defaults docs', function () { const BlogPost = db.model('BlogPost', schema); - const post = new BlogPost({title: '5 Best Arnold Schwarzenegger Movies'}); + const post = new BlogPost({ title: '5 Best Arnold Schwarzenegger Movies' }); // The post has a default Date set to now assert.ok(post.date.getTime() >= Date.now() - 1000); @@ -99,13 +99,13 @@ describe('defaults docs', function () { it('The `setDefaultsOnInsert` option', function(done) { const schema = new Schema({ title: String, - genre: {type: String, default: 'Action'} + genre: { type: String, default: 'Action' } }); const Movie = db.model('Movie', schema); const query = {}; - const update = {title: 'The Terminator'}; + const update = { title: 'The Terminator' }; const options = { // Return the document after updates are applied new: true, @@ -116,7 +116,7 @@ describe('defaults docs', function () { }; Movie. - findOneAndUpdate(query, update, options, function (error, doc) { + findOneAndUpdate(query, update, options, function(error, doc) { assert.ifError(error); assert.equal(doc.title, 'The Terminator'); assert.equal(doc.genre, 'Action'); diff --git a/test/docs/discriminators.test.js b/test/docs/discriminators.test.js index 5c9793e93e4..e05c186a1cf 100644 --- a/test/docs/discriminators.test.js +++ b/test/docs/discriminators.test.js @@ -5,28 +5,28 @@ const mongoose = require('../../'); const Schema = mongoose.Schema; -describe('discriminator docs', function () { +describe('discriminator docs', function() { let Event; let ClickedLinkEvent; let SignedUpEvent; let db; - before(function (done) { + before(function(done) { db = mongoose.createConnection('mongodb://localhost:27017/mongoose_test'); - const eventSchema = new mongoose.Schema({time: Date}); + const eventSchema = new mongoose.Schema({ time: Date }); Event = db.model('_event', eventSchema); ClickedLinkEvent = Event.discriminator('ClickedLink', - new mongoose.Schema({url: String})); + new mongoose.Schema({ url: String })); SignedUpEvent = Event.discriminator('SignedUp', - new mongoose.Schema({username: String})); + new mongoose.Schema({ username: String })); done(); }); - after(function (done) { + after(function(done) { db.close(done); }); @@ -47,24 +47,24 @@ describe('discriminator docs', function () { * key (defaults to the model name). It returns a model whose schema * is the union of the base schema and the discriminator schema. */ - it('The `model.discriminator()` function', function (done) { - const options = {discriminatorKey: 'kind'}; + it('The `model.discriminator()` function', function(done) { + const options = { discriminatorKey: 'kind' }; - const eventSchema = new mongoose.Schema({time: Date}, options); + const eventSchema = new mongoose.Schema({ time: Date }, options); const Event = mongoose.model('Event', eventSchema); // ClickedLinkEvent is a special type of Event that has // a URL. const ClickedLinkEvent = Event.discriminator('ClickedLink', - new mongoose.Schema({url: String}, options)); + new mongoose.Schema({ url: String }, options)); // When you create a generic event, it can't have a URL field... - const genericEvent = new Event({time: Date.now(), url: 'google.com'}); + const genericEvent = new Event({ time: Date.now(), url: 'google.com' }); assert.ok(!genericEvent.url); // But a ClickedLinkEvent can const clickedEvent = - new ClickedLinkEvent({time: Date.now(), url: 'google.com'}); + new ClickedLinkEvent({ time: Date.now(), url: 'google.com' }); assert.ok(clickedEvent.url); // acquit:ignore:start @@ -78,16 +78,17 @@ describe('discriminator docs', function () { * stored in the same collection as generic events and `ClickedLinkEvent` * instances. */ - it('Discriminators save to the Event model\'s collection', function (done) { - const event1 = new Event({time: Date.now()}); - const event2 = new ClickedLinkEvent({time: Date.now(), url: 'google.com'}); - const event3 = new SignedUpEvent({time: Date.now(), user: 'testuser'}); - - const save = function (doc, callback) { - doc.save(function (error, doc) { + it('Discriminators save to the Event model\'s collection', function(done) { + const event1 = new Event({ time: Date.now() }); + const event2 = new ClickedLinkEvent({ time: Date.now(), url: 'google.com' }); + const event3 = new SignedUpEvent({ time: Date.now(), user: 'testuser' }); + + /* + const save = function(doc, callback) { + doc.save(function(error, doc) { callback(error, doc); }); - }; + }; */ Promise.all([event1.save(), event2.save(), event3.save()]). then(() => Event.countDocuments()). @@ -106,10 +107,10 @@ describe('discriminator docs', function () { * to your schemas that it uses to track which discriminator * this document is an instance of. */ - it('Discriminator keys', function (done) { - const event1 = new Event({time: Date.now()}); - const event2 = new ClickedLinkEvent({time: Date.now(), url: 'google.com'}); - const event3 = new SignedUpEvent({time: Date.now(), user: 'testuser'}); + it('Discriminator keys', function(done) { + const event1 = new Event({ time: Date.now() }); + const event2 = new ClickedLinkEvent({ time: Date.now(), url: 'google.com' }); + const event3 = new SignedUpEvent({ time: Date.now(), user: 'testuser' }); assert.ok(!event1.__t); assert.equal(event2.__t, 'ClickedLink'); @@ -125,10 +126,10 @@ describe('discriminator docs', function () { * to queries. In other words, `find()`, `count()`, `aggregate()`, etc. * are smart enough to account for discriminators. */ - it('Discriminators add the discriminator key to queries', function (done) { - const event1 = new Event({time: Date.now()}); - const event2 = new ClickedLinkEvent({time: Date.now(), url: 'google.com'}); - const event3 = new SignedUpEvent({time: Date.now(), user: 'testuser'}); + it('Discriminators add the discriminator key to queries', function(done) { + const event1 = new Event({ time: Date.now() }); + const event2 = new ClickedLinkEvent({ time: Date.now(), url: 'google.com' }); + const event3 = new SignedUpEvent({ time: Date.now(), user: 'testuser' }); Promise.all([event1.save(), event2.save(), event3.save()]). then(() => ClickedLinkEvent.find({})). @@ -147,20 +148,20 @@ describe('discriminator docs', function () { * However, you can also attach middleware to the discriminator schema * without affecting the base schema. */ - it('Discriminators copy pre and post hooks', function (done) { - const options = {discriminatorKey: 'kind'}; + it('Discriminators copy pre and post hooks', function(done) { + const options = { discriminatorKey: 'kind' }; - const eventSchema = new mongoose.Schema({time: Date}, options); + const eventSchema = new mongoose.Schema({ time: Date }, options); let eventSchemaCalls = 0; - eventSchema.pre('validate', function (next) { + eventSchema.pre('validate', function(next) { ++eventSchemaCalls; next(); }); const Event = mongoose.model('GenericEvent', eventSchema); - const clickedLinkSchema = new mongoose.Schema({url: String}, options); + const clickedLinkSchema = new mongoose.Schema({ url: String }, options); let clickedSchemaCalls = 0; - clickedLinkSchema.pre('validate', function (next) { + clickedLinkSchema.pre('validate', function(next) { ++clickedSchemaCalls; next(); }); @@ -190,11 +191,11 @@ describe('discriminator docs', function () { * If a custom _id field is set on the base schema, that will always * override the discriminator's _id field, as shown below. */ - it('Handling custom _id fields', function (done) { - const options = {discriminatorKey: 'kind'}; + it('Handling custom _id fields', function(done) { + const options = { discriminatorKey: 'kind' }; // Base schema has a custom String `_id` and a Date `time`... - const eventSchema = new mongoose.Schema({_id: String, time: Date}, + const eventSchema = new mongoose.Schema({ _id: String, time: Date }, options); const Event = mongoose.model('BaseEvent', eventSchema); @@ -209,7 +210,7 @@ describe('discriminator docs', function () { const ClickedLinkEvent = Event.discriminator('ChildEventBad', clickedLinkSchema); - const event1 = new ClickedLinkEvent({_id: 'custom id', time: '4pm'}); + const event1 = new ClickedLinkEvent({ _id: 'custom id', time: '4pm' }); // clickedLinkSchema overwrites the `time` path, but **not** // the `_id` path. assert.strictEqual(typeof event1._id, 'string'); @@ -345,7 +346,7 @@ describe('discriminator docs', function () { const eventListSchema = new Schema({ events: [singleEventSchema] }); const subEventSchema = new Schema({ - sub_events: [singleEventSchema] + sub_events: [singleEventSchema] }, { _id: false }); const SubEvent = subEventSchema.path('sub_events'). @@ -357,8 +358,8 @@ describe('discriminator docs', function () { // Create a new batch of events with different kinds const list = { events: [ - { kind: 'SubEvent', sub_events: [{kind:'SubEvent', sub_events:[], message:'test1'}], message: 'hello' }, - { kind: 'SubEvent', sub_events: [{kind:'SubEvent', sub_events:[{kind:'SubEvent', sub_events:[], message:'test3'}], message:'test2'}], message: 'world' } + { kind: 'SubEvent', sub_events: [{ kind: 'SubEvent', sub_events: [], message: 'test1' }], message: 'hello' }, + { kind: 'SubEvent', sub_events: [{ kind: 'SubEvent', sub_events: [{ kind: 'SubEvent', sub_events: [], message: 'test3' }], message: 'test2' }], message: 'world' } ] }; @@ -374,7 +375,7 @@ describe('discriminator docs', function () { assert.equal(doc.events[1].message, 'world'); assert.ok(doc.events[1].sub_events[0].sub_events[0] instanceof SubEvent); - doc.events.push({kind:'SubEvent', sub_events:[{kind:'SubEvent', sub_events:[], message:'test4'}], message:'pushed'}); + doc.events.push({ kind: 'SubEvent', sub_events: [{ kind: 'SubEvent', sub_events: [], message: 'test4' }], message: 'pushed' }); return doc.save(); }). then(function(doc) { diff --git a/test/docs/promises.test.js b/test/docs/promises.test.js index c26b2a26e5e..6a76d3691cf 100644 --- a/test/docs/promises.test.js +++ b/test/docs/promises.test.js @@ -1,25 +1,25 @@ 'use strict'; -const PromiseProvider = require('../../lib/promise_provider'); +// const PromiseProvider = require('../../lib/promise_provider'); const assert = require('assert'); const mongoose = require('../../'); -describe('promises docs', function () { +describe('promises docs', function() { let Band; let db; - before(function (done) { + before(function(done) { db = mongoose.createConnection('mongodb://localhost:27017/mongoose_test'); - Band = db.model('band-promises', {name: String, members: [String]}); + Band = db.model('band-promises', { name: String, members: [String] }); done(); }); - beforeEach(function (done) { + beforeEach(function(done) { Band.deleteMany({}, done); }); - after(function (done) { + after(function(done) { db.close(done); }); @@ -28,21 +28,21 @@ describe('promises docs', function () { * This means that you can do things like `MyModel.findOne({}).then()` and * `await MyModel.findOne({}).exec()` if you're using * [async/await](http://thecodebarbarian.com/80-20-guide-to-async-await-in-node.js.html). - * + * * You can find the return type of specific operations [in the api docs](https://mongoosejs.com/docs/api.html) * You can also read more about [promises in Mongoose](https://masteringjs.io/tutorials/mongoose/promise). */ - it('Built-in Promises', function (done) { + it('Built-in Promises', function(done) { const gnr = new Band({ - name: "Guns N' Roses", + name: 'Guns N\' Roses', members: ['Axl', 'Slash'] }); const promise = gnr.save(); assert.ok(promise instanceof Promise); - promise.then(function (doc) { - assert.equal(doc.name, "Guns N' Roses"); + promise.then(function(doc) { + assert.equal(doc.name, 'Guns N\' Roses'); // acquit:ignore:start done(); // acquit:ignore:end @@ -55,8 +55,8 @@ describe('promises docs', function () { * a convenience. If you need * a fully-fledged promise, use the `.exec()` function. */ - it('Queries are not promises', function (done) { - const query = Band.findOne({name: "Guns N' Roses"}); + it('Queries are not promises', function(done) { + const query = Band.findOne({ name: 'Guns N\' Roses' }); assert.ok(!(query instanceof Promise)); // acquit:ignore:start @@ -64,7 +64,7 @@ describe('promises docs', function () { // acquit:ignore:end // A query is not a fully-fledged promise, but it does have a `.then()`. - query.then(function (doc) { + query.then(function(doc) { // use doc // acquit:ignore:start assert.ok(!doc); @@ -76,7 +76,7 @@ describe('promises docs', function () { const promise = query.exec(); assert.ok(promise instanceof Promise); - promise.then(function (doc) { + promise.then(function(doc) { // use doc // acquit:ignore:start assert.ok(!doc); @@ -90,8 +90,8 @@ describe('promises docs', function () { * That means they have a `.then()` function, so you can use queries as promises with either * promise chaining or [async await](https://asyncawait.net) */ - it('Queries are thenable', function (done) { - Band.findOne({name: "Guns N' Roses"}).then(function(doc) { + it('Queries are thenable', function(done) { + Band.findOne({ name: 'Guns N\' Roses' }).then(function(doc) { // use doc // acquit:ignore:start assert.ok(!doc); @@ -102,31 +102,31 @@ describe('promises docs', function () { /** * There are two alternatives for using `await` with queries: - * + * * - `await Band.findOne();` * - `await Band.findOne().exec();` - * + * * As far as functionality is concerned, these two are equivalent. * However, we recommend using `.exec()` because that gives you * better stack traces. */ it('Should You Use `exec()` With `await`?', function() { - + }); - + /** * If you're an advanced user, you may want to plug in your own promise * library like [bluebird](https://www.npmjs.com/package/bluebird). Just set * `mongoose.Promise` to your favorite * ES6-style promise constructor and mongoose will use it. */ - it('Plugging in your own Promises Library', function (done) { + it('Plugging in your own Promises Library', function(done) { // acquit:ignore:start if (!global.Promise) { return done(); } // acquit:ignore:end - const query = Band.findOne({name: "Guns N' Roses"}); + const query = Band.findOne({ name: 'Guns N\' Roses' }); // Use bluebird mongoose.Promise = require('bluebird'); diff --git a/test/docs/schemas.test.js b/test/docs/schemas.test.js index 8ae5ed59866..a2cad4f8c0e 100644 --- a/test/docs/schemas.test.js +++ b/test/docs/schemas.test.js @@ -3,9 +3,9 @@ const assert = require('assert'); const mongoose = require('../../'); -describe('Advanced Schemas', function () { +describe('Advanced Schemas', function() { let db; - let Schema = mongoose.Schema; + const Schema = mongoose.Schema; before(function() { db = mongoose.createConnection('mongodb://localhost:27017/mongoose_test'); diff --git a/test/docs/schematypes.test.js b/test/docs/schematypes.test.js index 77d32d9abf9..f3e454969b9 100644 --- a/test/docs/schematypes.test.js +++ b/test/docs/schematypes.test.js @@ -2,9 +2,9 @@ const assert = require('assert'); const mongoose = require('../../'); -describe('schemaTypes', function () { +describe('schemaTypes', function() { let db; - let Schema = mongoose.Schema; + const Schema = mongoose.Schema; before(function() { db = mongoose.createConnection('mongodb://localhost:27017/mongoose_test'); diff --git a/test/docs/validation.test.js b/test/docs/validation.test.js index 7e904526aa5..50d1268c9df 100644 --- a/test/docs/validation.test.js +++ b/test/docs/validation.test.js @@ -6,7 +6,7 @@ const Promise = global.Promise || require('bluebird'); describe('validation docs', function() { let db; - let Schema = mongoose.Schema; + const Schema = mongoose.Schema; before(function() { db = mongoose.createConnection('mongodb://localhost:27017/mongoose_test', { @@ -280,7 +280,7 @@ describe('validation docs', function() { const toy = new Toy({ color: 'Green', name: 'Power Ranger' }); - toy.save(function (err) { + toy.save(function(err) { // `err` is a ValidationError object // `err.errors.color` is a ValidatorError object assert.equal(err.errors.color.message, 'Color `Green` not valid'); @@ -399,12 +399,12 @@ describe('validation docs', function() { const Toy = db.model('Toys', toySchema); - Toy.schema.path('color').validate(function (value) { + Toy.schema.path('color').validate(function(value) { return /red|green|blue/i.test(value); }, 'Invalid color'); const opts = { runValidators: true }; - Toy.updateOne({}, { color: 'not a color' }, opts, function (err) { + Toy.updateOne({}, { color: 'not a color' }, opts, function(err) { assert.equal(err.errors.color.message, 'Invalid color'); // acquit:ignore:start @@ -517,7 +517,7 @@ describe('validation docs', function() { const update = { color: 'blue' }; const opts = { runValidators: true }; - Kitten.updateOne({}, update, opts, function(err) { + Kitten.updateOne({}, update, opts, function() { // Operation succeeds despite the fact that 'name' is not specified // acquit:ignore:start --outstanding || done(); @@ -570,7 +570,7 @@ describe('validation docs', function() { let update = { $inc: { number: 1 } }; const opts = { runValidators: true }; - Test.updateOne({}, update, opts, function(error) { + Test.updateOne({}, update, opts, function() { // There will never be a validation error here update = { $push: [{ message: 'hello' }, { message: 'world' }] }; Test.updateOne({}, update, opts, function(error) { diff --git a/test/typescript/aggregate.ts b/test/typescript/aggregate.ts index 9bcc1d12224..ec8a9096c8f 100644 --- a/test/typescript/aggregate.ts +++ b/test/typescript/aggregate.ts @@ -17,13 +17,13 @@ Test.aggregate([{ $match: { name: 'foo' } }]).then((res: Array) => run().catch((err: Error) => console.log(err.stack)); async function run() { - let res: Array = await Test.aggregate([{ $match: { name: 'foo' } }]).exec(); + const res: Array = await Test.aggregate([{ $match: { name: 'foo' } }]).exec(); console.log(res[0].name); - let res2: Array = await Test.aggregate([{ $match: { name: 'foo' } }]); + const res2: Array = await Test.aggregate([{ $match: { name: 'foo' } }]); console.log(res2[0].name); - await Test.aggregate([{ $match: { name: 'foo' } }]).cursor().exec().eachAsync(async (res) => { + await Test.aggregate([{ $match: { name: 'foo' } }]).cursor().exec().eachAsync(async(res) => { console.log(res); }); -} \ No newline at end of file +} diff --git a/test/typescript/base.ts b/test/typescript/base.ts index e952d82f96c..a663ef05e1b 100644 --- a/test/typescript/base.ts +++ b/test/typescript/base.ts @@ -1,6 +1,6 @@ -import * as mongoose from 'mongoose' +import * as mongoose from 'mongoose'; -Object.values(mongoose.models).forEach(model=>{ +Object.values(mongoose.models).forEach(model => { model.modelName; - model.findOne() -}); \ No newline at end of file + model.findOne(); +}); diff --git a/test/typescript/collection.ts b/test/typescript/collection.ts index 323bb08c719..12761e9968d 100644 --- a/test/typescript/collection.ts +++ b/test/typescript/collection.ts @@ -10,8 +10,8 @@ interface ITest extends Document { const Test = model('Test', schema); Test.collection.collectionName; -Test.collection.findOne({}) -Test.collection.findOneAndDelete({}) -Test.collection.ensureIndex() -Test.collection.findAndModify() -Test.collection.getIndexes() \ No newline at end of file +Test.collection.findOne({}); +Test.collection.findOneAndDelete({}); +Test.collection.ensureIndex(); +Test.collection.findAndModify(); +Test.collection.getIndexes(); diff --git a/test/typescript/connectSyntax.ts b/test/typescript/connectSyntax.ts index 1b84311dd7e..414a747eec0 100644 --- a/test/typescript/connectSyntax.ts +++ b/test/typescript/connectSyntax.ts @@ -5,10 +5,10 @@ connect('mongodb://localhost:27017/test', { useNewUrlParser: true, useFindAndModify: true, useCreateIndex: true, - useUnifiedTopology: true, + useUnifiedTopology: true }).then(mongoose => console.log(mongoose.connect)); // Callback connect('mongodb://localhost:27017/test', { useNewUrlParser: true, useUnifiedTopology: true }, (err: Error | null) => { console.log(err); -}); \ No newline at end of file +}); diff --git a/test/typescript/discriminator.ts b/test/typescript/discriminator.ts index 30e43378107..9b80adae4b9 100644 --- a/test/typescript/discriminator.ts +++ b/test/typescript/discriminator.ts @@ -25,48 +25,48 @@ function test(): void { Enchantment = 'enchantment', Land = 'land', } - + interface CardDb extends Document { _id: Types.ObjectId; type: CardType; } - + interface LandDb extends CardDb { type: CardType.Land; } - + const cardDbBaseSchemaDefinition: SchemaDefinition = { - type: { type: String, required: true }, + type: { type: String, required: true } }; - + const cardDbSchemaOptions: SchemaOptions = { discriminatorKey: 'type' }; - + const cardDbSchema: Schema = new Schema( cardDbBaseSchemaDefinition, cardDbSchemaOptions, ); - + const cardDbModel: Model = mongoose.model( 'Card', cardDbSchema, 'card', ); - + const landDbAdditionalPropertiesSchemaDefinition: SchemaDefinition = {}; - + const landDbSchema: Schema = new Schema( landDbAdditionalPropertiesSchemaDefinition, ); - + const landDbModel: Model = cardDbModel.discriminator( 'Land', landDbSchema, CardType.Land, ); - + const sampleLandDb: LandDb = new landDbModel({ - type: CardType.Land, + type: CardType.Land }); - + const sampleCardDb: CardDb = sampleLandDb; -} \ No newline at end of file +} diff --git a/test/typescript/methods.ts b/test/typescript/methods.ts index 7fe90a4755b..c39bf24243d 100644 --- a/test/typescript/methods.ts +++ b/test/typescript/methods.ts @@ -6,12 +6,12 @@ interface ITest extends Document { } const TestSchema = new Schema({ - foo: { type: String, required: true }, + foo: { type: String, required: true } }); TestSchema.methods.getAnswer = function(): number { return 42; -} +}; const Test = connection.model('Test', TestSchema); @@ -19,4 +19,4 @@ Test.create({ foo: 'test' }); const doc: ITest = new Test({ foo: 'test' }); -Math.floor(doc.getAnswer()); \ No newline at end of file +Math.floor(doc.getAnswer()); diff --git a/test/typescript/middleware.ts b/test/typescript/middleware.ts index c39d1e068d5..5c941ea887a 100644 --- a/test/typescript/middleware.ts +++ b/test/typescript/middleware.ts @@ -30,8 +30,9 @@ schema.post('save', function() { console.log(this.name); }); +// eslint-disable-next-line @typescript-eslint/ban-types schema.post('save', function(err: Error, res: ITest, next: Function) { console.log(this.name, err.stack); }); -const Test = model('Test', schema); \ No newline at end of file +const Test = model('Test', schema); diff --git a/test/typescript/modelInheritance.ts b/test/typescript/modelInheritance.ts index 0a720836617..d31b4854f60 100644 --- a/test/typescript/modelInheritance.ts +++ b/test/typescript/modelInheritance.ts @@ -7,7 +7,7 @@ class InteractsWithDatabase extends Model { } class SourceProvider extends InteractsWithDatabase { - static async deleteInstallation (installationId: number): Promise { + static async deleteInstallation(installationId: number): Promise { await this.findOneAndDelete({ installationId }); } -} \ No newline at end of file +} diff --git a/test/typescript/models.ts b/test/typescript/models.ts index 4b4bb75a63f..15a76f55d58 100644 --- a/test/typescript/models.ts +++ b/test/typescript/models.ts @@ -4,15 +4,15 @@ function conventionalSyntax(): void { interface ITest extends Document { foo: string; } - + const TestSchema = new Schema({ - foo: { type: String, required: true }, + foo: { type: String, required: true } }); - + const Test = connection.model('Test', TestSchema); - + const bar = (SomeModel: Model) => console.log(SomeModel); - + bar(Test); } @@ -21,9 +21,9 @@ function tAndDocSyntax(): void { id: number; foo: string; } - + const TestSchema = new Schema({ - foo: { type: String, required: true }, + foo: { type: String, required: true } }); const Test = connection.model('Test', TestSchema); @@ -36,12 +36,12 @@ function tAndDocSyntax(): void { const ExpiresSchema = new Schema({ ttl: { type: Date, - expires: 3600, - }, + expires: 3600 + } }); interface IProject extends Document { - name: String; + name: string; } interface ProjectModel extends Model { @@ -52,4 +52,4 @@ const projectSchema: Schema = new Schema({ name: String }); projectSchema.statics.myStatic = () => 42; const Project = connection.model('Project', projectSchema); -Project.myStatic(); \ No newline at end of file +Project.myStatic(); diff --git a/test/typescript/queries.ts b/test/typescript/queries.ts index cf4fe4b6c95..1c935e46d13 100644 --- a/test/typescript/queries.ts +++ b/test/typescript/queries.ts @@ -36,6 +36,6 @@ Test.findOneAndUpdate({ name: 'test' }, { name: 'test2' }).exec().then((res: ITe Test.findOneAndUpdate({ name: 'test' }, { name: 'test2' }).then((res: ITest | null) => console.log(res)); Test.findOneAndUpdate({ name: 'test' }, { $set: { name: 'test2' } }).then((res: ITest | null) => console.log(res)); Test.findOneAndUpdate({ name: 'test' }, { $inc: { age: 2 } }).then((res: ITest | null) => console.log(res)); -Test.findOneAndUpdate({ name: 'test' }, { name: 'test3' }, { upsert: true }).then((res: ITest) => { res.name = 'test4' }); +Test.findOneAndUpdate({ name: 'test' }, { name: 'test3' }, { upsert: true }).then((res: ITest) => { res.name = 'test4'; }); -Test.findOneAndReplace({ name: 'test' }, { _id: new Types.ObjectId(), name: 'test2' }).exec().then((res: ITest | null) => console.log(res)); \ No newline at end of file +Test.findOneAndReplace({ name: 'test' }, { _id: new Types.ObjectId(), name: 'test2' }).exec().then((res: ITest | null) => console.log(res)); diff --git a/test/typescript/querycursor.ts b/test/typescript/querycursor.ts index 2592bf98e68..6a03ee90c72 100644 --- a/test/typescript/querycursor.ts +++ b/test/typescript/querycursor.ts @@ -8,5 +8,5 @@ interface ITest extends Document { const Test = model('Test', schema); -Test.find().cursor().eachAsync(async (doc: ITest) => console.log(doc.name)). - then(() => console.log('Done!')); \ No newline at end of file +Test.find().cursor().eachAsync(async(doc: ITest) => console.log(doc.name)). + then(() => console.log('Done!')); diff --git a/test/typescript/subdocuments.ts b/test/typescript/subdocuments.ts index 19b132ad6af..a1b71f4e0aa 100644 --- a/test/typescript/subdocuments.ts +++ b/test/typescript/subdocuments.ts @@ -12,12 +12,12 @@ const schema: Schema = new Schema({ docarr2: [{ type: childSchema, _id: false - }], + }] }); interface ITest extends Document { - child1: { name: String }, - child2: { name: String } + child1: { name: string }, + child2: { name: string } } const Test = model('Test', schema); @@ -25,4 +25,4 @@ const Test = model('Test', schema); const doc: ITest = new Test({}); doc.child1 = { name: 'test1' }; -doc.child2 = { name: 'test2' }; \ No newline at end of file +doc.child2 = { name: 'test2' };