Skip to content

Commit

Permalink
chore: bump @typescript-eslint/no-unused-vars to error internally (#1…
Browse files Browse the repository at this point in the history
…1173)

Co-authored-by: Florian Lefebvre <contact@florian-lefebvre.dev>
Co-authored-by: Martin Trapp <94928215+martrapp@users.noreply.github.com>
  • Loading branch information
3 people authored Jul 24, 2024
1 parent 536209a commit 87c179a
Show file tree
Hide file tree
Showing 18 changed files with 25 additions and 64 deletions.
2 changes: 1 addition & 1 deletion eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: '^_',
Expand Down
5 changes: 4 additions & 1 deletion packages/astro/e2e/view-transitions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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 }) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
8 changes: 4 additions & 4 deletions packages/astro/src/actions/runtime/virtual/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ export type ActionClient<
input: TAccept extends 'form' ? FormData : z.input<TInputSchema>
) => Promise<
SafeResult<
z.input<TInputSchema> extends ErrorInferenceObject
? z.input<TInputSchema>
: ErrorInferenceObject,
Awaited<TOutput>
z.input<TInputSchema> extends ErrorInferenceObject
? z.input<TInputSchema>
: ErrorInferenceObject,
Awaited<TOutput>
>
>;
}
Expand Down
3 changes: 3 additions & 0 deletions packages/astro/src/actions/runtime/virtual/shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ const statusToCodeMap: Record<number, ActionErrorCode> = 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<T extends ErrorInferenceObject = ErrorInferenceObject> extends Error {
type = 'AstroActionError';
code: ActionErrorCode = 'INTERNAL_SERVER_ERROR';
Expand Down
17 changes: 1 addition & 16 deletions packages/astro/src/content/vite-plugin-content-assets.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -232,8 +219,6 @@ export function astroConfigBuildPlugin(
mutate(chunk, ['server'], newCode);
}
}

ssrPluginContext = undefined;
},
},
};
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/core/build/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/core/build/pipeline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
5 changes: 3 additions & 2 deletions packages/astro/src/env/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];

Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'],
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/render/astro/instance.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/astro/src/runtime/server/render/page.ts
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
10 changes: 1 addition & 9 deletions packages/astro/src/transitions/router.ts
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
3 changes: 1 addition & 2 deletions packages/astro/src/vite-plugin-astro-server/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion packages/astro/src/vite-plugin-astro-server/route.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/astro/templates/env/module.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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@@
});
2 changes: 0 additions & 2 deletions packages/astro/test/reuse-injected-entrypoint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
3 changes: 1 addition & 2 deletions packages/integrations/sitemap/src/utils/is-valid-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 87c179a

Please sign in to comment.