Skip to content

Commit d2412a6

Browse files
lint
1 parent 7fa1af4 commit d2412a6

File tree

3 files changed

+53
-54
lines changed

3 files changed

+53
-54
lines changed

lib/model.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3688,7 +3688,7 @@ Model.castObject = function castObject(obj, options) {
36883688
}
36893689

36903690
if (schemaType.$isMongooseDocumentArray) {
3691-
const castNonArraysOption = schemaType.options?.castNonArrays ??schemaType.constructor.options.castNonArrays;
3691+
const castNonArraysOption = schemaType.options?.castNonArrays ?? schemaType.constructor.options.castNonArrays;
36923692
if (!Array.isArray(val)) {
36933693
if (!castNonArraysOption) {
36943694
if (!options.ignoreCastErrors) {

lib/schema.js

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -209,16 +209,16 @@ function aliasFields(schema, paths) {
209209

210210
schema.
211211
virtual(a).
212-
get((function (p) {
213-
return function () {
212+
get((function(p) {
213+
return function() {
214214
if (typeof this.get === 'function') {
215215
return this.get(p);
216216
}
217217
return this[p];
218218
};
219219
})(prop)).
220-
set((function (p) {
221-
return function (v) {
220+
set((function(p) {
221+
return function(v) {
222222
return this.$set(p, v);
223223
};
224224
})(prop));
@@ -235,16 +235,16 @@ function aliasFields(schema, paths) {
235235

236236
schema.
237237
virtual(alias).
238-
get((function (p) {
239-
return function () {
238+
get((function(p) {
239+
return function() {
240240
if (typeof this.get === 'function') {
241241
return this.get(p);
242242
}
243243
return this[p];
244244
};
245245
})(prop)).
246-
set((function (p) {
247-
return function (v) {
246+
set((function(p) {
247+
return function(v) {
248248
return this.$set(p, v);
249249
};
250250
})(prop));
@@ -387,7 +387,7 @@ Schema.prototype.tree;
387387
* @instance
388388
*/
389389

390-
Schema.prototype.clone = function () {
390+
Schema.prototype.clone = function() {
391391
const s = this._clone();
392392

393393
// Bubble up `init` for backwards compat
@@ -407,7 +407,7 @@ Schema.prototype._clone = function _clone(Constructor) {
407407
s.base = this.base;
408408
s.obj = this.obj;
409409
s.options = clone(this.options);
410-
s.callQueue = this.callQueue.map(function (f) { return f; });
410+
s.callQueue = this.callQueue.map(function(f) { return f; });
411411
s.methods = clone(this.methods);
412412
s.methodOptions = clone(this.methodOptions);
413413
s.statics = clone(this.statics);
@@ -488,7 +488,7 @@ Schema.prototype._clone = function _clone(Constructor) {
488488
* @api public
489489
*/
490490

491-
Schema.prototype.pick = function (paths, options) {
491+
Schema.prototype.pick = function(paths, options) {
492492
const newSchema = new Schema({}, options || this.options);
493493
if (!Array.isArray(paths)) {
494494
throw new MongooseError('Schema#pick() only accepts an array argument, ' +
@@ -530,7 +530,7 @@ Schema.prototype.pick = function (paths, options) {
530530
* @api public
531531
*/
532532

533-
Schema.prototype.omit = function (paths, options) {
533+
Schema.prototype.omit = function(paths, options) {
534534
const newSchema = new Schema(this, options || this.options);
535535
if (!Array.isArray(paths)) {
536536
throw new MongooseError(
@@ -560,7 +560,7 @@ Schema.prototype.omit = function (paths, options) {
560560
* @api private
561561
*/
562562

563-
Schema.prototype.defaultOptions = function (options) {
563+
Schema.prototype.defaultOptions = function(options) {
564564
this._userProvidedOptions = options == null ? {} : clone(options);
565565
const baseOptions = this.base && this.base.options || {};
566566
const strict = 'strict' in baseOptions ? baseOptions.strict : true;
@@ -637,7 +637,7 @@ Schema.prototype.defaultOptions = function (options) {
637637
* @return {Schema} the Schema instance
638638
* @api public
639639
*/
640-
Schema.prototype.discriminator = function (name, schema, options) {
640+
Schema.prototype.discriminator = function(name, schema, options) {
641641
this._applyDiscriminators = this._applyDiscriminators || new Map();
642642
this._applyDiscriminators.set(name, { schema, options });
643643

@@ -649,7 +649,7 @@ Schema.prototype.discriminator = function (name, schema, options) {
649649
* options.
650650
*/
651651

652-
Schema.prototype._defaultToObjectOptions = function (json) {
652+
Schema.prototype._defaultToObjectOptions = function(json) {
653653
const path = json ? 'toJSON' : 'toObject';
654654
if (this._defaultToObjectOptionsMap && this._defaultToObjectOptionsMap[path]) {
655655
return this._defaultToObjectOptionsMap[path];
@@ -1044,7 +1044,7 @@ reserved.collection = 1;
10441044
* @api public
10451045
*/
10461046

1047-
Schema.prototype.path = function (path, obj) {
1047+
Schema.prototype.path = function(path, obj) {
10481048
if (obj === undefined) {
10491049
if (this.paths[path] != null) {
10501050
return this.paths[path];
@@ -1345,7 +1345,7 @@ Object.defineProperty(Schema.prototype, 'base', {
13451345
* @api private
13461346
*/
13471347

1348-
Schema.prototype.interpretAsType = function (path, obj, options) {
1348+
Schema.prototype.interpretAsType = function(path, obj, options) {
13491349
if (obj instanceof SchemaType) {
13501350
if (obj.path === path) {
13511351
return obj;
@@ -1610,7 +1610,7 @@ function createMapNestedSchemaType(schema, schemaType, path, obj, options) {
16101610
* @api public
16111611
*/
16121612

1613-
Schema.prototype.eachPath = function (fn) {
1613+
Schema.prototype.eachPath = function(fn) {
16141614
const keys = Object.keys(this.paths);
16151615
const len = keys.length;
16161616

@@ -1691,7 +1691,7 @@ Schema.prototype.indexedPaths = function indexedPaths() {
16911691
* @api public
16921692
*/
16931693

1694-
Schema.prototype.pathType = function (path) {
1694+
Schema.prototype.pathType = function(path) {
16951695
if (this.paths.hasOwnProperty(path)) {
16961696
return 'real';
16971697
}
@@ -1734,7 +1734,7 @@ Schema.prototype.pathType = function (path) {
17341734
* @api private
17351735
*/
17361736

1737-
Schema.prototype.hasMixedParent = function (path) {
1737+
Schema.prototype.hasMixedParent = function(path) {
17381738
const subpaths = path.split(/\./g);
17391739
path = '';
17401740
for (let i = 0; i < subpaths.length; ++i) {
@@ -1754,7 +1754,7 @@ Schema.prototype.hasMixedParent = function (path) {
17541754
* @param {Boolean|Object} timestamps timestamps options
17551755
* @api private
17561756
*/
1757-
Schema.prototype.setupTimestamp = function (timestamps) {
1757+
Schema.prototype.setupTimestamp = function(timestamps) {
17581758
return setupTimestamps(this, timestamps);
17591759
};
17601760

@@ -1852,7 +1852,7 @@ function getPositionalPath(self, path, cleanPath) {
18521852
* @api public
18531853
*/
18541854

1855-
Schema.prototype.queue = function (name, args) {
1855+
Schema.prototype.queue = function(name, args) {
18561856
this.callQueue.push([name, args]);
18571857
return this;
18581858
};
@@ -1900,7 +1900,7 @@ Schema.prototype.queue = function (name, args) {
19001900
* @api public
19011901
*/
19021902

1903-
Schema.prototype.pre = function (name) {
1903+
Schema.prototype.pre = function(name) {
19041904
if (name instanceof RegExp) {
19051905
const remainingArgs = Array.prototype.slice.call(arguments, 1);
19061906
for (const fn of hookNames) {
@@ -1958,7 +1958,7 @@ Schema.prototype.pre = function (name) {
19581958
* @api public
19591959
*/
19601960

1961-
Schema.prototype.post = function (name) {
1961+
Schema.prototype.post = function(name) {
19621962
if (name instanceof RegExp) {
19631963
const remainingArgs = Array.prototype.slice.call(arguments, 1);
19641964
for (const fn of hookNames) {
@@ -2001,7 +2001,7 @@ Schema.prototype.post = function (name) {
20012001
* @api public
20022002
*/
20032003

2004-
Schema.prototype.plugin = function (fn, opts) {
2004+
Schema.prototype.plugin = function(fn, opts) {
20052005
if (typeof fn !== 'function') {
20062006
throw new Error('First param to `schema.plugin()` must be a function, ' +
20072007
'got "' + (typeof fn) + '"');
@@ -2056,7 +2056,7 @@ Schema.prototype.plugin = function (fn, opts) {
20562056
* @api public
20572057
*/
20582058

2059-
Schema.prototype.method = function (name, fn, options) {
2059+
Schema.prototype.method = function(name, fn, options) {
20602060
if (typeof name !== 'string') {
20612061
for (const i in name) {
20622062
this.methods[i] = name[i];
@@ -2102,7 +2102,7 @@ Schema.prototype.method = function (name, fn, options) {
21022102
* @see Statics https://mongoosejs.com/docs/guide.html#statics
21032103
*/
21042104

2105-
Schema.prototype.static = function (name, fn) {
2105+
Schema.prototype.static = function(name, fn) {
21062106
if (typeof name !== 'string') {
21072107
for (const i in name) {
21082108
this.statics[i] = name[i];
@@ -2127,7 +2127,7 @@ Schema.prototype.static = function (name, fn) {
21272127
* @api public
21282128
*/
21292129

2130-
Schema.prototype.index = function (fields, options) {
2130+
Schema.prototype.index = function(fields, options) {
21312131
fields || (fields = {});
21322132
options || (options = {});
21332133

@@ -2173,7 +2173,7 @@ Schema.prototype.index = function (fields, options) {
21732173
* @api public
21742174
*/
21752175

2176-
Schema.prototype.set = function (key, value, tags) {
2176+
Schema.prototype.set = function(key, value, tags) {
21772177
if (arguments.length === 1) {
21782178
return this.options[key];
21792179
}
@@ -2264,7 +2264,7 @@ function _propagateOptionsToImplicitlyCreatedSchemas(baseSchema, options) {
22642264
* @return {Any} the option's value
22652265
*/
22662266

2267-
Schema.prototype.get = function (key) {
2267+
Schema.prototype.get = function(key) {
22682268
return this.options[key];
22692269
};
22702270

@@ -2280,10 +2280,10 @@ const indexTypes = '2d 2dsphere hashed text'.split(' ');
22802280
*/
22812281

22822282
Object.defineProperty(Schema, 'indexTypes', {
2283-
get: function () {
2283+
get: function() {
22842284
return indexTypes;
22852285
},
2286-
set: function () {
2286+
set: function() {
22872287
throw new Error('Cannot overwrite Schema.indexTypes');
22882288
}
22892289
});
@@ -2318,7 +2318,7 @@ Object.defineProperty(Schema, 'indexTypes', {
23182318
* @return {Array} list of indexes defined in the schema
23192319
*/
23202320

2321-
Schema.prototype.indexes = function () {
2321+
Schema.prototype.indexes = function() {
23222322
return getIndexes(this);
23232323
};
23242324

@@ -2338,7 +2338,7 @@ Schema.prototype.indexes = function () {
23382338
* @return {VirtualType}
23392339
*/
23402340

2341-
Schema.prototype.virtual = function (name, options) {
2341+
Schema.prototype.virtual = function(name, options) {
23422342
if (name instanceof VirtualType || getConstructorName(name) === 'VirtualType') {
23432343
return this.virtual(name.path, name.options);
23442344
}
@@ -2394,7 +2394,7 @@ Schema.prototype.virtual = function (name, options) {
23942394
});
23952395

23962396
virtual.
2397-
set(function (v) {
2397+
set(function(v) {
23982398
if (!this.$$populatedVirtuals) {
23992399
this.$$populatedVirtuals = {};
24002400
}
@@ -2440,7 +2440,7 @@ Schema.prototype.virtual = function (name, options) {
24402440
' conflicts with a real path in the schema');
24412441
}
24422442

2443-
virtuals[name] = parts.reduce(function (mem, part, i) {
2443+
virtuals[name] = parts.reduce(function(mem, part, i) {
24442444
mem[part] || (mem[part] = (i === parts.length - 1)
24452445
? new VirtualType(options, name)
24462446
: {});
@@ -2466,7 +2466,7 @@ Schema.prototype.virtual = function (name, options) {
24662466
* @return {VirtualType|null}
24672467
*/
24682468

2469-
Schema.prototype.virtualpath = function (name) {
2469+
Schema.prototype.virtualpath = function(name) {
24702470
return this.virtuals.hasOwnProperty(name) ? this.virtuals[name] : null;
24712471
};
24722472

@@ -2490,12 +2490,12 @@ Schema.prototype.virtualpath = function (name) {
24902490
* @return {Schema} the Schema instance
24912491
* @api public
24922492
*/
2493-
Schema.prototype.remove = function (path) {
2493+
Schema.prototype.remove = function(path) {
24942494
if (typeof path === 'string') {
24952495
path = [path];
24962496
}
24972497
if (Array.isArray(path)) {
2498-
path.forEach(function (name) {
2498+
path.forEach(function(name) {
24992499
if (this.path(name) == null && !this.nested[name]) {
25002500
return;
25012501
}
@@ -2547,7 +2547,7 @@ function _deletePath(schema, name) {
25472547
* @api public
25482548
*/
25492549

2550-
Schema.prototype.removeVirtual = function (path) {
2550+
Schema.prototype.removeVirtual = function(path) {
25512551
if (typeof path === 'string') {
25522552
path = [path];
25532553
}
@@ -2609,7 +2609,7 @@ Schema.prototype.removeVirtual = function (path) {
26092609
* @param {Function} model The Class to load
26102610
* @param {Boolean} [virtualsOnly] if truthy, only pulls virtuals from the class, not methods or statics
26112611
*/
2612-
Schema.prototype.loadClass = function (model, virtualsOnly) {
2612+
Schema.prototype.loadClass = function(model, virtualsOnly) {
26132613
// Stop copying when hit certain base classes
26142614
if (model === Object.prototype ||
26152615
model === Function.prototype ||
@@ -2622,7 +2622,7 @@ Schema.prototype.loadClass = function (model, virtualsOnly) {
26222622

26232623
// Add static methods
26242624
if (!virtualsOnly) {
2625-
Object.getOwnPropertyNames(model).forEach(function (name) {
2625+
Object.getOwnPropertyNames(model).forEach(function(name) {
26262626
if (name.match(/^(length|name|prototype|constructor|__proto__)$/)) {
26272627
return;
26282628
}
@@ -2634,7 +2634,7 @@ Schema.prototype.loadClass = function (model, virtualsOnly) {
26342634
}
26352635

26362636
// Add methods and virtuals
2637-
Object.getOwnPropertyNames(model.prototype).forEach(function (name) {
2637+
Object.getOwnPropertyNames(model.prototype).forEach(function(name) {
26382638
if (name.match(/^(constructor)$/)) {
26392639
return;
26402640
}
@@ -2665,7 +2665,7 @@ Schema.prototype.loadClass = function (model, virtualsOnly) {
26652665
* ignore
26662666
*/
26672667

2668-
Schema.prototype._getSchema = function (path) {
2668+
Schema.prototype._getSchema = function(path) {
26692669
const _this = this;
26702670
const pathschema = _this.path(path);
26712671
const resultPath = [];
@@ -2772,7 +2772,7 @@ Schema.prototype._getSchema = function (path) {
27722772
* ignore
27732773
*/
27742774

2775-
Schema.prototype._getPathType = function (path) {
2775+
Schema.prototype._getPathType = function(path) {
27762776
const _this = this;
27772777
const pathschema = _this.path(path);
27782778

@@ -2782,8 +2782,8 @@ Schema.prototype._getPathType = function (path) {
27822782

27832783
function search(parts, schema) {
27842784
let p = parts.length + 1,
2785-
foundschema,
2786-
trypath;
2785+
foundschema,
2786+
trypath;
27872787

27882788
while (p--) {
27892789
trypath = parts.slice(0, p).join('.');

0 commit comments

Comments
 (0)