Skip to content

Commit

Permalink
Attempt to fix more linting errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DABH committed Jul 10, 2023
1 parent 1ff9b58 commit 9e86ae1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 24 deletions.
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@
"parserOptions": {
"ecmaVersion": 2022,
},
"env": {
"es2020": true
}
}
14 changes: 7 additions & 7 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ exports.prepareMetaData = meta => {
* with string '[Circular]' and fixes field names to be storable within
* MongoDB
* @param {Object} node Current object or its leaf
* @param {Array=} opt_parents Object's parents
* @param {Array=} optParents Object's parents
*/
function cloneMeta(node, opt_parents) {
function cloneMeta(node, optParents) {
if (!((node !== null && typeof node === 'object') || typeof node === 'function')
|| (node instanceof ObjectID) || (node instanceof Buffer)) {
return node;
Expand All @@ -37,8 +37,8 @@ function cloneMeta(node, opt_parents) {
// This is needed because Error's message, name and stack isn't accessible when cycling through properties
copy = { message: node.message, name: node.name, stack: node.stack };
}
opt_parents = opt_parents || [];
opt_parents.push(node);
optParents = optParents || [];
optParents.push(node);
for (const key in node) {
if (!Object.prototype.hasOwnProperty.call(node, key)) {
continue;
Expand All @@ -49,15 +49,15 @@ function cloneMeta(node, opt_parents) {
newKey = newKey.replace(/\./g, '[dot]').replace(/\$/g, '[$]');
}
if ((value !== null && typeof value === 'object') || typeof value === 'function') {
if (opt_parents.indexOf(value) === -1) {
copy[newKey] = cloneMeta(value, opt_parents);
if (optParents.indexOf(value) === -1) {
copy[newKey] = cloneMeta(value, optParents);
} else {
copy[newKey] = '[Circular]';
}
} else {
copy[newKey] = value;
}
}
opt_parents.pop();
optParents.pop();
return copy;
}
18 changes: 9 additions & 9 deletions lib/winston-mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,20 @@ MongoDB.prototype.log = function (info, cb) {

/**
* Query the transport. Options object is optional.
* @param {Object=} opt_options Loggly-like query options for this instance.
* @param {Object=} optOptions Loggly-like query options for this instance.
* @param {Function} cb Continuation to respond to when complete.
* @returns {*}
*/
MongoDB.prototype.query = function (opt_options, cb) {
MongoDB.prototype.query = function (optOptions, cb) {
if (!this.logDb) {
this._opQueue.push({ method: 'query', args: arguments });
return;
}
if (typeof opt_options === 'function') {
cb = opt_options;
opt_options = {};
if (typeof optOptions === 'function') {
cb = optOptions;
optOptions = {};
}
const options = this.normalizeQuery(opt_options);
const options = this.normalizeQuery(optOptions);
const query = { timestamp: { $gte: options.from, $lte: options.until }};
const opt = {
skip: options.start,
Expand Down Expand Up @@ -302,7 +302,7 @@ MongoDB.prototype.stream = function (options, stream) {
start = null;
}
const col = this.logDb.collection(this.collection);
if (start != null) {
if (start !== null) {
col.find({}, { skip: start }).toArray().then(docs => {
docs.forEach(doc => {
if (!options.includeIds) {
Expand Down Expand Up @@ -358,7 +358,7 @@ MongoDB.prototype.streamPoll = function (options, stream) {
if (start === -1) {
start = null;
}
if (start == null) {
if (start === null) {
last = new Date(new Date() - 1000);
}
stream.destroy = function () {
Expand All @@ -373,7 +373,7 @@ MongoDB.prototype.streamPoll = function (options, stream) {
if (!docs.length) {
return next();
}
if (start == null) {
if (start === null) {
docs.forEach(doc => {
if (!options.includeIds) {
delete doc._id;
Expand Down
16 changes: 8 additions & 8 deletions test/winston-mongodb-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
require('dotenv').config();
const mongodb = require('mongodb');
const mongoose = require('mongoose');
const test_suite = require('abstract-winston-transport');
const testSuite = require('abstract-winston-transport');

const MongoDB = require('../lib/winston-mongodb').MongoDB;

Expand All @@ -29,19 +29,19 @@ describe('winston-mongodb-manual-tests', function () {
});
});

test_suite({ name: '{db: url}', Transport: MongoDB, construct: { db: dbUrl }});
test_suite({ name: '{db: url, dbName: string}', Transport: MongoDB,
testSuite({ name: '{db: url}', Transport: MongoDB, construct: { db: dbUrl }});
testSuite({ name: '{db: url, dbName: string}', Transport: MongoDB,
construct: { db: dbUrl, dbName }});
test_suite({ name: '{db: url} on capped collection', Transport: MongoDB,
testSuite({ name: '{db: url} on capped collection', Transport: MongoDB,
construct: { db: dbUrl, capped: true, collection: 'cappedLog' }});
test_suite({ name: '{db: url, dbName: string} on capped collection', Transport: MongoDB,
testSuite({ name: '{db: url, dbName: string} on capped collection', Transport: MongoDB,
construct: { db: dbUrl, dbName, capped: true, collection: 'cappedLog' }});
test_suite({ name: '{db: client promise}', Transport: MongoDB,
testSuite({ name: '{db: client promise}', Transport: MongoDB,
construct: { db: mongodb.MongoClient.connect(dbUrl, { useNewUrlParser: true }) }});
test_suite({ name: '{db: client promise, dbName: string}', Transport: MongoDB,
testSuite({ name: '{db: client promise, dbName: string}', Transport: MongoDB,
construct: {
dbName,
db: mongodb.MongoClient.connect(dbUrl, { useNewUrlParser: true }) }
});
test_suite({ name: '{db: mongoose client}', Transport: MongoDB,
testSuite({ name: '{db: mongoose client}', Transport: MongoDB,
construct: { db: mongoose.connection }});

0 comments on commit 9e86ae1

Please sign in to comment.