From cf99df8abe6e0b402e74e008fb4065a9bb715c60 Mon Sep 17 00:00:00 2001 From: Gordon Date: Thu, 27 Oct 2022 15:44:28 -0500 Subject: [PATCH] Fix remaining lint issues --- .eslintrc.js | 4 +++- src/build_pipeline.ts | 2 +- src/divergent_stream_wrapper.ts | 8 ++++---- src/event_forwarder.ts | 1 + src/fetch_interface.ts | 2 +- src/fetcher.test.ts | 18 +++++++++--------- src/formatters/console.ts | 4 ++-- src/formatters/table.ts | 2 +- src/formatters/write-out.ts | 4 ++-- src/hostname_set.ts | 4 ++-- src/index.ts | 12 ++++++------ src/parsers/index.ts | 2 +- src/parsers/json-parser.ts | 17 +++++++++-------- 13 files changed, 42 insertions(+), 38 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 4647f54..4d6ef33 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -25,6 +25,8 @@ module.exports = { }], 'semi': ['error','never'], '@typescript-eslint/no-explicit-any': 'off', - '@typescript-eslint/no-non-null-assertion': 'off' + '@typescript-eslint/no-non-null-assertion': 'off', + '@typescript-eslint/no-unused-vars': 'off', + '@typescript-eslint/no-empty-function': 'off' } } diff --git a/src/build_pipeline.ts b/src/build_pipeline.ts index ccbccc1..718b34f 100644 --- a/src/build_pipeline.ts +++ b/src/build_pipeline.ts @@ -141,7 +141,7 @@ export function BuildPipeline( source .pipe(urlParser) .pipe(sourceUrlTracker) - // reentry is responsible for ending itself when the EOF handler sends the EOF back + // reentry is responsible for ending itself when the EOF handler sends the EOF back .pipe(reentry, { end: false }) .pipe(fetcher) .pipe(eofHandler) diff --git a/src/divergent_stream_wrapper.ts b/src/divergent_stream_wrapper.ts index 4dc4846..c010cb2 100644 --- a/src/divergent_stream_wrapper.ts +++ b/src/divergent_stream_wrapper.ts @@ -28,10 +28,10 @@ export class DivergentStreamWrapper extends ParallelTransform { private readonly _streams: Map private readonly _createStreamOptions: CreateStreamOptions private readonly _forwarder = new EventForwarder({ - // Don't forward the normal stream events from inner streams, just the - // special Linkscanner events - ignore: StreamEvents, - }).to(this) + // Don't forward the normal stream events from inner streams, just the + // special Linkscanner events + ignore: StreamEvents, + }).to(this) constructor(options: DivergentStreamWrapperOptions) { super({ diff --git a/src/event_forwarder.ts b/src/event_forwarder.ts index 51f926b..973ff04 100644 --- a/src/event_forwarder.ts +++ b/src/event_forwarder.ts @@ -53,6 +53,7 @@ export class EventForwarder { addMethods.forEach((methodName) => { const oldMethod = emitter[methodName] + // eslint-disable-next-line @typescript-eslint/no-this-alias const self = this emitter[methodName] = function(event: string | symbol, listener: (...args: any[]) => void) { const ignore = self._options.ignore && self._options.ignore.has(event) diff --git a/src/fetch_interface.ts b/src/fetch_interface.ts index 9897d13..fedaca0 100644 --- a/src/fetch_interface.ts +++ b/src/fetch_interface.ts @@ -46,7 +46,7 @@ export class FetchInterfaceWrapper implements FetchInterface { interval: maxConcurrency.interval, }) - // tslint:disable-next-line: max-classes-per-file + // tslint:disable-next-line: max-classes-per-file this.Request = class { constructor(url: string, requestInit?: RequestInit) { // add in the headers inside the request constructor call diff --git a/src/fetcher.test.ts b/src/fetcher.test.ts index 1304deb..2ee4455 100644 --- a/src/fetcher.test.ts +++ b/src/fetcher.test.ts @@ -14,15 +14,15 @@ describe('Fetcher', () => { let options: Partial let fetchMockSandbox: fetchMock.FetchMockSandbox beforeEach(() => { - fetchMock.reset() - fetchMockSandbox = fetchMock.sandbox() - options = { - fetch: { - fetch: fetchMockSandbox, - Request: fetchMock.config.Request!, - }, - } - }) + fetchMock.reset() + fetchMockSandbox = fetchMock.sandbox() + options = { + fetch: { + fetch: fetchMockSandbox, + Request: fetchMock.config.Request!, + }, + } + }) const instance = (additionalOptions?: Partial) => new Fetcher({ diff --git a/src/formatters/console.ts b/src/formatters/console.ts index eb2d712..f5d5085 100644 --- a/src/formatters/console.ts +++ b/src/formatters/console.ts @@ -183,8 +183,8 @@ export class ConsoleFormatter extends Writable { chalk.dim(`\t${linkCount.toFixed(0)} links found. ${excludedResults.length.toFixed(0)} not checked. `) + (brokenResults.length == 0 ? (successResults.length > 0 ? chalk.green(`0 broken.`) : '') : - chalk.red(`${brokenResults.length} broken.`)), - ) + chalk.red(`${brokenResults.length} broken.`)), + ) } /** diff --git a/src/formatters/table.ts b/src/formatters/table.ts index ecc8a5f..c0e51b0 100644 --- a/src/formatters/table.ts +++ b/src/formatters/table.ts @@ -58,7 +58,7 @@ export class TableFormatter extends Writable { if (!verbose) { if (isSuccessResult(result)) { if (!result.leaf && [301, 302, 307].includes(result.status)) { - // don't log non-leaf redirects unless verbose + // don't log non-leaf redirects unless verbose return } diff --git a/src/formatters/write-out.ts b/src/formatters/write-out.ts index eab8a53..b159b0b 100644 --- a/src/formatters/write-out.ts +++ b/src/formatters/write-out.ts @@ -13,7 +13,7 @@ export interface WriteOutFormatterOptions { export class WriteOutFormatter extends Writable { - public static readonly templateRegexp = /[\$\%]\{(?[^\}]*)\}/g + public static readonly templateRegexp = /[$%]\{(?[^}]*)\}/g private readonly options: WriteOutFormatterOptions private readonly results = new Map() @@ -147,7 +147,7 @@ export class WriteOutFormatter extends Writable { const {logger, formatter} = this.options let matchedOne = false let matches: RegExpExecArray | null - // tslint:disable-next-line: no-conditional-assignment + // eslint-disable-next-line no-cond-assign while (matches = WriteOutFormatter.templateRegexp.exec(formatter)) { matchedOne = true if (matches.groups && diff --git a/src/hostname_set.ts b/src/hostname_set.ts index aafe493..aa3b574 100644 --- a/src/hostname_set.ts +++ b/src/hostname_set.ts @@ -32,7 +32,7 @@ export class HostnameSet { private readonly _options: HostnameSetOptions constructor(public readonly hostnames: Set, - options?: Options) { + options?: Options) { this._options = assign({ followRedirects: false, ignoreRobotsFile: false, @@ -42,7 +42,7 @@ export class HostnameSet { maxConcurrency: 1, parsers: {}, }, - options) + options) } public async lockFor(host: Host): Promise { diff --git a/src/index.ts b/src/index.ts index dbd36e7..4994482 100644 --- a/src/index.ts +++ b/src/index.ts @@ -100,9 +100,9 @@ export const runDefaults: Readonly = { verbose: false, debug: false, progress: !!( - typeof process != 'undefined' && + typeof process != 'undefined' && process.stderr.isTTY - ), + ), } /** @@ -279,8 +279,8 @@ class Builder { _progress?: Builder['_progress'], }, ) { - this._formatters = previousBuilder ? previousBuilder._formatters : [] - this._progress = previousBuilder && previousBuilder._progress + this._formatters = previousBuilder ? previousBuilder._formatters : [] + this._progress = previousBuilder && previousBuilder._progress } /** @@ -294,7 +294,7 @@ class Builder { f = defaultFormatter } else if (formatters[formatter]) { f = formatters[formatter] - } else if (/[\$\%]{/.test(formatter)) { + } else if (/[$%]{/.test(formatter)) { f = formatters['write-out'] } if (!f) { @@ -325,7 +325,7 @@ class Builder { return new Builder({ ...this._options, - // the progress bar intercepts logging so as to clear & rewrite after each log line + // the progress bar intercepts logging so as to clear & rewrite after each log line logger: _progress, }, { ...this, diff --git a/src/parsers/index.ts b/src/parsers/index.ts index 8d09be3..940a605 100644 --- a/src/parsers/index.ts +++ b/src/parsers/index.ts @@ -55,7 +55,7 @@ export const defaultParsers = (options?: Options html, application/vnd.blah+json => json - const lastPart = key.split(/[\/\+]/).filter((p) => p.length > 0).pop() + const lastPart = key.split(/[/+]/).filter((p) => p.length > 0).pop() if (lastPart && only.includes(lastPart)) { return } diff --git a/src/parsers/json-parser.ts b/src/parsers/json-parser.ts index 64f1c8c..52fa174 100644 --- a/src/parsers/json-parser.ts +++ b/src/parsers/json-parser.ts @@ -14,7 +14,7 @@ const defaultIncludes = [ ] export class JsonParser { - public static readonly regexp = /^\s*((((ftp|http|https):)?\/\/)|\/)[^ "<\{\}]+\s*$/igm + public static readonly regexp = /^\s*((((ftp|http|https):)?\/\/)|\/)[^ "<{}]+\s*$/igm private readonly _options: ParserOptions private readonly _seen = new Set() @@ -64,7 +64,7 @@ export class JsonParser { private* traverse(json: any): Iterable { for (const path of this._options.include) { for (const obj of JSONPath({ path, json })) { - // directly selected strings + // directly selected strings if (typeof obj == 'string') { yield obj @@ -79,6 +79,7 @@ export class JsonParser { // objects } else if (typeof obj == 'object') { for (const key of Object.keys(obj)) { + // eslint-disable-next-line no-prototype-builtins if (!obj.hasOwnProperty(key)) { continue } if (typeof obj[key] != 'string') { continue } @@ -95,11 +96,11 @@ export class JsonParser { */ function* traverse(o: any, path: string[] = []): Iterable<{ key: string, value: string, path: string[]}> { for (const i of Object.keys(o)) { - const itemPath = path.concat(i) - yield {key: i, value: o[i], path: itemPath } - if (o[i] !== null && typeof(o[i]) == 'object') { - // going one step down in the object tree!! - yield* traverse(o[i], itemPath) - } + const itemPath = path.concat(i) + yield {key: i, value: o[i], path: itemPath } + if (o[i] !== null && typeof(o[i]) == 'object') { + // going one step down in the object tree!! + yield* traverse(o[i], itemPath) + } } }