From f411dde51a6ec6dbec5a96f67ab03fe7d9c2f81e Mon Sep 17 00:00:00 2001 From: Sergio Zharinov <zharinov@users.noreply.github.com> Date: Thu, 27 Aug 2020 11:12:37 +0400 Subject: [PATCH] refactor(logger): Fix lint warnings (#7109) --- lib/logger/cmd-serializer.ts | 4 +++- lib/logger/err-serializer.ts | 16 ++++++++++++++-- lib/logger/index.ts | 6 ++---- lib/logger/pretty-stdout.ts | 2 +- lib/logger/utils.ts | 13 ++++++++----- 5 files changed, 28 insertions(+), 13 deletions(-) diff --git a/lib/logger/cmd-serializer.ts b/lib/logger/cmd-serializer.ts index b3aabfb340..ba656b9d48 100644 --- a/lib/logger/cmd-serializer.ts +++ b/lib/logger/cmd-serializer.ts @@ -1,5 +1,7 @@ // istanbul ignore next -export default function (cmd: string | string[]): string | string[] { +export default function cmdSerializer( + cmd: string | string[] +): string | string[] { if (typeof cmd === 'string') { return cmd.replace(/https:\/\/[^@]*@/g, 'https://**redacted**@'); } diff --git a/lib/logger/err-serializer.ts b/lib/logger/err-serializer.ts index 8bc0b266c1..b62225f9b7 100644 --- a/lib/logger/err-serializer.ts +++ b/lib/logger/err-serializer.ts @@ -2,8 +2,20 @@ import is from '@sindresorhus/is'; Error.stackTraceLimit = 20; -// eslint-disable-next-lint @typescript-eslint/explicit-module-boundary-types -export default function errSerializer(err: any): any { +interface Err { + body?: unknown; + response?: { + body?: unknown; + }; + message?: unknown; + stack?: unknown; + gotOptions?: { + auth?: unknown; + headers?: unknown; + }; +} + +export default function errSerializer(err: Err): any { const response = { ...err, }; diff --git a/lib/logger/index.ts b/lib/logger/index.ts index 499a60ec2d..bdf75289e4 100644 --- a/lib/logger/index.ts +++ b/lib/logger/index.ts @@ -111,14 +111,12 @@ export function getContext(): any { } // setMeta overrides existing meta, may remove fields if no longer existing -// eslint-disable-next-lint @typescript-eslint/explicit-module-boundary-types -export function setMeta(obj: any): void { +export function setMeta(obj: Record<string, unknown>): void { meta = { ...obj }; } // addMeta overrides or adds fields but does not remove any -// eslint-disable-next-lint @typescript-eslint/explicit-module-boundary-types -export function addMeta(obj: any): void { +export function addMeta(obj: Record<string, unknown>): void { meta = { ...meta, ...obj }; } diff --git a/lib/logger/pretty-stdout.ts b/lib/logger/pretty-stdout.ts index c43408c173..643fb773c3 100644 --- a/lib/logger/pretty-stdout.ts +++ b/lib/logger/pretty-stdout.ts @@ -50,7 +50,7 @@ export function getMeta(rec: BunyanRecord): string { return res; } const metaStr = filteredMeta - .map((field) => `${field}=${rec[field]}`) + .map((field) => `${field}=${String(rec[field])}`) .join(', '); res = ` (${metaStr})${res}`; return chalk.gray(res); diff --git a/lib/logger/utils.ts b/lib/logger/utils.ts index 944a362856..af1d97cd16 100644 --- a/lib/logger/utils.ts +++ b/lib/logger/utils.ts @@ -92,14 +92,17 @@ function sanitizeValue(value: any, seen = new WeakMap()): any { return valueType === 'string' ? sanitize(value) : value; } -// TODO -// eslint-disable-next-lint @typescript-eslint/explicit-module-boundary-types -export function withSanitizer(streamConfig): bunyan.Stream { +type BunyanStream = (NodeJS.WritableStream | Stream) & { + writable?: boolean; + write: (chunk: BunyanRecord, enc, cb) => void; +}; + +export function withSanitizer(streamConfig: bunyan.Stream): bunyan.Stream { if (streamConfig.type === 'rotating-file') { throw new Error("Rotating files aren't supported"); } - const stream = streamConfig.stream; + const stream = streamConfig.stream as BunyanStream; if (stream?.writable) { const write = (chunk: BunyanRecord, enc, cb): void => { const raw = sanitizeValue(chunk); @@ -114,7 +117,7 @@ export function withSanitizer(streamConfig): bunyan.Stream { ...streamConfig, type: 'raw', stream: { write }, - }; + } as bunyan.Stream; } if (streamConfig.path) { -- GitLab