From fe88f89512d583e651f114fe010a35b33bae1910 Mon Sep 17 00:00:00 2001 From: Emanuele Stoppa Date: Tue, 7 Mar 2023 13:41:24 +0000 Subject: [PATCH] chore: use directive `@ts-expect-error` instead of `@ts-ignore` (#6429) --- packages/astro/src/core/add/babel.ts | 4 ++-- .../astro/src/core/build/plugins/plugin-internals.ts | 1 - packages/astro/src/core/endpoint/index.ts | 2 +- packages/astro/src/core/render/result.ts | 3 +-- packages/astro/src/jsx/renderer.ts | 2 +- packages/integrations/deno/src/server.ts | 4 ++-- packages/integrations/image/src/endpoint.ts | 2 +- packages/integrations/image/src/lib/get-image.ts | 4 ++-- packages/integrations/image/src/loaders/squoosh.ts | 1 - packages/integrations/image/src/vendor/squoosh/codecs.ts | 9 --------- .../integrations/image/src/vendor/squoosh/image-pool.ts | 1 - packages/integrations/image/src/vendor/squoosh/impl.ts | 1 - .../netlify/test/edge-functions/edge-basic.test.ts | 8 ++++---- .../netlify/test/edge-functions/prerender.test.ts | 6 +++--- .../netlify/test/edge-functions/root-dynamic.test.ts | 6 +++--- .../netlify/test/edge-functions/test-utils.ts | 4 ++-- packages/integrations/node/src/response-iterator.ts | 2 +- packages/integrations/preact/src/client-dev.ts | 1 - packages/markdown/remark/src/index.ts | 2 +- packages/webapi/src/lib/Image.ts | 2 +- packages/webapi/src/lib/utils.ts | 2 +- 21 files changed, 26 insertions(+), 41 deletions(-) diff --git a/packages/astro/src/core/add/babel.ts b/packages/astro/src/core/add/babel.ts index b7b0dd16192e..7da8eed6cd27 100644 --- a/packages/astro/src/core/add/babel.ts +++ b/packages/astro/src/core/add/babel.ts @@ -3,12 +3,12 @@ import parser from '@babel/parser'; import traverse from '@babel/traverse'; import * as t from '@babel/types'; -// @ts-ignore @babel/traverse isn't ESM and needs this trick +// @ts-expect-error @babel/traverse isn't ESM and needs this trick export const visit = traverse.default as typeof traverse; export { t }; export async function generate(ast: t.File) { - // @ts-ignore @babel/generator isn't ESM and needs this trick + // @ts-expect-error @babel/generator isn't ESM and needs this trick const astToText = generator.default as typeof generator; const { code } = astToText(ast); return code; diff --git a/packages/astro/src/core/build/plugins/plugin-internals.ts b/packages/astro/src/core/build/plugins/plugin-internals.ts index 1ea61a97aaf5..d181e8596d51 100644 --- a/packages/astro/src/core/build/plugins/plugin-internals.ts +++ b/packages/astro/src/core/build/plugins/plugin-internals.ts @@ -15,7 +15,6 @@ export function vitePluginInternals(input: Set, internals: BuildInternal external.push('shiki'); } - // @ts-ignore extra.ssr = { external, noExternal, diff --git a/packages/astro/src/core/endpoint/index.ts b/packages/astro/src/core/endpoint/index.ts index fbfa8cfd40b3..8554cfe78286 100644 --- a/packages/astro/src/core/endpoint/index.ts +++ b/packages/astro/src/core/endpoint/index.ts @@ -51,7 +51,7 @@ function createAPIContext({ }); }, url: new URL(request.url), - // @ts-ignore + // @ts-expect-error get clientAddress() { if (!(clientAddressSymbol in request)) { if (adapterName) { diff --git a/packages/astro/src/core/render/result.ts b/packages/astro/src/core/render/result.ts index 7d90b13e3a76..f1474a0a380a 100644 --- a/packages/astro/src/core/render/result.ts +++ b/packages/astro/src/core/render/result.ts @@ -174,7 +174,6 @@ export function createResult(args: CreateResultArgs): SSRResult { const Astro: AstroGlobal = { // @ts-expect-error __proto__: astroGlobal, - // @ts-ignore get clientAddress() { if (!(clientAddressSymbol in request)) { if (args.adapterName) { @@ -221,7 +220,7 @@ export function createResult(args: CreateResultArgs): SSRResult { writable: false, // TODO: Remove this hole "Deno" logic once our plugin gets Deno support value: async function (content: string, opts: MarkdownRenderingOptions) { - // @ts-ignore + // @ts-expect-error if (typeof Deno !== 'undefined') { throw new Error('Markdown is not supported in Deno SSR'); } diff --git a/packages/astro/src/jsx/renderer.ts b/packages/astro/src/jsx/renderer.ts index 3aee8520fc64..78ac1a0b2e3b 100644 --- a/packages/astro/src/jsx/renderer.ts +++ b/packages/astro/src/jsx/renderer.ts @@ -5,7 +5,7 @@ const renderer = { jsxTransformOptions: async () => { const { default: { default: jsx }, - // @ts-ignore + // @ts-expect-error } = await import('@babel/plugin-transform-react-jsx'); const { default: astroJSX } = await import('./babel.js'); return { diff --git a/packages/integrations/deno/src/server.ts b/packages/integrations/deno/src/server.ts index 8d3e074f5890..08d967065296 100644 --- a/packages/integrations/deno/src/server.ts +++ b/packages/integrations/deno/src/server.ts @@ -2,7 +2,7 @@ import type { SSRManifest } from 'astro'; import { App } from 'astro/app'; -// @ts-ignore +// @ts-expect-error import { fromFileUrl, serveFile, Server } from '@astrojs/deno/__deno_imports.js'; interface Options { @@ -15,7 +15,7 @@ let _server: Server | undefined = undefined; let _startPromise: Promise | undefined = undefined; async function* getPrerenderedFiles(clientRoot: URL): AsyncGenerator { - // @ts-ignore + // @ts-expect-error for await (const ent of Deno.readDir(clientRoot)) { if (ent.isDirectory) { yield* getPrerenderedFiles(new URL(`./${ent.name}/`, clientRoot)); diff --git a/packages/integrations/image/src/endpoint.ts b/packages/integrations/image/src/endpoint.ts index fc3e82c6744d..5a8ca554ba40 100644 --- a/packages/integrations/image/src/endpoint.ts +++ b/packages/integrations/image/src/endpoint.ts @@ -1,6 +1,6 @@ import type { APIRoute } from 'astro'; import mime from 'mime'; -// @ts-ignore +// @ts-expect-error import loader from 'virtual:image-loader'; import { etag } from './utils/etag.js'; import { isRemoteImage } from './utils/paths.js'; diff --git a/packages/integrations/image/src/lib/get-image.ts b/packages/integrations/image/src/lib/get-image.ts index 65526f653d09..d6aae4665257 100644 --- a/packages/integrations/image/src/lib/get-image.ts +++ b/packages/integrations/image/src/lib/get-image.ts @@ -111,7 +111,7 @@ export async function getImage( let loader = globalThis.astroImage?.loader; if (!loader) { - // @ts-ignore + // @ts-expect-error const { default: mod } = await import('virtual:image-loader').catch(() => { throw new Error( '[@astrojs/image] Builtin image loader not found. (Did you remember to add the integration to your Astro config?)' @@ -127,7 +127,7 @@ export async function getImage( const attributes = await loader.getImageAttributes(resolved); // `.env` must be optional to support running in environments outside of `vite` (such as `astro.config`) - // @ts-ignore + // @ts-expect-error const isDev = import.meta.env?.DEV; const isLocalImage = !isRemoteImage(resolved.src); diff --git a/packages/integrations/image/src/loaders/squoosh.ts b/packages/integrations/image/src/loaders/squoosh.ts index a5be16adb019..e4ea530475df 100644 --- a/packages/integrations/image/src/loaders/squoosh.ts +++ b/packages/integrations/image/src/loaders/squoosh.ts @@ -1,4 +1,3 @@ -// @ts-ignore import { red } from 'kleur/colors'; import { error } from '../utils/logger.js'; import { metadata } from '../utils/metadata.js'; diff --git a/packages/integrations/image/src/vendor/squoosh/codecs.ts b/packages/integrations/image/src/vendor/squoosh/codecs.ts index 85ccb51a77d9..b65691a624ed 100644 --- a/packages/integrations/image/src/vendor/squoosh/codecs.ts +++ b/packages/integrations/image/src/vendor/squoosh/codecs.ts @@ -35,46 +35,37 @@ export interface RotateOptions { // MozJPEG import type { MozJPEGModule as MozJPEGEncodeModule } from './mozjpeg/mozjpeg_enc' -// @ts-ignore import mozEnc from './mozjpeg/mozjpeg_node_enc.js' const mozEncWasm = new URL('./mozjpeg/mozjpeg_node_enc.wasm', getModuleURL(import.meta.url)) -// @ts-ignore import mozDec from './mozjpeg/mozjpeg_node_dec.js' const mozDecWasm = new URL('./mozjpeg/mozjpeg_node_dec.wasm', getModuleURL(import.meta.url)) // WebP import type { WebPModule as WebPEncodeModule } from './webp/webp_enc' -// @ts-ignore import webpEnc from './webp/webp_node_enc.js' const webpEncWasm = new URL('./webp/webp_node_enc.wasm', getModuleURL(import.meta.url)) -// @ts-ignore import webpDec from './webp/webp_node_dec.js' const webpDecWasm = new URL('./webp/webp_node_dec.wasm', getModuleURL(import.meta.url)) // AVIF import type { AVIFModule as AVIFEncodeModule } from './avif/avif_enc' -// @ts-ignore import avifEnc from './avif/avif_node_enc.js' const avifEncWasm = new URL('./avif/avif_node_enc.wasm', getModuleURL(import.meta.url)) -// @ts-ignore import avifDec from './avif/avif_node_dec.js' const avifDecWasm = new URL('./avif/avif_node_dec.wasm', getModuleURL(import.meta.url)) // PNG -// @ts-ignore import * as pngEncDec from './png/squoosh_png.js' const pngEncDecWasm = new URL('./png/squoosh_png_bg.wasm', getModuleURL(import.meta.url)) const pngEncDecInit = () => pngEncDec.default(fsp.readFile(pathify(pngEncDecWasm.toString()))) // OxiPNG -// @ts-ignore import * as oxipng from './png/squoosh_oxipng.js' const oxipngWasm = new URL('./png/squoosh_oxipng_bg.wasm', getModuleURL(import.meta.url)) const oxipngInit = () => oxipng.default(fsp.readFile(pathify(oxipngWasm.toString()))) // Resize -// @ts-ignore import * as resize from './resize/squoosh_resize.js' const resizeWasm = new URL('./resize/squoosh_resize_bg.wasm', getModuleURL(import.meta.url)) const resizeInit = () => resize.default(fsp.readFile(pathify(resizeWasm.toString()))) diff --git a/packages/integrations/image/src/vendor/squoosh/image-pool.ts b/packages/integrations/image/src/vendor/squoosh/image-pool.ts index 4275aa8ebc9a..04606285ba1f 100644 --- a/packages/integrations/image/src/vendor/squoosh/image-pool.ts +++ b/packages/integrations/image/src/vendor/squoosh/image-pool.ts @@ -91,7 +91,6 @@ export async function processBuffer( encoding: OutputFormat, quality?: number ): Promise { - // @ts-ignore const worker = await getWorker(); let imageData = await worker.dispatchJob({ diff --git a/packages/integrations/image/src/vendor/squoosh/impl.ts b/packages/integrations/image/src/vendor/squoosh/impl.ts index 3d01141d3e76..4c57730f7372 100644 --- a/packages/integrations/image/src/vendor/squoosh/impl.ts +++ b/packages/integrations/image/src/vendor/squoosh/impl.ts @@ -44,7 +44,6 @@ export async function decodeBuffer( const encoder = supportedFormats[key] const mod = await encoder.dec() const rgba = mod.decode(new Uint8Array(buffer)) - // @ts-ignore return rgba } diff --git a/packages/integrations/netlify/test/edge-functions/edge-basic.test.ts b/packages/integrations/netlify/test/edge-functions/edge-basic.test.ts index 8283fe579bf6..2e3ae4d5fe77 100644 --- a/packages/integrations/netlify/test/edge-functions/edge-basic.test.ts +++ b/packages/integrations/netlify/test/edge-functions/edge-basic.test.ts @@ -1,12 +1,12 @@ -// @ts-ignore +// @ts-expect-error import { runBuild } from './test-utils.ts'; -// @ts-ignore +// @ts-expect-error import { assertEquals, assert, DOMParser } from './deps.ts'; -// @ts-ignore +// @ts-expect-error Deno.env.set('SECRET_STUFF', 'secret'); -// @ts-ignore +// @ts-expect-error Deno.test({ // TODO: debug why build cannot be found in "await import" ignore: true, diff --git a/packages/integrations/netlify/test/edge-functions/prerender.test.ts b/packages/integrations/netlify/test/edge-functions/prerender.test.ts index 98065d9bf5f5..976c50b5f000 100644 --- a/packages/integrations/netlify/test/edge-functions/prerender.test.ts +++ b/packages/integrations/netlify/test/edge-functions/prerender.test.ts @@ -1,9 +1,9 @@ -// @ts-ignore +// @ts-expect-error import { runBuild } from './test-utils.ts'; -// @ts-ignore +// @ts-expect-error import { assertEquals } from './deps.ts'; -// @ts-ignore +// @ts-expect-error Deno.test({ name: 'Prerender', async fn() { diff --git a/packages/integrations/netlify/test/edge-functions/root-dynamic.test.ts b/packages/integrations/netlify/test/edge-functions/root-dynamic.test.ts index 954c590eeefc..8e05b05de70a 100644 --- a/packages/integrations/netlify/test/edge-functions/root-dynamic.test.ts +++ b/packages/integrations/netlify/test/edge-functions/root-dynamic.test.ts @@ -1,9 +1,9 @@ -// @ts-ignore +// @ts-expect-error import { runBuild } from './test-utils.ts'; -// @ts-ignore +// @ts-expect-error import { assertEquals, assert, DOMParser } from './deps.ts'; -// @ts-ignore +// @ts-expect-error Deno.test({ // TODO: debug why build cannot be found in "await import" ignore: true, diff --git a/packages/integrations/netlify/test/edge-functions/test-utils.ts b/packages/integrations/netlify/test/edge-functions/test-utils.ts index 7c2400d93a7d..7ba078a3a53f 100644 --- a/packages/integrations/netlify/test/edge-functions/test-utils.ts +++ b/packages/integrations/netlify/test/edge-functions/test-utils.ts @@ -1,9 +1,9 @@ -// @ts-ignore +// @ts-expect-error import { fromFileUrl, readableStreamFromReader } from './deps.ts'; const dir = new URL('./', import.meta.url); export async function runBuild(fixturePath: string) { - // @ts-ignore + // @ts-expect-error let proc = Deno.run({ cmd: ['node', '../../../../../../astro/astro.js', 'build', '--silent'], cwd: fromFileUrl(new URL(fixturePath, dir)), diff --git a/packages/integrations/node/src/response-iterator.ts b/packages/integrations/node/src/response-iterator.ts index 890902e1e039..3b83824f0acb 100644 --- a/packages/integrations/node/src/response-iterator.ts +++ b/packages/integrations/node/src/response-iterator.ts @@ -70,7 +70,7 @@ function readerIterator(reader: ReadableStreamDefaultReader): AsyncIterabl if (canUseAsyncIteratorSymbol) { iterator[Symbol.asyncIterator] = function (): AsyncIterator { - //@ts-ignore + //@ts-expect-error return this; }; } diff --git a/packages/integrations/preact/src/client-dev.ts b/packages/integrations/preact/src/client-dev.ts index 9a9edcb3bbfc..d37e6e0afd8e 100644 --- a/packages/integrations/preact/src/client-dev.ts +++ b/packages/integrations/preact/src/client-dev.ts @@ -1,4 +1,3 @@ -// @ts-ignore import 'preact/debug'; import clientFn from './client.js'; diff --git a/packages/markdown/remark/src/index.ts b/packages/markdown/remark/src/index.ts index fdd669280b5f..79b5b3ad5ef9 100644 --- a/packages/markdown/remark/src/index.ts +++ b/packages/markdown/remark/src/index.ts @@ -144,7 +144,7 @@ function prefixError(err: any, prefix: string) { const wrappedError = new Error(`${prefix}${err ? `: ${err}` : ''}`); try { wrappedError.stack = err.stack; - // @ts-ignore + // @ts-expect-error wrappedError.cause = err; } catch (error) { // It's ok if we could not set the stack or cause - the message is the most important part diff --git a/packages/webapi/src/lib/Image.ts b/packages/webapi/src/lib/Image.ts index 4f403e94503b..c2e0a10fb357 100644 --- a/packages/webapi/src/lib/Image.ts +++ b/packages/webapi/src/lib/Image.ts @@ -2,7 +2,7 @@ import { HTMLImageElement } from './HTMLImageElement' import * as _ from './utils' export function Image() { - // @ts-ignore + // @ts-expect-error _.INTERNALS.set(this, { attributes: {}, localName: 'img', diff --git a/packages/webapi/src/lib/utils.ts b/packages/webapi/src/lib/utils.ts index 61a78e97be71..63a6bba7bb3e 100644 --- a/packages/webapi/src/lib/utils.ts +++ b/packages/webapi/src/lib/utils.ts @@ -17,7 +17,7 @@ export const __object_isPrototypeOf = Function.call.bind( /** Current high resolution millisecond timestamp. */ export const __performance_now = performance.now as () => number -// @ts-ignore +// @ts-expect-error export const INTERNALS = new WeakMap() export const internalsOf = (