Skip to content

Commit

Permalink
winstonjs#225: Fix ESLint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
curledUpSheep committed Jul 13, 2023
1 parent 6a9fb9c commit c6140ab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
7 changes: 4 additions & 3 deletions lib/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ const ObjectID = require('mongodb').ObjectID;

/**
* Prepares metadata to store into database.
* @param {*} meta Metadata
* @returns {*}
* @param {Object} meta Metadata
* @returns {Object} Prepared metadata
*/
exports.prepareMetaData = meta => {
return cloneMeta(meta);
Expand All @@ -23,7 +23,8 @@ 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=} optParents Object's parents
* @param {Array} optParents Object's parents
* @returns {Object} Adjusted clone of object
*/
function cloneMeta(node, optParents) {
if (!((node !== null && typeof node === 'object') || typeof node === 'function')
Expand Down
13 changes: 8 additions & 5 deletions lib/winston-mongodb.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const helpers = require('./helpers');
/**
* Constructor for the MongoDB transport object.
* @constructor
* @param {Object} options
* @param {Object} options Options
* @param {string} [options.level=info] Level of messages that this transport
* should log.
* @param {boolean} [options.silent=false] Boolean flag indicating whether to
Expand Down Expand Up @@ -189,7 +189,7 @@ MongoDB.prototype.close = function () {
if (!this.mongoClient || this.leaveConnectionOpen) {
return;
}
this.mongoClient.close().then(() => this.mongoClient = null).catch(err => {
this.mongoClient.close().then(() => { this.mongoClient = null; }).catch(err => {
console.error('Winston MongoDB transport encountered on error during '
+ 'closing.', err);
});
Expand All @@ -200,6 +200,7 @@ MongoDB.prototype.close = function () {
* Core logging method exposed to Winston. Metadata is optional.
* @param {Object} info Logging metadata
* @param {Function} cb Continuation to respond to when complete.
* @returns {boolean} Result boolean
*/
MongoDB.prototype.log = function (info, cb) {
if (!this.logDb) {
Expand All @@ -213,8 +214,10 @@ MongoDB.prototype.log = function (info, cb) {
// If database logs, better not to call database itself in the same call.
process.nextTick(() => {
if (this.silent) {
// eslint-disable-next-line callback-return
cb(null, true);
}
// eslint-disable-next-line no-control-regex
const decolorizeRegex = new RegExp(/\u001b\[[0-9]{1,2}m/g);
const entry = { timestamp: new Date(), level: (this.decolorize) ? info.level.replace(decolorizeRegex, '') : info.level };
const msg = util.format(info.message, ...(info.splat || []));
Expand Down Expand Up @@ -250,7 +253,6 @@ MongoDB.prototype.log = function (info, cb) {
* Query the transport. Options object is optional.
* @param {Object=} optOptions Loggly-like query options for this instance.
* @param {Function} cb Continuation to respond to when complete.
* @returns {*}
*/
MongoDB.prototype.query = function (optOptions, cb) {
if (!this.logDb) {
Expand Down Expand Up @@ -285,7 +287,7 @@ MongoDB.prototype.query = function (optOptions, cb) {
* This will only work with a capped collection.
* @param {Object} options Stream options for this instance.
* @param {Stream} stream Pass in a pre-existing stream.
* @returns {Stream}
* @returns {Stream} Log stream for the transport
*/
MongoDB.prototype.stream = function (options, stream) {
options = options || {};
Expand Down Expand Up @@ -343,7 +345,7 @@ MongoDB.prototype.stream = function (options, stream) {
* Returns a log stream for this transport. Options object is optional.
* @param {Object} options Stream options for this instance.
* @param {Stream} stream Pass in a pre-existing stream.
* @returns {Stream}
* @returns {Stream} Log stream for the transport
*/
MongoDB.prototype.streamPoll = function (options, stream) {
options = options || {};
Expand Down Expand Up @@ -398,6 +400,7 @@ MongoDB.prototype.streamPoll = function (options, stream) {
if (stream.destroyed) {
return;
}
// eslint-disable-next-line callback-return
next();
stream.emit('error', err);
});
Expand Down
2 changes: 1 addition & 1 deletion test/helpers-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ describe('winston-mongodb-helpers', function () {
assert.strictEqual(preparedData.objectId, originalData.objectId);
});
it('should preserve Buffers', function () {
const originalData = { buffer: new Buffer.from('test') };
const originalData = { buffer: Buffer.from('test') };

const preparedData = helpers.prepareMetaData(originalData);

Expand Down

0 comments on commit c6140ab

Please sign in to comment.