From 4f1111ee40f677fdd859efd93da228024f72ca9f Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Fri, 11 Mar 2022 22:36:08 +0800 Subject: [PATCH 1/7] chore(lint): added specific eslint rule(s) to disable for clarity --- lib/appenders/dateFile.js | 3 ++- lib/appenders/file.js | 3 ++- lib/appenders/index.js | 5 +++-- lib/clustering.js | 3 ++- test/tap/LoggingEvent-test.js | 2 +- test/tap/layouts-test.js | 2 +- 6 files changed, 11 insertions(+), 7 deletions(-) diff --git a/lib/appenders/dateFile.js b/lib/appenders/dateFile.js index 8999c74..76de634 100644 --- a/lib/appenders/dateFile.js +++ b/lib/appenders/dateFile.js @@ -10,7 +10,8 @@ function openTheStream(filename, pattern, options) { options ); stream.on('error', (err) => { - console.error('log4js.dateFileAppender - Writing to file %s, error happened ', filename, err); // eslint-disable-line + // eslint-disable-next-line no-console + console.error('log4js.dateFileAppender - Writing to file %s, error happened ', filename, err); }); stream.on("drain", () => { process.emit("log4js:pause", false); diff --git a/lib/appenders/file.js b/lib/appenders/file.js index 2680fc1..73dad71 100644 --- a/lib/appenders/file.js +++ b/lib/appenders/file.js @@ -50,7 +50,8 @@ function fileAppender(file, layout, logSize, numBackups, options, timezoneOffset opt ); stream.on('error', (err) => { - console.error('log4js.fileAppender - Writing to file %s, error happened ', filePath, err); // eslint-disable-line + // eslint-disable-next-line no-console + console.error('log4js.fileAppender - Writing to file %s, error happened ', filePath, err); }); stream.on('drain', () => { process.emit("log4js:pause", false); diff --git a/lib/appenders/index.js b/lib/appenders/index.js index 2039dab..b9100b1 100644 --- a/lib/appenders/index.js +++ b/lib/appenders/index.js @@ -24,7 +24,8 @@ const appenders = new Map(); const tryLoading = (modulePath, config) => { debug('Loading module from ', modulePath); try { - return require(modulePath); // eslint-disable-line + // eslint-disable-next-line global-require, import/no-dynamic-require + return require(modulePath); } catch (e) { // if the module was found, and we still got an error, then raise it configuration.throwExceptionIf( @@ -83,7 +84,7 @@ const createAppender = (name, config) => { } debug(`${name}: clustering.isMaster ? ${clustering.isMaster()}`); - debug(`${name}: appenderModule is ${require('util').inspect(appenderModule)}`); // eslint-disable-line + debug(`${name}: appenderModule is ${require('util').inspect(appenderModule)}`); // eslint-disable-line global-require return clustering.onlyOnMaster(() => { debug(`calling appenderModule.configure for ${name} / ${appenderConfig.type}`); return appenderModule.configure( diff --git a/lib/clustering.js b/lib/clustering.js index 61c6ff1..fefe976 100644 --- a/lib/clustering.js +++ b/lib/clustering.js @@ -5,7 +5,8 @@ const configuration = require("./configuration"); let disabled = false; let cluster = null; try { - cluster = require("cluster"); // eslint-disable-line + // eslint-disable-next-line global-require + cluster = require("cluster"); } catch (e) { debug("cluster module not present"); disabled = true; diff --git a/test/tap/LoggingEvent-test.js b/test/tap/LoggingEvent-test.js index c6af015..a9f6487 100644 --- a/test/tap/LoggingEvent-test.js +++ b/test/tap/LoggingEvent-test.js @@ -48,7 +48,7 @@ test("LoggingEvent", batch => { batch.test("Should correct construct with/without location info", t => { // console.log([Error('123').stack.split('\n').slice(1).join('\n')]) const callStack = - " at repl:1:14\n at ContextifyScript.Script.runInThisContext (vm.js:50:33)\n at REPLServer.defaultEval (repl.js:240:29)\n at bound (domain.js:301:14)\n at REPLServer.runBound [as eval] (domain.js:314:12)\n at REPLServer.onLine (repl.js:468:10)\n at emitOne (events.js:121:20)\n at REPLServer.emit (events.js:211:7)\n at REPLServer.Interface._onLine (readline.js:280:10)\n at REPLServer.Interface._line (readline.js:629:8)"; // eslint-disable-line + " at repl:1:14\n at ContextifyScript.Script.runInThisContext (vm.js:50:33)\n at REPLServer.defaultEval (repl.js:240:29)\n at bound (domain.js:301:14)\n at REPLServer.runBound [as eval] (domain.js:314:12)\n at REPLServer.onLine (repl.js:468:10)\n at emitOne (events.js:121:20)\n at REPLServer.emit (events.js:211:7)\n at REPLServer.Interface._onLine (readline.js:280:10)\n at REPLServer.Interface._line (readline.js:629:8)"; // eslint-disable-line max-len const fileName = "/log4js-node/test/tap/layouts-test.js"; const lineNumber = 1; const columnNumber = 14; diff --git a/test/tap/layouts-test.js b/test/tap/layouts-test.js index f2f1843..855b6c9 100644 --- a/test/tap/layouts-test.js +++ b/test/tap/layouts-test.js @@ -257,7 +257,7 @@ test("log4js layouts", batch => { // console.log([Error('123').stack.split('\n').slice(1).join('\n')]) const callStack = - " at repl:1:14\n at ContextifyScript.Script.runInThisContext (vm.js:50:33)\n at REPLServer.defaultEval (repl.js:240:29)\n at bound (domain.js:301:14)\n at REPLServer.runBound [as eval] (domain.js:314:12)\n at REPLServer.onLine (repl.js:468:10)\n at emitOne (events.js:121:20)\n at REPLServer.emit (events.js:211:7)\n at REPLServer.Interface._onLine (readline.js:280:10)\n at REPLServer.Interface._line (readline.js:629:8)"; // eslint-disable-line + " at repl:1:14\n at ContextifyScript.Script.runInThisContext (vm.js:50:33)\n at REPLServer.defaultEval (repl.js:240:29)\n at bound (domain.js:301:14)\n at REPLServer.runBound [as eval] (domain.js:314:12)\n at REPLServer.onLine (repl.js:468:10)\n at emitOne (events.js:121:20)\n at REPLServer.emit (events.js:211:7)\n at REPLServer.Interface._onLine (readline.js:280:10)\n at REPLServer.Interface._line (readline.js:629:8)"; // eslint-disable-line max-len const fileName = path.normalize("/log4js-node/test/tap/layouts-test.js"); const lineNumber = 1; const columnNumber = 14; From 53c6837a60affdb45f1c095758b6579c34944664 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Sat, 12 Mar 2022 01:26:48 +0800 Subject: [PATCH 2/7] chore(lint): should not disable eslint rule, no-plusplus, in file-level --- .eslintrc | 1 + lib/connect-logger.js | 6 ++---- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.eslintrc b/.eslintrc index 7fd293c..65d85be 100644 --- a/.eslintrc +++ b/.eslintrc @@ -13,6 +13,7 @@ "max-len": [1, 120, 2], "no-use-before-define": ["warn"], "no-param-reassign": 0, + "no-plusplus": ["error", { "allowForLoopAfterthoughts": true }], "strict": 1, "import/no-extraneous-dependencies": 1 } diff --git a/lib/connect-logger.js b/lib/connect-logger.js index ed6c313..9ca3d54 100755 --- a/lib/connect-logger.js +++ b/lib/connect-logger.js @@ -1,5 +1,3 @@ -/* eslint-disable no-plusplus */ - const levels = require("./levels"); const DEFAULT_FORMAT = @@ -37,9 +35,9 @@ function assembleTokens(req, res, customTokens) { for (let i = 0; i < a.length; ++i) { for (let j = i + 1; j < a.length; ++j) { // not === because token can be regexp object - /* eslint eqeqeq:0 */ + // eslint-disable-next-line eqeqeq if (a[i].token == a[j].token) { - a.splice(j--, 1); + a.splice(j--, 1); // eslint-disable-line no-plusplus } } } From 235656df8dd9236ddc9c9bf797f581630d2fd349 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Sat, 12 Mar 2022 15:16:00 +0800 Subject: [PATCH 3/7] chore(lint): should not disable eslint rule, no-cond-assign, in file-level --- .eslintrc | 1 + lib/appenders/multiprocess.js | 1 - lib/appenders/tcp.js | 1 - lib/layouts.js | 1 - 4 files changed, 1 insertion(+), 3 deletions(-) diff --git a/.eslintrc b/.eslintrc index 65d85be..75260ea 100644 --- a/.eslintrc +++ b/.eslintrc @@ -11,6 +11,7 @@ "indent": 2, "func-names": 0, "max-len": [1, 120, 2], + "no-cond-assign": ["error", "except-parens"], "no-use-before-define": ["warn"], "no-param-reassign": 0, "no-plusplus": ["error", { "allowForLoopAfterthoughts": true }], diff --git a/lib/appenders/multiprocess.js b/lib/appenders/multiprocess.js index 50810a3..5a3a442 100644 --- a/lib/appenders/multiprocess.js +++ b/lib/appenders/multiprocess.js @@ -100,7 +100,6 @@ function workerAppender(config) { function emptyBuffer() { let evt; debug('(worker) emptying worker buffer'); - /* eslint no-cond-assign:0 */ while ((evt = buffer.shift())) { write(evt); } diff --git a/lib/appenders/tcp.js b/lib/appenders/tcp.js index f5ee9b5..8098d48 100644 --- a/lib/appenders/tcp.js +++ b/lib/appenders/tcp.js @@ -18,7 +18,6 @@ function appender(config, layout) { function emptyBuffer() { let evt; debug('emptying buffer'); - /* eslint no-cond-assign:0 */ while ((evt = buffer.shift())) { write(evt); } diff --git a/lib/layouts.js b/lib/layouts.js index dad2797..8223ce6 100644 --- a/lib/layouts.js +++ b/lib/layouts.js @@ -340,7 +340,6 @@ function patternLayout(pattern, tokens) { let result; let searchString = pattern; - /* eslint no-cond-assign:0 */ while ((result = regex.exec(searchString)) !== null) { // const matchedString = result[0]; const padding = result[1]; From e38f1c5aa99731351d141a7df11b51d0f9dd9886 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Sat, 12 Mar 2022 15:16:35 +0800 Subject: [PATCH 4/7] chore(lint): should not disable eslint rule, no-unused-var, in file-level --- lib/appenders/fileSync.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/appenders/fileSync.js b/lib/appenders/fileSync.js index a1db821..d5db399 100755 --- a/lib/appenders/fileSync.js +++ b/lib/appenders/fileSync.js @@ -131,7 +131,7 @@ class RollingFileSync { renameTheFiles(); } - /* eslint no-unused-vars:0 */ + // eslint-disable-next-line no-unused-vars write(chunk, encoding) { const that = this; From 3291aae870704df4c711590451d8c556a2518194 Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Sat, 12 Mar 2022 15:34:10 +0800 Subject: [PATCH 5/7] chore(lint): should not disable eslint rule, prefer-arrow-callback, in file-level --- lib/appenders/multiprocess.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/appenders/multiprocess.js b/lib/appenders/multiprocess.js index 5a3a442..da74a62 100644 --- a/lib/appenders/multiprocess.js +++ b/lib/appenders/multiprocess.js @@ -25,8 +25,7 @@ function logServer(config, actualAppender, levels) { return loggingEvent; } - /* eslint prefer-arrow-callback:0 */ - const server = net.createServer(function connectionHandler(clientSocket) { + const server = net.createServer((clientSocket) => { debug('(master) connection received'); clientSocket.setEncoding('utf8'); let logMessage = ''; @@ -66,7 +65,7 @@ function logServer(config, actualAppender, levels) { clientSocket.on('error', handleError); }); - server.listen(config.loggerPort || 5000, config.loggerHost || 'localhost', function (e) { + server.listen(config.loggerPort || 5000, config.loggerHost || 'localhost', (e) => { debug('(master) master server listening, error was ', e); // allow the process to exit, if this is the only socket active server.unref(); From 03f74493a9a10884fb88bb690d525a281933fc2a Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Sat, 12 Mar 2022 15:37:27 +0800 Subject: [PATCH 6/7] chore(lint): should not disable eslint rule, quote-props, in file-level --- lib/layouts.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/layouts.js b/lib/layouts.js index 8223ce6..bdb327c 100644 --- a/lib/layouts.js +++ b/lib/layouts.js @@ -271,7 +271,6 @@ function patternLayout(pattern, tokens) { return loggingEvent.callStack || ''; } - /* eslint quote-props:0 */ const replacers = { c: categoryName, d: formatAsDate, From 4c14bde0bb48bae05323f8d1c9fde3ada26bcbef Mon Sep 17 00:00:00 2001 From: Lam Wei Li Date: Sat, 12 Mar 2022 16:00:40 +0800 Subject: [PATCH 7/7] chore(lint): moved eslint rule, no-underscore-dangle, with exceptions declared, to file-level --- lib/connect-logger.js | 3 ++- lib/logger.js | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/connect-logger.js b/lib/connect-logger.js index 9ca3d54..d39d371 100755 --- a/lib/connect-logger.js +++ b/lib/connect-logger.js @@ -1,3 +1,5 @@ +/* eslint no-underscore-dangle: ["error", { "allow": ["__statusCode", "_remoteAddress", "__headers", "_logging"] }] */ + const levels = require("./levels"); const DEFAULT_FORMAT = @@ -235,7 +237,6 @@ function matchRules(statusCode, currentLevel, ruleSet) { * @api public */ module.exports = function getLogger(logger4js, options) { - /* eslint no-underscore-dangle:0 */ if (typeof options === "string" || typeof options === "function") { options = { format: options }; } else { diff --git a/lib/logger.js b/lib/logger.js index 32600e9..26059cf 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -1,4 +1,5 @@ -/* eslint no-underscore-dangle:0 */ +/* eslint no-underscore-dangle: ["error", { "allow": ["_log"] }] */ + const debug = require("debug")("log4js:logger"); const LoggingEvent = require("./LoggingEvent"); const levels = require("./levels");