From: Justin Wind Date: Thu, 20 Jul 2023 21:31:24 +0000 (-0700) Subject: more lint cleanup X-Git-Tag: v1.2.10~2 X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=cea77553ae5746713defff5528a475c702797f37;p=squeep-api-dingus more lint cleanup --- diff --git a/CHANGELOG.md b/CHANGELOG.md index a173576..cd9edc7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ Releases and notable changes to this project are documented here. ## [Unreleased] -- matched route path stored on ctx is now string, not array +- the matched route path stored on ctx is now string, not array - minor cleanups - no longer add missing log levels to logger objects, that is a logger problem - updated devDependencies diff --git a/lib/common.js b/lib/common.js index d1abf3e..723f922 100644 --- a/lib/common.js +++ b/lib/common.js @@ -308,7 +308,7 @@ const ensureLoggerLevels = (logger = {}) => { const unfoldHeaderLines = (lines) => { const foldedLineRE = /^(\t| +)(.*)$/; if (lines) { - lines.reduceRight((_, line, idx) => { + lines.reduceRight((_, line, idx) => { // NOSONAR const result = foldedLineRE.exec(line); if (result && idx) { const prevIdx = idx - 1; diff --git a/lib/dingus.js b/lib/dingus.js index f55ad06..d8eed91 100644 --- a/lib/dingus.js +++ b/lib/dingus.js @@ -138,9 +138,9 @@ class Dingus { */ _getAddress(req) { // TODO: RFC7239 Forwarded support - const address = (this.trustProxy && req && req.getHeader(Enum.Header.XForwardedFor)) || - (this.trustProxy && req && req.getHeader(Enum.Header.XRealIP)) || - (req && req.connection && req.connection.remoteAddress) || + const address = (this.trustProxy && req?.getHeader(Enum.Header.XForwardedFor)) || + (this.trustProxy && req?.getHeader(Enum.Header.XRealIP)) || + (req?.connection?.remoteAddress) || ''; return address.split(/\s*,\s*/u)[0]; } @@ -152,8 +152,8 @@ class Dingus { */ _getProtocol(req) { // TODO: RFC7239 Forwarded support - const protocol = (this.trustProxy && req && req.getHeader(Enum.Header.XForwardedProto)) || - ((req && req.connection && req.connection.encrypted) ? 'https' : 'http'); + const protocol = (this.trustProxy && req?.getHeader(Enum.Header.XForwardedProto)) || + ((req?.connection?.encrypted) ? 'https' : 'http'); return protocol.split(/\s*,\s*/u)[0]; } @@ -538,7 +538,7 @@ class Dingus { // We will not deal with any subdirs, nor any dot-files. // (Note that we could not deal with subdirs even if we wanted, due to simple router matching scheme.) if (fileName.indexOf(path.sep) >= 0 - || fileName.charAt(0) === '.') { + || fileName.startsWith('.')) { this.logger.debug(_scope, 'rejected filename', { fileName }); return this.handlerNotFound(req, res, ctx); } @@ -651,7 +651,7 @@ class Dingus { res.setHeader(Enum.Header.ContentType, Enum.ContentType.TextPlain); } - if (err && err.statusCode) { + if (err?.statusCode) { res.statusCode = err.statusCode; body = this.renderError(res.getHeader(Enum.Header.ContentType), err); this.logger.debug(_scope, 'handler error', { err, req, res, ctx });