From 87c179a5f3bc198a4c1caf774574b39413ad7486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josh=20Goldberg=20=E2=9C=A8?= Date: Wed, 24 Jul 2024 11:43:07 -0400 Subject: [PATCH] chore: bump @typescript-eslint/no-unused-vars to error internally (#11173) Co-authored-by: Florian Lefebvre Co-authored-by: Martin Trapp <94928215+martrapp@users.noreply.github.com> --- eslint.config.js | 2 +- packages/astro/e2e/view-transitions.test.js | 5 ++++- packages/astro/src/@types/astro.ts | 2 +- .../src/actions/runtime/virtual/server.ts | 8 ++++---- .../src/actions/runtime/virtual/shared.ts | 3 +++ .../src/content/vite-plugin-content-assets.ts | 17 +---------------- packages/astro/src/core/build/generate.ts | 2 +- packages/astro/src/core/build/pipeline.ts | 1 - packages/astro/src/env/runtime.ts | 5 +++-- .../dev-toolbar/apps/audit/rules/a11y.ts | 19 ------------------- .../runtime/server/render/astro/instance.ts | 2 +- .../astro/src/runtime/server/render/page.ts | 2 +- packages/astro/src/transitions/router.ts | 10 +--------- .../src/vite-plugin-astro-server/error.ts | 3 +-- .../src/vite-plugin-astro-server/route.ts | 1 - packages/astro/templates/env/module.mjs | 2 ++ .../test/reuse-injected-entrypoint.test.js | 2 -- .../sitemap/src/utils/is-valid-url.ts | 3 +-- 18 files changed, 25 insertions(+), 64 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 47e2b501c6..e92f3aea6f 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -62,7 +62,7 @@ export default [ // These off/configured-differently-by-default rules fit well for us '@typescript-eslint/switch-exhaustiveness-check': 'error', '@typescript-eslint/no-unused-vars': [ - 'warn', + 'error', { argsIgnorePattern: '^_', varsIgnorePattern: '^_', diff --git a/packages/astro/e2e/view-transitions.test.js b/packages/astro/e2e/view-transitions.test.js index da6fafc0c9..cbcd38497b 100644 --- a/packages/astro/e2e/view-transitions.test.js +++ b/packages/astro/e2e/view-transitions.test.js @@ -169,7 +169,6 @@ test.describe('View Transitions', () => { test('Moving from a page without ViewTransitions w/ back button', async ({ page, astro }) => { const loads = collectLoads(page); - // Go to page 1 await page.goto(astro.resolveUrl('/one')); let p = page.locator('#one'); @@ -184,6 +183,10 @@ test.describe('View Transitions', () => { await page.goBack(); p = page.locator('#one'); await expect(p, 'should have content').toHaveText('Page 1'); + expect( + loads.length, + 'There should be 3 page loads (for page one & three), and an additional loads for the back navigation' + ).toEqual(3); }); test('Stylesheets in the head are waited on', async ({ page, astro }) => { diff --git a/packages/astro/src/@types/astro.ts b/packages/astro/src/@types/astro.ts index db46ae5f67..2c24f74b53 100644 --- a/packages/astro/src/@types/astro.ts +++ b/packages/astro/src/@types/astro.ts @@ -50,7 +50,7 @@ import type { TransitionBeforePreparationEvent, TransitionBeforeSwapEvent, } from '../transitions/events.js'; -import type { DeepPartial, OmitIndexSignature, Simplify, WithRequired } from '../type-utils.js'; +import type { DeepPartial, OmitIndexSignature, Simplify } from '../type-utils.js'; import type { SUPPORTED_MARKDOWN_FILE_EXTENSIONS } from './../core/constants.js'; export type { AstroIntegrationLogger, ToolbarServerHelpers }; diff --git a/packages/astro/src/actions/runtime/virtual/server.ts b/packages/astro/src/actions/runtime/virtual/server.ts index 3efa7ca149..cfd96e1239 100644 --- a/packages/astro/src/actions/runtime/virtual/server.ts +++ b/packages/astro/src/actions/runtime/virtual/server.ts @@ -33,10 +33,10 @@ export type ActionClient< input: TAccept extends 'form' ? FormData : z.input ) => Promise< SafeResult< - z.input extends ErrorInferenceObject - ? z.input - : ErrorInferenceObject, - Awaited + z.input extends ErrorInferenceObject + ? z.input + : ErrorInferenceObject, + Awaited > >; } diff --git a/packages/astro/src/actions/runtime/virtual/shared.ts b/packages/astro/src/actions/runtime/virtual/shared.ts index 10ed75aa51..5c18828a60 100644 --- a/packages/astro/src/actions/runtime/virtual/shared.ts +++ b/packages/astro/src/actions/runtime/virtual/shared.ts @@ -43,6 +43,9 @@ const statusToCodeMap: Record = Object.entries(codeToSt {} ); +// T is used for error inference with SafeInput -> isInputError. +// See: https://github.com/withastro/astro/pull/11173/files#r1622767246 +// eslint-disable-next-line @typescript-eslint/no-unused-vars export class ActionError extends Error { type = 'AstroActionError'; code: ActionErrorCode = 'INTERNAL_SERVER_ERROR'; diff --git a/packages/astro/src/content/vite-plugin-content-assets.ts b/packages/astro/src/content/vite-plugin-content-assets.ts index d3228270a6..cba907bbf6 100644 --- a/packages/astro/src/content/vite-plugin-content-assets.ts +++ b/packages/astro/src/content/vite-plugin-content-assets.ts @@ -1,6 +1,6 @@ import { extname } from 'node:path'; import { pathToFileURL } from 'node:url'; -import type { Plugin, Rollup } from 'vite'; +import type { Plugin } from 'vite'; import type { AstroSettings, SSRElement } from '../@types/astro.js'; import { getAssetsPrefix } from '../assets/utils/getAssetsPrefix.js'; import type { BuildInternals } from '../core/build/internal.js'; @@ -129,22 +129,9 @@ export function astroConfigBuildPlugin( options: StaticBuildOptions, internals: BuildInternals ): AstroBuildPlugin { - let ssrPluginContext: Rollup.PluginContext | undefined = undefined; return { targets: ['server'], hooks: { - 'build:before': ({ target }) => { - return { - vitePlugin: { - name: 'astro:content-build-plugin', - generateBundle() { - if (target === 'server') { - ssrPluginContext = this; - } - }, - }, - }; - }, 'build:post': ({ ssrOutputs, clientOutputs, mutate }) => { const outputs = ssrOutputs.flatMap((o) => o.output); const prependBase = (src: string) => { @@ -232,8 +219,6 @@ export function astroConfigBuildPlugin( mutate(chunk, ['server'], newCode); } } - - ssrPluginContext = undefined; }, }, }; diff --git a/packages/astro/src/core/build/generate.ts b/packages/astro/src/core/build/generate.ts index 05a8f8b647..cc514e551c 100644 --- a/packages/astro/src/core/build/generate.ts +++ b/packages/astro/src/core/build/generate.ts @@ -199,7 +199,7 @@ async function generatePage( pipeline: BuildPipeline ) { // prepare information we need - const { config, internals, logger } = pipeline; + const { config, logger } = pipeline; const pageModulePromise = ssrEntry.page; // Calculate information of the page, like scripts, links and styles diff --git a/packages/astro/src/core/build/pipeline.ts b/packages/astro/src/core/build/pipeline.ts index 4a56dca4cd..7ef94acd9a 100644 --- a/packages/astro/src/core/build/pipeline.ts +++ b/packages/astro/src/core/build/pipeline.ts @@ -8,7 +8,6 @@ import type { import { getOutputDirectory } from '../../prerender/utils.js'; import { BEFORE_HYDRATION_SCRIPT_ID, PAGE_SCRIPT_ID } from '../../vite-plugin-scripts/index.js'; import type { SSRManifest } from '../app/types.js'; -import { DEFAULT_404_COMPONENT } from '../constants.js'; import { routeIsFallback, routeIsRedirect } from '../redirects/helpers.js'; import { RedirectSinglePageBuiltModule } from '../redirects/index.js'; import { Pipeline } from '../render/index.js'; diff --git a/packages/astro/src/env/runtime.ts b/packages/astro/src/env/runtime.ts index 57729cdb8b..022687d1eb 100644 --- a/packages/astro/src/env/runtime.ts +++ b/packages/astro/src/env/runtime.ts @@ -4,6 +4,7 @@ import type { ValidationResultInvalid } from './validators.js'; export { validateEnvVariable, getEnvFieldType } from './validators.js'; export type GetEnv = (key: string) => string | undefined; +type OnSetGetEnv = (reset: boolean) => void let _getEnv: GetEnv = (key) => process.env[key]; @@ -13,9 +14,9 @@ export function setGetEnv(fn: GetEnv, reset = false) { _onSetGetEnv(reset); } -let _onSetGetEnv = (reset: boolean) => {}; +let _onSetGetEnv: OnSetGetEnv = () => {}; -export function setOnSetGetEnv(fn: typeof _onSetGetEnv) { +export function setOnSetGetEnv(fn: OnSetGetEnv) { _onSetGetEnv = fn; } diff --git a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/rules/a11y.ts b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/rules/a11y.ts index 64b13f67b1..8cf15df3e9 100644 --- a/packages/astro/src/runtime/client/dev-toolbar/apps/audit/rules/a11y.ts +++ b/packages/astro/src/runtime/client/dev-toolbar/apps/audit/rules/a11y.ts @@ -126,12 +126,6 @@ const a11y_required_content = [ const a11y_distracting_elements = ['blink', 'marquee']; -// Unused for now -// eslint-disable-next-line @typescript-eslint/no-unused-vars -const a11y_nested_implicit_semantics = new Map([ - ['header', 'banner'], - ['footer', 'contentinfo'], -]); const a11y_implicit_semantics = new Map([ ['a', 'link'], ['area', 'link'], @@ -624,19 +618,6 @@ export const a11y: AuditRuleWithSelector[] = [ }, ]; -// Unused for now -// eslint-disable-next-line @typescript-eslint/no-unused-vars -const a11y_labelable = [ - 'button', - 'input', - 'keygen', - 'meter', - 'output', - 'progress', - 'select', - 'textarea', -]; - /** * Exceptions to the rule which follows common A11y conventions * TODO make this configurable by the user diff --git a/packages/astro/src/runtime/server/render/astro/instance.ts b/packages/astro/src/runtime/server/render/astro/instance.ts index a7745c03bb..1cfb5b524c 100644 --- a/packages/astro/src/runtime/server/render/astro/instance.ts +++ b/packages/astro/src/runtime/server/render/astro/instance.ts @@ -1,6 +1,6 @@ import type { SSRResult } from '../../../../@types/astro.js'; import type { ComponentSlots } from '../slot.js'; -import type { AstroComponentFactory, AstroFactoryReturnValue } from './factory.js'; +import type { AstroComponentFactory } from './factory.js'; import { isPromise } from '../../util.js'; import { renderChild } from '../any.js'; diff --git a/packages/astro/src/runtime/server/render/page.ts b/packages/astro/src/runtime/server/render/page.ts index 66e9973dce..32345d926a 100644 --- a/packages/astro/src/runtime/server/render/page.ts +++ b/packages/astro/src/runtime/server/render/page.ts @@ -1,4 +1,4 @@ -import type { AstroConfig, RouteData, SSRResult } from '../../../@types/astro.js'; +import type { RouteData, SSRResult } from '../../../@types/astro.js'; import { type NonAstroPageComponent, renderComponentToString } from './component.js'; import type { AstroComponentFactory } from './index.js'; diff --git a/packages/astro/src/transitions/router.ts b/packages/astro/src/transitions/router.ts index 29029cefb8..b5e1a22354 100644 --- a/packages/astro/src/transitions/router.ts +++ b/packages/astro/src/transitions/router.ts @@ -1,13 +1,5 @@ -import type { TransitionBeforePreparationEvent, TransitionBeforeSwapEvent } from './events.js'; +import type { TransitionBeforePreparationEvent } from './events.js'; import { TRANSITION_AFTER_SWAP, doPreparation, doSwap } from './events.js'; -import { - deselectScripts, - restoreFocus, - saveFocus, - swapBodyElement, - swapHeadElements, - swapRootAttributes, -} from './swap-functions.js'; import type { Direction, Fallback, Options } from './types.js'; type State = { diff --git a/packages/astro/src/vite-plugin-astro-server/error.ts b/packages/astro/src/vite-plugin-astro-server/error.ts index 464351943a..f29a49ba65 100644 --- a/packages/astro/src/vite-plugin-astro-server/error.ts +++ b/packages/astro/src/vite-plugin-astro-server/error.ts @@ -3,9 +3,8 @@ import type { ModuleLoader } from '../core/module-loader/index.js'; import type { DevPipeline } from './pipeline.js'; import { collectErrorMetadata } from '../core/errors/dev/index.js'; -import { AstroErrorData, createSafeError } from '../core/errors/index.js'; +import { createSafeError } from '../core/errors/index.js'; import { formatErrorMessage } from '../core/messages.js'; -import { eventError, telemetry } from '../events/index.js'; export function recordServerError( loader: ModuleLoader, diff --git a/packages/astro/src/vite-plugin-astro-server/route.ts b/packages/astro/src/vite-plugin-astro-server/route.ts index acd590661c..07d6cd2b14 100644 --- a/packages/astro/src/vite-plugin-astro-server/route.ts +++ b/packages/astro/src/vite-plugin-astro-server/route.ts @@ -1,7 +1,6 @@ import type http from 'node:http'; import type { ComponentInstance, ManifestData, RouteData } from '../@types/astro.js'; import { - DEFAULT_404_COMPONENT, REROUTE_DIRECTIVE_HEADER, REWRITE_DIRECTIVE_HEADER_KEY, clientLocalsSymbol, diff --git a/packages/astro/templates/env/module.mjs b/packages/astro/templates/env/module.mjs index 0e2dd89eb5..d7637af157 100644 --- a/packages/astro/templates/env/module.mjs +++ b/packages/astro/templates/env/module.mjs @@ -25,6 +25,8 @@ const _internalGetSecret = (key) => { throw createInvalidVariablesError(key, type, result); }; +// used while generating the virtual module +// eslint-disable-next-line @typescript-eslint/no-unused-vars setOnSetGetEnv((reset) => { // @@ON_SET_GET_ENV@@ }); diff --git a/packages/astro/test/reuse-injected-entrypoint.test.js b/packages/astro/test/reuse-injected-entrypoint.test.js index 18723f16ce..10b8e528f8 100644 --- a/packages/astro/test/reuse-injected-entrypoint.test.js +++ b/packages/astro/test/reuse-injected-entrypoint.test.js @@ -106,8 +106,6 @@ describe('Reuse injected entrypoint', () => { }); routes.forEach(({ description, url, fourOhFour, h1, p, htmlMatch }) => { - const isEndpoint = htmlMatch && !h1 && !p; - // checks URLs as written above it(description, async () => { const html = await fixture.fetch(url).then((res) => res.text()); diff --git a/packages/integrations/sitemap/src/utils/is-valid-url.ts b/packages/integrations/sitemap/src/utils/is-valid-url.ts index b140623b09..1a456da933 100644 --- a/packages/integrations/sitemap/src/utils/is-valid-url.ts +++ b/packages/integrations/sitemap/src/utils/is-valid-url.ts @@ -4,8 +4,7 @@ export const isValidUrl = (s: any) => { return false; } try { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const dummy = new URL(s); + new URL(s); return true; } catch { return false;