Skip to content

Commit

Permalink
cleanup and linting
Browse files Browse the repository at this point in the history
  • Loading branch information
debadutta98 committed Jun 29, 2023
1 parent 9eb31d8 commit b72562b
Show file tree
Hide file tree
Showing 48 changed files with 314 additions and 324 deletions.
12 changes: 9 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@
"extends": "@dabh/eslint-config-populist",
"rules": {
"one-var": ["error", { "var": "never", "let": "never", "const": "never" }],
"strict": 0
"strict": 0,
"no-sync":"off",
"no-undefined":"off",
"no-new":"off",
"callback-return":"off",
"max-nested-callbacks":"warn",
"no-return-assign":"off"
},
"parserOptions": {
"ecmaVersion": 2022,
},
"ecmaVersion": 2022
}
}
10 changes: 5 additions & 5 deletions examples/create-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ const filename = path.join(__dirname, 'created-logfile.log');
//
// Remove the file, ignoring any errors
//
try { fs.unlinkSync(filename); }
catch (ex) { }
/* eslint-disable-next-line no-empty */
try { fs.unlinkSync(filename); } catch (ex) {}

//
// Create a new winston logger instance with two tranports: Console, and File
Expand All @@ -23,12 +23,12 @@ const logger = winston.createLogger({
]
});

logger.log('info', 'Hello created log files!', { 'foo': 'bar' });
logger.log('info', 'Hello created log files!', { foo: 'bar' });

setTimeout(function () {
//
// Remove the file, ignoring any errors
//
try { fs.unlinkSync(filename); }
catch (ex) { }
/* eslint-disable-next-line no-empty */
try { fs.unlinkSync(filename); } catch (ex) {}
}, 1000);
2 changes: 1 addition & 1 deletion examples/custom-levels-colors.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ const logger = module.exports = winston.createLogger({
level: 'custom'
});

logger.custom('hello')
logger.custom('hello');
10 changes: 5 additions & 5 deletions examples/custom-pretty-print.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
'use strict';

const winston = require('../');

const logger = winston.createLogger({
format: winston.format.printf(info => {
return JSON.stringify(info)
.replace(/\{/g, '< wow ')
// eslint-disable-next-line no-useless-escape
.replace(/\:/g, ' such ')
.replace(/\}/g, ' >')
.replace(/\}/g, ' >');
}),
transports: [
new winston.transports.Console(),
new winston.transports.Console()
]
});

logger.info('Hello, this is a logging event with a custom pretty print', { 'foo': 'bar' });
logger.info('Hello, this is a logging event with a custom pretty print2', { 'foo': 'bar' });
logger.info('Hello, this is a logging event with a custom pretty print', { foo: 'bar' });
logger.info('Hello, this is a logging event with a custom pretty print2', { foo: 'bar' });

4 changes: 2 additions & 2 deletions examples/custom-transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class CustomTransport extends Transport {

callback();
}
};
}

const transport = new CustomTransport();
transport.on('logged', (info) => {
Expand All @@ -40,4 +40,4 @@ const logger = createLogger({
transports: [transport]
});

logger.info('hello')
logger.info('hello');
6 changes: 3 additions & 3 deletions examples/delete-level.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ const logger = createLogger({
json()
),
transports: [
new transports.Console(),
new transports.Console()
]
});

logger.info('This will print without { level }', { 'foo': 'bar' });
logger.info('This will also print without { level }', { 'foo': 'bar' });
logger.info('This will print without { level }', { foo: 'bar' });
logger.info('This will also print without { level }', { foo: 'bar' });

2 changes: 1 addition & 1 deletion examples/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const logger = createLogger({
json()
),
transports: [
new transports.Console(),
new transports.Console()
]
});

Expand Down
2 changes: 1 addition & 1 deletion examples/exception.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const winston = require('../');
// This should output what was previously referred to
// as "humanReadableUncaughtExceptions" by default.
//
const logger = winston.createLogger({
winston.createLogger({
format: winston.format.simple(),
transports: [
new winston.transports.Console({ handleExceptions: true })
Expand Down
1 change: 0 additions & 1 deletion examples/file-maxsize.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
const path = require('path');
const { MESSAGE } = require('triple-beam');
const winston = require('../');

const logger = winston.createLogger({
Expand Down
4 changes: 2 additions & 2 deletions examples/finish-event.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ logger.on('finish', function () {
console.log('Your logger is done logging');
});

logger.log('info', 'Hello, this is a raw logging event', { 'foo': 'bar' });
logger.log('info', 'Hello, this is a raw logging event 2', { 'foo': 'bar' });
logger.log('info', 'Hello, this is a raw logging event', { foo: 'bar' });
logger.log('info', 'Hello, this is a raw logging event 2', { foo: 'bar' });

logger.end();
2 changes: 1 addition & 1 deletion examples/format-dynamic-content.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const winston = require('../');
const logger = module.exports = winston.createLogger({
transports: [new winston.transports.Console()],
format: winston.format.combine(
winston.format(function dynamicContent(info, opts) {
winston.format(function dynamicContent(info) {
info.message = '[dynamic content] ' + info.message;
return info;
})(),
Expand Down
2 changes: 1 addition & 1 deletion examples/format-filter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { createLogger, format, transports } = require('../');

// Ignore log messages if the have { private: true }
const ignorePrivate = format((info, opts) => {
const ignorePrivate = format((info) => {
if (info.private) { return false; }
return info;
});
Expand Down
2 changes: 1 addition & 1 deletion examples/format-logger-and-transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const logger = createLogger({
stream: fs.createWriteStream('./example.log')
})
]
})
});

logger.log({
level: 'info',
Expand Down
6 changes: 3 additions & 3 deletions examples/json.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ const winston = require('../');
//
const logger = winston.createLogger({
transports: [
new winston.transports.Console(),
new winston.transports.Console()
]
});

logger.log('info', 'Hello, this is a raw logging event', { 'foo': 'bar' });
logger.log('info', 'Hello, this is a raw logging event 2', { 'foo': 'bar' });
logger.log('info', 'Hello, this is a raw logging event', { foo: 'bar' });
logger.log('info', 'Hello, this is a raw logging event 2', { foo: 'bar' });
2 changes: 1 addition & 1 deletion examples/metadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const logger = winston.createLogger({
// Notice that both arguments have been combined into a single
// "info" object.
//
winston.format(function (info, opts) {
winston.format(function (info) {
console.log(`{ reason: ${info.reason}, promise: ${info.promise} }`);
return info;
})(),
Expand Down
6 changes: 3 additions & 3 deletions examples/splat-message.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,18 @@ const loggers = {
winston.format.splat(),
winston.format.simple()
),
transports: [new winston.transports.Console()],
transports: [new winston.transports.Console()]
}),
simple: winston.createLogger({
level: 'info',
format: winston.format.simple(),
transports: [new winston.transports.Console()],
transports: [new winston.transports.Console()]
})
};

const meta = {
subject: 'Hello, World!',
message: 'This message is a unique property separate from implicit merging.',
message: 'This message is a unique property separate from implicit merging.'
};

loggers.simple.info('email.message is hidden', meta);
Expand Down
4 changes: 2 additions & 2 deletions examples/splat.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const winston = require('../');
let { format } = winston;
const { format } = winston;

/*
* Simple helper for stringifying all remaining
Expand All @@ -14,7 +14,7 @@ function rest(info) {
}));
}

let logger = winston.createLogger({
const logger = winston.createLogger({
transports: [new winston.transports.Console({ level: 'info' })],
format: format.combine(
format.splat(),
Expand Down
4 changes: 2 additions & 2 deletions lib/winston/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ class Profiler {

return this.logger.write(info);
}
};
}

module.exports = Profiler;
module.exports = Profiler;
25 changes: 14 additions & 11 deletions test/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
*
*/

const assume = require('assume'),
fs = require('fs'),
path = require('path'),
through = require('through2'),
spawn = require('child_process').spawn,
stream = require('stream'),
util = require('util'),
winston = require('../../lib/winston'),
mockTransport = require('./mocks/mock-transport');
const assume = require('assume');
const fs = require('fs');
const through = require('through2');
const spawn = require('child_process').spawn;
const stream = require('stream');
const winston = require('../../lib/winston');
const mockTransport = require('./mocks/mock-transport');

var helpers = exports;

Expand All @@ -23,6 +21,7 @@ var helpers = exports;
* the `write` method on each call to `.log`
*
* @param {function} write Write function for the specified stream
* @param {Object} format - object
* @returns {Logger} A winston.Logger instance
*/
helpers.createLogger = function (write, format) {
Expand All @@ -37,6 +36,7 @@ helpers.createLogger = function (write, format) {
/**
* Returns a new writeable stream with the specified write function.
* @param {function} write Write function for the specified stream
* @param {boolean} objectMode - a boolean value
* @returns {stream.Writeable} A writeable stream instance
*/
helpers.writeable = function (write, objectMode) {
Expand Down Expand Up @@ -115,6 +115,7 @@ helpers.clearRejections = function () {
/**
* Throws an exception with the specified `msg`
* @param {String} msg Error mesage to use
* @returns {void}
*/
helpers.throw = function (msg) {
throw new Error(msg);
Expand All @@ -123,6 +124,7 @@ helpers.throw = function (msg) {
/**
* Causes a Promise rejection with the specified `msg`
* @param {String} msg Error mesage to use
* @returns {Promise} return a promise
*/
helpers.reject = function (msg) {
return new Promise((resolve, reject) => {
Expand All @@ -132,18 +134,19 @@ helpers.reject = function (msg) {

/**
* Attempts to unlink the specifyed `filename` ignoring errors
* @param {String} File Full path to attempt to unlink.
* @param {String} filename Full path to attempt to unlink.
*/
helpers.tryUnlink = function (filename) {
try {
fs.unlinkSync(filename);
/* eslint-disable-next-line no-empty*/
} catch (ex) {}
};

/**
* Returns a stream that will emit data for the `filename` if it exists
* and is capable of being opened.
* @param {filename} Full path to attempt to read from.
* @param {string} filename path to attempt to read from.
* @returns {Stream} Stream instance to the contents of the file
*/
helpers.tryRead = function tryRead(filename) {
Expand Down
4 changes: 1 addition & 3 deletions test/helpers/mocks/legacy-mixed-transport.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
'use strict'
'use strict';

const events = require('events');
const util = require('util')
const Transport = require('../../../').Transport;

//
Expand Down
5 changes: 2 additions & 3 deletions test/helpers/mocks/legacy-transport.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'
'use strict';

const events = require('events');
const util = require('util')
const util = require('util');
const Transport = require('winston-compat').Transport;

//
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/mocks/mock-transport.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const stream = require('stream')
const stream = require('stream');
const winston = require('../../../lib/winston');

/**
Expand All @@ -14,7 +14,7 @@ function createMockTransport(write) {
write: write
});

return new winston.transports.Stream({ stream: writeable })
return new winston.transports.Stream({ stream: writeable });
}

module.exports = {
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/scripts/default-exceptions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*
*/

var path = require('path'),
winston = require('../../../lib/winston');
var path = require('path');
var winston = require('../../../lib/winston');
const testLogFixturesPath = path.join(__dirname, '..', '..', 'fixtures', 'logs');

winston.exceptions.handle([
Expand Down
12 changes: 6 additions & 6 deletions test/helpers/scripts/default-rejections.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,19 @@
*
*/

var path = require("path"),
winston = require("../../../lib/winston");
var path = require('path');
var winston = require('../../../lib/winston');
const testLogFixturesPath = path.join(__dirname, '..', '..', 'fixtures', 'logs');

winston.rejections.handle([
new winston.transports.File({
filename: path.join(testLogFixturesPath, "default-rejection.log"),
filename: path.join(testLogFixturesPath, 'default-rejection.log'),
handleRejections: true
})
]);

winston.info("Log something before error");
winston.info('Log something before error');

setTimeout(function() {
Promise.reject(new Error("OH NOES! It rejected!"));
setTimeout(function () {
Promise.reject(new Error('OH NOES! It rejected!'));
}, 1000);
4 changes: 2 additions & 2 deletions test/helpers/scripts/exit-on-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
*
*/

var path = require('path'),
winston = require('../../../lib/winston');
var path = require('path');
var winston = require('../../../lib/winston');
const testLogFixturesPath = path.join(__dirname, '..', '..', 'fixtures', 'logs');

winston.exitOnError = function (err) {
Expand Down
Loading

0 comments on commit b72562b

Please sign in to comment.