From fbf53939c35d23b2a2de9bc99f13835099e06265 Mon Sep 17 00:00:00 2001 From: derduher Date: Wed, 29 May 2024 20:18:53 -0700 Subject: [PATCH] [chore]: cleanup requires and unnecessary eslint-disables --- cli.ts | 13 ++++++------- lib/errors.ts | 1 - lib/sitemap-item-stream.ts | 1 - lib/utils.ts | 1 - package.json | 2 +- tests/sitemap-index-parser.test.ts | 4 ++-- tests/sitemap-parser.test.ts | 4 ++-- tests/xmllint.test.ts | 4 ++-- tsconfig.json | 3 ++- 9 files changed, 15 insertions(+), 18 deletions(-) diff --git a/cli.ts b/cli.ts index 6eead105..aaee99d8 100755 --- a/cli.ts +++ b/cli.ts @@ -13,8 +13,7 @@ import { SitemapAndIndexStream } from './lib/sitemap-index-stream'; import { URL } from 'url'; import { createGzip, Gzip } from 'zlib'; import { ErrorLevel } from './lib/types'; -/* eslint-disable-next-line @typescript-eslint/no-var-requires */ -const arg = require('arg'); +import arg from 'arg'; const pickStreamOrArg = (argv: { _: string[] }): Readable => { if (!argv._.length) { @@ -50,9 +49,9 @@ function getStream(): Readable { } } if (argv['--version']) { - /* eslint-disable-next-line @typescript-eslint/no-var-requires */ - const packagejson = require('../package.json'); - console.log(packagejson.version); + import('./package.json').then(({ default: packagejson }) => { + console.log(packagejson.version); + }); } else if (argv['--help']) { console.log(` Turn a list of urls into a sitemap xml. @@ -104,8 +103,8 @@ Use XMLLib to validate your sitemap (requires xmllib) } }); } else if (argv['--index']) { - const limit: number = argv['--limit']; - const baseURL: string = argv['--index-base-url']; + const limit: number | undefined = argv['--limit']; + const baseURL: string | undefined = argv['--index-base-url']; if (!baseURL) { throw new Error( "You must specify where the sitemaps will be hosted. use --index-base-url 'https://example.com/path'" diff --git a/lib/errors.ts b/lib/errors.ts index dd3702c6..bea45ff4 100644 --- a/lib/errors.ts +++ b/lib/errors.ts @@ -1,4 +1,3 @@ -/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ /* eslint-disable @typescript-eslint/no-explicit-any */ /*! * Sitemap diff --git a/lib/sitemap-item-stream.ts b/lib/sitemap-item-stream.ts index 92ec40a1..8e9440d0 100644 --- a/lib/sitemap-item-stream.ts +++ b/lib/sitemap-item-stream.ts @@ -17,7 +17,6 @@ function attrBuilder( const iv: StringObj = {}; return keys.reduce((attrs, key): StringObj => { - // eslint-disable-next-line if (conf[key] !== undefined) { const keyAr = key.split(':'); if (keyAr.length !== 2) { diff --git a/lib/utils.ts b/lib/utils.ts index df86ad2f..94c0634b 100644 --- a/lib/utils.ts +++ b/lib/utils.ts @@ -324,7 +324,6 @@ export function lineSeparatedURLsToSitemapOptions( return new ReadlineStream({ input: stream }).pipe( new Transform({ objectMode: true, - // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types transform: (line, encoding, cb): void => { if (isJSON || (isJSON === undefined && line[0] === '{')) { cb(null, JSON.parse(line)); diff --git a/package.json b/package.json index bd7d941b..d58c008a 100644 --- a/package.json +++ b/package.json @@ -80,4 +80,4 @@ "node": ">=18.20.3", "npm": ">=10.5.0" } -} +} \ No newline at end of file diff --git a/tests/sitemap-index-parser.test.ts b/tests/sitemap-index-parser.test.ts index 71a5a9f8..0c15ff5d 100644 --- a/tests/sitemap-index-parser.test.ts +++ b/tests/sitemap-index-parser.test.ts @@ -9,8 +9,8 @@ import { } from '../lib/sitemap-index-parser'; import { ErrorLevel, IndexItem } from '../lib/types'; const pipeline = promisify(pipe); -// eslint-disable-next-line @typescript-eslint/no-var-requires -const normalizedSample = require('./mocks/sampleconfig-index.normalized.json'); +import normalizedSample from './mocks/sampleconfig-index.normalized.json'; + describe('parseSitemapIndex', () => { it('parses xml into index-items', async () => { const urls = await parseSitemapIndex( diff --git a/tests/sitemap-parser.test.ts b/tests/sitemap-parser.test.ts index ee39373a..d05b6249 100644 --- a/tests/sitemap-parser.test.ts +++ b/tests/sitemap-parser.test.ts @@ -10,8 +10,8 @@ import { import { SitemapStreamOptions } from '../lib/sitemap-stream'; import { ErrorLevel, SitemapItem } from '../lib/types'; const pipeline = promisify(pipe); -// eslint-disable-next-line @typescript-eslint/no-var-requires -const normalizedSample = require('./mocks/sampleconfig.normalized.json'); +import normalizedSample from './mocks/sampleconfig.normalized.json'; + describe('parseSitemap', () => { it('parses xml into sitemap-items', async () => { const urls = await parseSitemap( diff --git a/tests/xmllint.test.ts b/tests/xmllint.test.ts index 78664d80..8d01077a 100644 --- a/tests/xmllint.test.ts +++ b/tests/xmllint.test.ts @@ -1,6 +1,6 @@ import { xmlLint } from '../lib/xmllint'; -// eslint-disable-next-line @typescript-eslint/no-var-requires -const execFileSync = require('child_process').execFileSync; +import { execFileSync } from 'child_process'; + let hasXMLLint = true; try { execFileSync('which', ['xmllint']); diff --git a/tsconfig.json b/tsconfig.json index f2cdf5c8..8182c0ff 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -10,7 +10,8 @@ "esModuleInterop": true, "moduleResolution": "node", "lib": ["es2022"], - "forceConsistentCasingInFileNames": true + "forceConsistentCasingInFileNames": true, + "resolveJsonModule": true }, "include": ["index.ts", "cli.ts"], "exclude": ["node_modules"]