diff --git a/AGENTS.md b/AGENTS.md index 0b6ef049..cb4f4f86 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -145,7 +145,7 @@ Document new variables in `README.md` and `.env.example`; don't read `env` ad ho - Run `npm run format`. - British English. - Use `resolve()` from `$app/paths` for internal links and `goto` (`svelte/no-navigation-without-resolve`). -- **Redirects**: never wrap `throw redirect()` in try-catch; put it after the try-catch. +- **Redirects and errors**: `redirect()` and `error()` throw by themselves, so call them without `throw` (`only-throw-error`). Never call `redirect()` inside a try-catch; put it after the try-catch. ```typescript try { @@ -153,7 +153,7 @@ Document new variables in `README.md` and `.env.example`; don't read `env` ad ho } catch (err) { return fail(500, { error: 'Failed' }); } - throw redirect(303, '/path'); + redirect(303, '/path'); ``` - **Public routes**: add unauthenticated paths to `PUBLIC_PATHS` in `hooks.server.ts`. `/metrics` and `/healthz` are permanently public — never put auth in front of them. diff --git a/e2e/storage/context-menu.spec.ts b/e2e/storage/context-menu.spec.ts index 9c92f3d9..4d157253 100644 --- a/e2e/storage/context-menu.spec.ts +++ b/e2e/storage/context-menu.spec.ts @@ -86,9 +86,7 @@ test.describe('Storage S3 — Context Menu', () => { await page.getByRole('button', { name: 'Delete permanently' }).click(); await expect(page.getByText('This folder is empty')).toBeVisible(); - await expect(await objectExists(client, credentials.bucket, `${prefix}ctx-del.txt`)).toBe( - false - ); + expect(await objectExists(client, credentials.bucket, `${prefix}ctx-del.txt`)).toBe(false); } finally { await deleteKnownKeys(client, credentials.bucket, cleanupKeys); } diff --git a/e2e/storage/delete.spec.ts b/e2e/storage/delete.spec.ts index 36c0d074..cff4a002 100644 --- a/e2e/storage/delete.spec.ts +++ b/e2e/storage/delete.spec.ts @@ -47,12 +47,10 @@ test.describe('Storage S3 — Delete & Selection', () => { await page.getByRole('dialog').getByRole('button', { name: 'Delete permanently' }).click(); await expect(page.getByText('This folder is empty')).toBeVisible(); - await expect(await objectExists(client, credentials.bucket, `${prefix}remove-me.txt`)).toBe( + expect(await objectExists(client, credentials.bucket, `${prefix}remove-me.txt`)).toBe(false); + expect(await objectExists(client, credentials.bucket, `${prefix}archive/nested.txt`)).toBe( false ); - await expect( - await objectExists(client, credentials.bucket, `${prefix}archive/nested.txt`) - ).toBe(false); } finally { await deleteKnownKeys(client, credentials.bucket, cleanupKeys); } @@ -151,7 +149,7 @@ test.describe('Storage S3 — Delete & Selection', () => { page.getByRole('menuitem', { name: 'Download' }).click() ]); expect(await download.failure()).toBeNull(); - expect(await readFile((await download.path())!, 'utf8')).toBe(body); + expect(await readFile(await download.path(), 'utf8')).toBe(body); } await page.getByRole('button', { name: 'Toggle selection mode' }).click(); @@ -193,9 +191,7 @@ test.describe('Storage S3 — Delete & Selection', () => { await expect(page.getByText('This action cannot be undone.')).not.toBeVisible(); await expect(rowByName(page, 'keep-me.txt')).toBeVisible(); - await expect(await objectExists(client, credentials.bucket, `${prefix}keep-me.txt`)).toBe( - true - ); + expect(await objectExists(client, credentials.bucket, `${prefix}keep-me.txt`)).toBe(true); } finally { await deleteKnownKeys(client, credentials.bucket, cleanupKeys); } diff --git a/e2e/storage/download.spec.ts b/e2e/storage/download.spec.ts index cbdb971f..66c9413c 100644 --- a/e2e/storage/download.spec.ts +++ b/e2e/storage/download.spec.ts @@ -50,7 +50,7 @@ test.describe('Storage S3 — Download', () => { expect(download.suggestedFilename()).toBe('download-me.txt'); expect(await download.failure()).toBeNull(); - expect(await readFile((await download.path())!, 'utf8')).toBe('download content'); + expect(await readFile(await download.path(), 'utf8')).toBe('download content'); } finally { await deleteKnownKeys(client, credentials.bucket, cleanupKeys); } @@ -135,7 +135,7 @@ test.describe('Storage S3 — Download', () => { ]); expect(download.suggestedFilename()).toMatch(/\.zip$/); expect(await download.failure()).toBeNull(); - const zip = new AdmZip(await readFile((await download.path())!)); + const zip = new AdmZip(await readFile(await download.path())); // Entries are named relative to the current folder; the content is the full key. const entryName = (key: string) => key.slice(prefix.length); expect( @@ -168,7 +168,7 @@ test.describe('Storage S3 — Download', () => { history.getByRole('button', { name: 'Download all', exact: true }).first().click() ]); expect(await redownload.failure()).toBeNull(); - const recreatedZip = new AdmZip(await readFile((await redownload.path())!)); + const recreatedZip = new AdmZip(await readFile(await redownload.path())); for (const key of cleanupKeys) expect(recreatedZip.readAsText(entryName(key))).toBe(key); } finally { await deleteKnownKeys(client, credentials.bucket, cleanupKeys); @@ -197,7 +197,7 @@ test.describe('Storage S3 — Download', () => { const [download] = await Promise.all([page.waitForEvent('download'), downloadBtn.click()]); expect(download.suggestedFilename()).toMatch(/\.zip$/); expect(await download.failure()).toBeNull(); - const zip = new AdmZip(await readFile((await download.path())!)); + const zip = new AdmZip(await readFile(await download.path())); // Entries are named relative to the current folder; the content is the full key. for (const key of cleanupKeys) expect(zip.readAsText(key.slice(prefix.length))).toBe(key); } finally { diff --git a/e2e/storage/permissions.spec.ts b/e2e/storage/permissions.spec.ts index bd98cae1..43f260d1 100644 --- a/e2e/storage/permissions.spec.ts +++ b/e2e/storage/permissions.spec.ts @@ -66,7 +66,7 @@ test.describe('Storage S3 — Permissions', () => { uploadModal.getByText('Access denied. You do not have permission to upload here.') ).toBeVisible(); await uploadModal.getByRole('button', { name: 'Done' }).click(); - await expect(await objectExists(adminClient, restrictedBucket, blockedKey)).toBe(false); + expect(await objectExists(adminClient, restrictedBucket, blockedKey)).toBe(false); await page.getByRole('button', { name: 'Toggle selection mode' }).click(); await page.getByLabel(`Select ${existingKey}`).check(); @@ -78,7 +78,7 @@ test.describe('Storage S3 — Permissions', () => { .filter({ hasText: 'Access denied. You do not have permission to delete this item.' }); await expect(errorToast).toBeVisible(); await expect(rowByName(page, existingKey)).toBeVisible(); - await expect(await getObjectText(adminClient, restrictedBucket, existingKey)).toBe('keep me'); + expect(await getObjectText(adminClient, restrictedBucket, existingKey)).toBe('keep me'); } finally { await deleteKnownKeys(adminClient, restrictedBucket, [existingKey, blockedKey]); } diff --git a/e2e/storage/upload.spec.ts b/e2e/storage/upload.spec.ts index df1a34e8..cd394b93 100644 --- a/e2e/storage/upload.spec.ts +++ b/e2e/storage/upload.spec.ts @@ -95,7 +95,7 @@ test.describe('Storage S3 — Upload', () => { await expect(uploadModal.getByText('2 uploaded · 0 skipped · 0 failed')).toBeVisible(); await uploadModal.getByRole('button', { name: 'Done' }).click(); await expect(rowByName(page, fixture.name)).toBeVisible(); - await expect(await getObjectText(client, credentials.bucket, key)).toBe(fixture.fullText); + expect(await getObjectText(client, credentials.bucket, key)).toBe(fixture.fullText); } finally { await transfer.dispose(); } @@ -137,20 +137,20 @@ test.describe('Storage S3 — Upload', () => { await expect(rowByName(page, csvFixture.name)).toBeVisible(); await expect(rowByName(page, imageFixture.name)).toBeVisible(); - await expect( + expect( await getObjectText(client, credentials.bucket, `${prefix}${textFixture.name}`) ).toContain(textFixture.expectedSnippet); - await expect( + expect( await getObjectText(client, credentials.bucket, `${prefix}${csvFixture.name}`) ).toContain(csvFixture.expectedCell); - await expect( + expect( (await headObject(client, credentials.bucket, `${prefix}${textFixture.name}`)).ContentType ).toBe('text/plain'); - await expect( + expect( (await headObject(client, credentials.bucket, `${prefix}${csvFixture.name}`)).ContentType ).toBe('text/csv'); - await expect( + expect( (await headObject(client, credentials.bucket, `${prefix}${imageFixture.name}`)).ContentType ).toBe('image/svg+xml'); @@ -254,19 +254,17 @@ test.describe('Storage S3 — Upload', () => { await expect(rowByName(page, 'fresh.txt')).toBeVisible(); await expect(rowByName(page, 'renamed.txt')).toBeVisible(); - await expect(await getObjectText(client, credentials.bucket, `${prefix}replace.txt`)).toBe( + expect(await getObjectText(client, credentials.bucket, `${prefix}replace.txt`)).toBe( 'new replace' ); - await expect(await getObjectText(client, credentials.bucket, `${prefix}skip.txt`)).toBe( - 'old skip' - ); - await expect(await getObjectText(client, credentials.bucket, `${prefix}taken.txt`)).toBe( + expect(await getObjectText(client, credentials.bucket, `${prefix}skip.txt`)).toBe('old skip'); + expect(await getObjectText(client, credentials.bucket, `${prefix}taken.txt`)).toBe( 'old taken' ); - await expect(await getObjectText(client, credentials.bucket, `${prefix}renamed.txt`)).toBe( + expect(await getObjectText(client, credentials.bucket, `${prefix}renamed.txt`)).toBe( 'new taken' ); - await expect(await getObjectText(client, credentials.bucket, `${prefix}fresh.txt`)).toBe( + expect(await getObjectText(client, credentials.bucket, `${prefix}fresh.txt`)).toBe( 'brand new' ); } finally { @@ -297,7 +295,7 @@ test.describe('Storage S3 — Upload', () => { await uploadModal.getByRole('button', { name: 'Upload', exact: true }).click(); await expect(uploadModal.getByRole('alert')).toContainText('Nothing was uploaded'); - await expect(await getObjectText(client, credentials.bucket, key)).toBe('old content'); + expect(await getObjectText(client, credentials.bucket, key)).toBe('old content'); // Once the check works again, the retry finds the conflict instead of overwriting. await page.unroute('**/api/storage/download?*', failHead); diff --git a/e2e/support/start-mock-trino.ts b/e2e/support/start-mock-trino.ts index c4dde65a..1047bcc6 100644 --- a/e2e/support/start-mock-trino.ts +++ b/e2e/support/start-mock-trino.ts @@ -363,7 +363,7 @@ http res.end('502 Bad Gateway from proxy.internal'); return; } - pollQuery(executing[1], Number(executing[2])).then((page) => sendJson(res, page)); + void pollQuery(executing[1], Number(executing[2])).then((page) => sendJson(res, page)); return; } if (req.method === 'GET' && url.pathname === '/v1/info') { @@ -377,8 +377,8 @@ http } let body = ''; - req.on('data', (c: Buffer) => (body += c)); - req.on('end', async () => { + req.on('data', (c: Buffer) => (body += c.toString())); + const respond = async () => { // Logged on arrival, so tests can act while a gated submit is still pending. const id = `q-mock-${++queryCounter}`; queries.set(id, { sql: body, pages: [] }); @@ -406,6 +406,7 @@ http // Unique id per submit so cancellations can be traced back to the statement. const match = routes.find(([key]) => body.includes(key)); sendJson(res, { ...(match ? match[1] : DEFAULT_RESPONSE), id }); - }); + }; + req.on('end', () => void respond()); }) .listen(MOCK_TRINO_PORT, 'localhost', () => console.log(`Mock Trino on :${MOCK_TRINO_PORT}`)); diff --git a/e2e/trino/connection-form.spec.ts b/e2e/trino/connection-form.spec.ts index d0598ff2..8fdc9ef8 100644 --- a/e2e/trino/connection-form.spec.ts +++ b/e2e/trino/connection-form.spec.ts @@ -18,8 +18,8 @@ import { MOCK_TRINO_URL } from '../support/mock-trino'; * The test server is env-configured, so the real action rejects every save. * This only exercises the client-side success path. */ -function interceptSaveSuccess(page: import('@playwright/test').Page) { - page.route( +async function interceptSaveSuccess(page: import('@playwright/test').Page) { + await page.route( (url) => url.pathname === '/trino' && url.search === '?/save', async (route, request) => { // Echo the client's form id back, otherwise superforms ignores the response. @@ -59,11 +59,11 @@ function interceptSaveSuccess(page: import('@playwright/test').Page) { * - __data.json uses devalue.stringify with indexed arrays where booleans * are stored at positions referenced by the shape object at index 0 */ -function interceptPageData( +async function interceptPageData( page: import('@playwright/test').Page, overrides: Record ) { - page.route('**/trino', async (route, request) => { + await page.route('**/trino', async (route, request) => { if (request.resourceType() !== 'document') return route.continue(); const response = await route.fetch(); let html = await response.text(); @@ -75,7 +75,7 @@ function interceptPageData( await route.fulfill({ response, body: html }); }); - page.route('**/trino/__data.json*', async (route) => { + await page.route('**/trino/__data.json*', async (route) => { const response = await route.fetch(); const json = await response.json(); for (const node of json.nodes ?? []) { @@ -91,17 +91,22 @@ function interceptPageData( }); } -/** Capture the fields posted by the next `?/save` request and abort it. */ -function captureSave(page: import('@playwright/test').Page): Promise { - return new Promise((resolve) => { - page.route( - (url) => url.pathname === '/trino' && url.search === '?/save', - async (route, request) => { - resolve(new URLSearchParams(request.postData() ?? '')); - await route.abort(); - } - ); - }); +/** + * Capture the fields posted by the next `?/save` request and abort it. + * Resolves once the route is registered; `posted` resolves with the captured fields. + */ +async function captureSave( + page: import('@playwright/test').Page +): Promise<{ posted: Promise }> { + const { promise, resolve } = Promise.withResolvers(); + await page.route( + (url) => url.pathname === '/trino' && url.search === '?/save', + async (route, request) => { + resolve(new URLSearchParams(request.postData() ?? '')); + await route.abort(); + } + ); + return { posted: promise }; } // --------------------------------------------------------------------------- @@ -115,7 +120,7 @@ test.describe('Connection form (insecure TLS allowed)', () => { localStorage.removeItem('trino_url'); localStorage.removeItem('trino_tls_insecure'); }); - interceptPageData(page, { trinoConfigured: false, allowInsecureTls: true }); + await interceptPageData(page, { trinoConfigured: false, allowInsecureTls: true }); }); test('skipping TLS verification is posted, persisted and shown in the summary', async ({ @@ -128,7 +133,7 @@ test.describe('Connection form (insecure TLS allowed)', () => { await page.getByLabel('Skip TLS certificate verification').check(); await expect(page.getByText('TLS unverified')).toBeVisible(); - const posted = captureSave(page); + const { posted } = await captureSave(page); await page.getByRole('button', { name: 'Save' }).click(); expect((await posted).get('tlsInsecure')).toBe('on'); @@ -166,7 +171,7 @@ test.describe('Connection form (manual mode)', () => { localStorage.removeItem('trino_password'); }); - interceptPageData(page, { trinoConfigured: false }); + await interceptPageData(page, { trinoConfigured: false }); }); test('connection form is visible', async ({ page }) => { @@ -353,7 +358,7 @@ test.describe('Connection form (manual mode)', () => { test('saving a connection clears previous query results', async ({ page }) => { await setTabSql(page, 'SELECT id, name FROM users'); - interceptSaveSuccess(page); + await interceptSaveSuccess(page); await page.goto('/trino'); await waitForHydration(page); diff --git a/e2e/tsconfig.json b/e2e/tsconfig.json new file mode 100644 index 00000000..0e316d9f --- /dev/null +++ b/e2e/tsconfig.json @@ -0,0 +1,7 @@ +{ + // Lets the typescript-eslint project service type-check the E2E tests, which the root + // tsconfig (based on the one SvelteKit generates) doesn't cover. + "extends": "../tsconfig.json", + "include": ["./**/*.ts"], + "exclude": [] +} diff --git a/eslint.config.js b/eslint.config.js index 880f4a38..c79c861e 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -17,7 +17,7 @@ export default defineConfig( includeIgnoreFile(gitignorePath), { ignores: ['src/lib/editor/generated/**'] }, js.configs.recommended, - ...ts.configs.recommended, + ...ts.configs.recommendedTypeChecked, ...svelte.configs.recommended, { ...security.configs.recommended, files: ['**/*.ts'] }, prettier, @@ -44,15 +44,37 @@ export default defineConfig( } }, { - files: ['**/*.svelte', '**/*.svelte.ts', '**/*.svelte.js'], languageOptions: { parserOptions: { - projectService: true, + projectService: { + // Root config files that no tsconfig includes. + allowDefaultProject: [ + 'drizzle.config.ts', + 'playwright.config.ts', + 'vitest.arch.config.ts' + ] + }, extraFileExtensions: ['.svelte'], parser: ts.parser } + }, + rules: { + // Untyped JSON, third-party data and test mocks make up nearly all of the ~1,000 hits; + // svelte-check with `strict` already covers the typed code. See #411. + '@typescript-eslint/no-unsafe-argument': 'off', + '@typescript-eslint/no-unsafe-assignment': 'off', + '@typescript-eslint/no-unsafe-call': 'off', + '@typescript-eslint/no-unsafe-member-access': 'off', + '@typescript-eslint/no-unsafe-return': 'off', + // Mostly async functions that implement an async interface without awaiting; style, not bugs. + '@typescript-eslint/require-await': 'off' } }, + { + // Plain JS files (root configs, server.js, CLI scripts) are outside every tsconfig. + files: ['**/*.js', '**/*.mjs'], + ...ts.configs.disableTypeChecked + }, { files: ['src/**/*.svelte'], plugins: { 'better-tailwindcss': betterTailwindcss }, @@ -101,6 +123,18 @@ export default defineConfig( files: ['**/*.{test,spec}.ts', 'e2e/**/*.ts', 'src/architecture-tests/**/*.ts'], rules: { 'security/detect-non-literal-fs-filename': 'off' } }, + { + files: ['**/*.{test,spec}.ts', '**/*.test-utils.ts'], + rules: { + // `expect(mock.method).toHaveBeenCalled()` passes methods around unbound by design. + '@typescript-eslint/unbound-method': 'off', + // Async `mockImplementation()`s for mocks typed with a void return. + '@typescript-eslint/no-misused-promises': [ + 'error', + { checksVoidReturn: { arguments: false } } + ] + } + }, { files: ['src/**/*.ts'], ignores: ['src/**/*.test.ts', 'src/**/*.spec.ts'], diff --git a/src/hooks.client.ts b/src/hooks.client.ts index 4de7dab2..dd77dede 100644 --- a/src/hooks.client.ts +++ b/src/hooks.client.ts @@ -8,7 +8,7 @@ import { checkSession } from '$lib/client/session.svelte'; * unchanged and `checkSession` decides whether the session is really gone. */ export const init: ClientInit = () => { - const originalFetch = window.fetch; + const originalFetch = window.fetch.bind(window); window.fetch = async (input, requestInit) => { const response = await originalFetch(input, requestInit); if (response.status === 401 && isSameOrigin(response.url)) { diff --git a/src/hooks.server.ts b/src/hooks.server.ts index 94fd58a9..5542455f 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -131,7 +131,7 @@ const handleStorageConnection: Handle = async ({ event, resolve }) => { event.route.id?.startsWith('/(app)/api/storage/')) && !storageBrowserEnabled ) { - throw error(404, 'Storage browser is not enabled'); + error(404, 'Storage browser is not enabled'); } const userId = event.locals.user?.id ?? null; if (userId && event.route.id?.startsWith('/(app)/api/storage/')) { diff --git a/src/lib/client/format-cell.spec.ts b/src/lib/client/format-cell.spec.ts new file mode 100644 index 00000000..8564f4a7 --- /dev/null +++ b/src/lib/client/format-cell.spec.ts @@ -0,0 +1,17 @@ +import { describe, expect, it } from 'vitest'; +import { formatCell } from './format-cell'; + +describe('formatCell', () => { + it.each([ + [null, ''], + [undefined, ''], + ['text', 'text'], + [42, '42'], + [false, 'false'], + [12n, '12'], + [{ a: 1 }, '{"a":1}'], + [Symbol('s'), ''] + ])('formats %o as %s', (value, expected) => { + expect(formatCell(value)).toBe(expected); + }); +}); diff --git a/src/lib/client/format-cell.ts b/src/lib/client/format-cell.ts new file mode 100644 index 00000000..38826cb3 --- /dev/null +++ b/src/lib/client/format-cell.ts @@ -0,0 +1,13 @@ +/** + * Formats a table cell from an untyped result row (Trino, CSV/Parquet preview) as text. + * Objects and arrays are shown as JSON instead of `[object Object]`. + */ +export function formatCell(value: unknown): string { + if (value === null || value === undefined) return ''; + if (typeof value === 'string') return value; + if (typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint') { + return value.toString(); + } + // JSON.stringify returns undefined for functions and symbols. + return JSON.stringify(value) ?? ''; +} diff --git a/src/lib/components/TooltipTrigger.svelte b/src/lib/components/TooltipTrigger.svelte index 5e20a797..689a5a06 100644 --- a/src/lib/components/TooltipTrigger.svelte +++ b/src/lib/components/TooltipTrigger.svelte @@ -74,7 +74,7 @@ while (el && el.tagName !== 'DIALOG') { el = el.parentElement; } - return (el ?? document.body) as HTMLElement; + return el ?? document.body; } $effect(() => { @@ -89,7 +89,7 @@ tooltipState = state; return () => { - unmount(state); + void unmount(state); portalHost?.remove(); portalHost = undefined; tooltipState = undefined; diff --git a/src/lib/components/TooltipTrigger.svelte.spec.ts b/src/lib/components/TooltipTrigger.svelte.spec.ts index 2f5e1b3b..5c469d84 100644 --- a/src/lib/components/TooltipTrigger.svelte.spec.ts +++ b/src/lib/components/TooltipTrigger.svelte.spec.ts @@ -23,23 +23,23 @@ describe('TooltipTrigger', () => { render(TooltipTriggerWrapper, { text: 'Delete' }); await page.getByRole('button', { name: 'Trigger' }).hover(); await expect.element(page.getByRole('tooltip')).toBeInTheDocument(); - await userEvent.unhover(await page.getByRole('button', { name: 'Trigger' }).element()); + await userEvent.unhover(page.getByRole('button', { name: 'Trigger' }).element()); await expect.element(page.getByRole('tooltip')).not.toBeInTheDocument(); }); it('shows the tooltip when the trigger receives focus', async () => { render(TooltipTriggerWrapper, { text: 'Delete' }); const button = page.getByRole('button', { name: 'Trigger' }); - (await button.element()).focus(); + button.element().focus(); await expect.element(page.getByRole('tooltip')).toBeInTheDocument(); }); it('hides the tooltip when the trigger loses focus', async () => { render(TooltipTriggerWrapper, { text: 'Delete' }); const button = page.getByRole('button', { name: 'Trigger' }); - (await button.element()).focus(); + button.element().focus(); await expect.element(page.getByRole('tooltip')).toBeInTheDocument(); - (await button.element()).blur(); + button.element().blur(); await expect.element(page.getByRole('tooltip')).not.toBeInTheDocument(); }); @@ -52,10 +52,8 @@ describe('TooltipTrigger', () => { it('renders the tooltip in a portal attached to , not inline in the trigger', async () => { render(TooltipTriggerWrapper, { text: 'Delete' }); await page.getByRole('button', { name: 'Trigger' }).hover(); - const tooltipEl = (await page.getByRole('tooltip').element()) as HTMLElement; - const triggerEl = (await page - .getByRole('button', { name: 'Trigger' }) - .element()) as HTMLElement; + const tooltipEl = page.getByRole('tooltip').element() as HTMLElement; + const triggerEl = page.getByRole('button', { name: 'Trigger' }).element() as HTMLElement; // The popup is portaled: it must not be a descendant of the trigger wrapper. expect(triggerEl.contains(tooltipEl)).toBe(false); // It is mounted into a host div that is a direct child of . @@ -67,7 +65,7 @@ describe('TooltipTrigger', () => { const dialogEl = document.querySelector('dialog'); expect(dialogEl).not.toBeNull(); await page.getByRole('button', { name: 'Trigger' }).hover(); - const tooltipEl = (await page.getByRole('tooltip').element()) as HTMLElement; + const tooltipEl = page.getByRole('tooltip').element() as HTMLElement; // The popup must be inside the dialog (top layer), not attached to . expect(dialogEl!.contains(tooltipEl)).toBe(true); }); diff --git a/src/lib/components/catalog/CatalogBrowser.svelte b/src/lib/components/catalog/CatalogBrowser.svelte index 6fab5a9c..ee4ee0ba 100644 --- a/src/lib/components/catalog/CatalogBrowser.svelte +++ b/src/lib/components/catalog/CatalogBrowser.svelte @@ -175,7 +175,7 @@ $effect(() => { // Read connectionVersion to subscribe to changes. if (connectionVersion > 0) { - loadCatalogs(); + void loadCatalogs(); } }); @@ -209,7 +209,7 @@ function handleRefresh() { expanded.clear(); - loadCatalogs(); + void loadCatalogs(); } function handleCatalogChange(event: Event) { diff --git a/src/lib/components/editor/MonacoEditor.svelte b/src/lib/components/editor/MonacoEditor.svelte index 7dae505c..f2ccfc1d 100644 --- a/src/lib/components/editor/MonacoEditor.svelte +++ b/src/lib/components/editor/MonacoEditor.svelte @@ -276,39 +276,39 @@ cleanups.push(() => document.removeEventListener('keydown', handleZoomKeys)); // Bind keyboard shortcuts to the built-in font zoom commands - const zoomDisposable = monaco!.editor.addKeybindingRules([ + const zoomDisposable = monaco.editor.addKeybindingRules([ { - keybinding: monaco!.KeyMod.CtrlCmd | monaco!.KeyCode.Equal, + keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.Equal, command: 'editor.action.fontZoomIn', when: 'editorFocus' }, { - keybinding: monaco!.KeyMod.CtrlCmd | monaco!.KeyMod.Shift | monaco!.KeyCode.Equal, + keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.Equal, command: 'editor.action.fontZoomIn', when: 'editorFocus' }, { - keybinding: monaco!.KeyMod.CtrlCmd | monaco!.KeyCode.NumpadAdd, + keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.NumpadAdd, command: 'editor.action.fontZoomIn', when: 'editorFocus' }, { - keybinding: monaco!.KeyMod.CtrlCmd | monaco!.KeyCode.Minus, + keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.Minus, command: 'editor.action.fontZoomOut', when: 'editorFocus' }, { - keybinding: monaco!.KeyMod.CtrlCmd | monaco!.KeyCode.NumpadSubtract, + keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.NumpadSubtract, command: 'editor.action.fontZoomOut', when: 'editorFocus' }, { - keybinding: monaco!.KeyMod.CtrlCmd | monaco!.KeyCode.Digit0, + keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.Digit0, command: 'editor.action.fontZoomReset', when: 'editorFocus' }, { - keybinding: monaco!.KeyMod.CtrlCmd | monaco!.KeyCode.Numpad0, + keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.Numpad0, command: 'editor.action.fontZoomReset', when: 'editorFocus' } diff --git a/src/lib/components/editor/TextEditor.svelte b/src/lib/components/editor/TextEditor.svelte index eee46d97..cc622386 100644 --- a/src/lib/components/editor/TextEditor.svelte +++ b/src/lib/components/editor/TextEditor.svelte @@ -240,39 +240,39 @@ cleanups.push(() => document.removeEventListener('keydown', handleZoomKeys)); // Bind keyboard shortcuts to the built-in font zoom commands - const zoomDisposable = monaco!.editor.addKeybindingRules([ + const zoomDisposable = monaco.editor.addKeybindingRules([ { - keybinding: monaco!.KeyMod.CtrlCmd | monaco!.KeyCode.Equal, + keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.Equal, command: 'editor.action.fontZoomIn', when: 'editorFocus' }, { - keybinding: monaco!.KeyMod.CtrlCmd | monaco!.KeyMod.Shift | monaco!.KeyCode.Equal, + keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyMod.Shift | monaco.KeyCode.Equal, command: 'editor.action.fontZoomIn', when: 'editorFocus' }, { - keybinding: monaco!.KeyMod.CtrlCmd | monaco!.KeyCode.NumpadAdd, + keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.NumpadAdd, command: 'editor.action.fontZoomIn', when: 'editorFocus' }, { - keybinding: monaco!.KeyMod.CtrlCmd | monaco!.KeyCode.Minus, + keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.Minus, command: 'editor.action.fontZoomOut', when: 'editorFocus' }, { - keybinding: monaco!.KeyMod.CtrlCmd | monaco!.KeyCode.NumpadSubtract, + keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.NumpadSubtract, command: 'editor.action.fontZoomOut', when: 'editorFocus' }, { - keybinding: monaco!.KeyMod.CtrlCmd | monaco!.KeyCode.Digit0, + keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.Digit0, command: 'editor.action.fontZoomReset', when: 'editorFocus' }, { - keybinding: monaco!.KeyMod.CtrlCmd | monaco!.KeyCode.Numpad0, + keybinding: monaco.KeyMod.CtrlCmd | monaco.KeyCode.Numpad0, command: 'editor.action.fontZoomReset', when: 'editorFocus' } diff --git a/src/lib/components/editor/TextEditor.svelte.spec.ts b/src/lib/components/editor/TextEditor.svelte.spec.ts index 5330781f..ef3afe2e 100644 --- a/src/lib/components/editor/TextEditor.svelte.spec.ts +++ b/src/lib/components/editor/TextEditor.svelte.spec.ts @@ -42,8 +42,8 @@ import TextEditor from './TextEditor.svelte'; describe('TextEditor', () => { const initialLocale = getLocale(); - afterEach(() => { - setLocale(initialLocale, { reload: false }); + afterEach(async () => { + await setLocale(initialLocale, { reload: false }); addAction.mockClear(); }); @@ -57,7 +57,7 @@ describe('TextEditor', () => { }); it('uses the active locale for the save action label', async () => { - setLocale('de', { reload: false }); + await setLocale('de', { reload: false }); render(TextEditor, { value: 'hallo', filename: 'a.txt', onSave: () => {} }); await vi.waitFor(() => expect(addAction).toHaveBeenCalled()); diff --git a/src/lib/components/layout/header/LanguageSwitcher.svelte b/src/lib/components/layout/header/LanguageSwitcher.svelte index 4288d1f1..642881bb 100644 --- a/src/lib/components/layout/header/LanguageSwitcher.svelte +++ b/src/lib/components/layout/header/LanguageSwitcher.svelte @@ -22,7 +22,7 @@ ); function handleLocaleChange(locale: (typeof locales)[number]) { - setLocale(locale); + void setLocale(locale); } diff --git a/src/lib/components/storage/StorageSearchForm.svelte b/src/lib/components/storage/StorageSearchForm.svelte index 28828b04..b3f03112 100644 --- a/src/lib/components/storage/StorageSearchForm.svelte +++ b/src/lib/components/storage/StorageSearchForm.svelte @@ -51,7 +51,7 @@ const nextIndex = queryCycleIndex + direction; if (nextIndex < 0 || nextIndex >= queryCycleTerms.length) return; queryCycleIndex = nextIndex; - update({ query: queryCycleTerms[queryCycleIndex]! }); + update({ query: queryCycleTerms[queryCycleIndex] }); } const hasInvalidFilter = $derived( diff --git a/src/lib/components/storage/__tests__/StorageSearch.svelte.spec.ts b/src/lib/components/storage/__tests__/StorageSearch.svelte.spec.ts index 50880a49..ff80537c 100644 --- a/src/lib/components/storage/__tests__/StorageSearch.svelte.spec.ts +++ b/src/lib/components/storage/__tests__/StorageSearch.svelte.spec.ts @@ -329,7 +329,7 @@ describe('StorageSearch', () => { render(StorageSearchWrapper, { state }); await page.getByRole('button', { name: 'Open search' }).click(); await page.getByRole('tab', { name: 'Recent' }).click(); - const entries = await page.getByRole('button', { name: /md/ }).elements(); + const entries = page.getByRole('button', { name: /md/ }).elements(); expect(entries).toHaveLength(2); }); diff --git a/src/lib/components/storage/explorer/FileExplorer.svelte b/src/lib/components/storage/explorer/FileExplorer.svelte index fdd17a84..588388c7 100644 --- a/src/lib/components/storage/explorer/FileExplorer.svelte +++ b/src/lib/components/storage/explorer/FileExplorer.svelte @@ -118,16 +118,18 @@ } } + const onDrop = (e: DragEvent) => void handleDrop(e); + el.addEventListener('dragenter', handleDragEnter, true); el.addEventListener('dragover', handleDragOver, true); el.addEventListener('dragleave', handleDragLeave, true); - el.addEventListener('drop', handleDrop, true); + el.addEventListener('drop', onDrop, true); window.addEventListener('dragend', resetDrag); return () => { el.removeEventListener('dragenter', handleDragEnter, true); el.removeEventListener('dragover', handleDragOver, true); el.removeEventListener('dragleave', handleDragLeave, true); - el.removeEventListener('drop', handleDrop, true); + el.removeEventListener('drop', onDrop, true); window.removeEventListener('dragend', resetDrag); }; }); @@ -205,21 +207,21 @@ if (!hasCtxKey) { return [ { - key: 'create-file' as ActionName, + key: 'create-file', icon: IconDescriptionOutline, label: m.storage_create_file(), disabled: false, hidden: storage.archive.isInArchive }, { - key: 'create-folder' as ActionName, + key: 'create-folder', icon: IconFolderOutline, label: m.storage_create_folder(), disabled: false, hidden: storage.archive.isInArchive }, { - key: 'paste' as ActionName, + key: 'paste', icon: IconPaste, label: m.storage_action_paste(), disabled: !storage.clipboardState.canPaste || storage.archive.isInArchive, @@ -230,56 +232,56 @@ const items: ContextMenuAction[] = [ { - key: 'preview' as ActionName, + key: 'preview', icon: IconVisibility, label: m.storage_action_preview(), disabled: !canPreview, hidden: false }, { - key: 'download' as ActionName, + key: 'download', icon: IconDownload, label: m.storage_action_download(), disabled: !canDownload, hidden: false }, { - key: 'details' as ActionName, + key: 'details', icon: IconInfo, label: m.storage_action_details(), disabled: !canShowDetails, hidden: false }, { - key: 'cut' as ActionName, + key: 'cut', icon: IconCut, label: m.storage_action_cut(), disabled: selectionCount === 0 || storage.archive.isInArchive, hidden: !storageTransferEnabled || storage.archive.isInArchive }, { - key: 'copy' as ActionName, + key: 'copy', icon: IconCopy, label: m.storage_action_copy(), disabled: selectionCount === 0 || storage.archive.isInArchive, hidden: !storageTransferEnabled || storage.archive.isInArchive }, { - key: 'paste' as ActionName, + key: 'paste', icon: IconPaste, label: m.storage_action_paste(), disabled: !storage.clipboardState.canPaste || storage.archive.isInArchive, hidden: !storageTransferEnabled || storage.archive.isInArchive }, { - key: 'rename' as ActionName, + key: 'rename', icon: IconDriveFileRenameOutline, label: m.storage_action_rename(), disabled: selectionCount !== 1 || storage.archive.isInArchive, hidden: !storageTransferEnabled || storage.archive.isInArchive }, { - key: 'copy-filename' as ActionName, + key: 'copy-filename', icon: IconFileCopy, label: hasCtxKey && !storage.ctxIsFile @@ -289,21 +291,21 @@ hidden: false }, { - key: 'copy-path' as ActionName, + key: 'copy-path', icon: IconContentCopy, label: m.storage_action_copy_path(), disabled: !hasCtxKey, hidden: false }, { - key: 'pin' as ActionName, + key: 'pin', icon: IconPushPinOutline, label: m.storage_action_pin(), disabled: !storage.canPin || storage.archive.isInArchive, hidden: !storage.canPin || storage.ctxIsPinned || storage.archive.isInArchive }, { - key: 'unpin' as ActionName, + key: 'unpin', icon: IconPushPin, label: m.storage_action_unpin(), disabled: !storage.ctxIsPinned || storage.archive.isInArchive, @@ -313,7 +315,7 @@ if (!storage.archive.isInArchive && hasCtxKey) { items.push({ - key: 'delete' as ActionName, + key: 'delete', icon: IconDelete, label: m.storage_action_delete(), disabled: selectionCount === 0, @@ -325,7 +327,7 @@ }); function handleContextMenuAction(key: string) { - storage.executeAction(key as ActionName); + void storage.executeAction(key as ActionName); storage.contextMenu = null; } diff --git a/src/lib/components/storage/explorer/FileRow.svelte b/src/lib/components/storage/explorer/FileRow.svelte index df83b07f..97f33eb5 100644 --- a/src/lib/components/storage/explorer/FileRow.svelte +++ b/src/lib/components/storage/explorer/FileRow.svelte @@ -43,7 +43,7 @@ if (isArchive) { void storage.archive.enterArchive(file.key); } else { - storage.executeAction('preview'); + void storage.executeAction('preview'); } }} oncontextmenu={(e) => storage.openContextMenu(e, file.key)} diff --git a/src/lib/components/storage/explorer/FolderRow.svelte b/src/lib/components/storage/explorer/FolderRow.svelte index 9094c120..c84592e3 100644 --- a/src/lib/components/storage/explorer/FolderRow.svelte +++ b/src/lib/components/storage/explorer/FolderRow.svelte @@ -32,7 +32,7 @@ function open() { if (storage.archive.isInArchive) { - storage.archive.navigateInArchive(folder.key); + void storage.archive.navigateInArchive(folder.key); } else { storage.navigate(folder.key); } diff --git a/src/lib/components/storage/explorer/ObjectTable.svelte b/src/lib/components/storage/explorer/ObjectTable.svelte index f61d1fc2..3f5e86a2 100644 --- a/src/lib/components/storage/explorer/ObjectTable.svelte +++ b/src/lib/components/storage/explorer/ObjectTable.svelte @@ -98,7 +98,7 @@ if (!container) return; const edgeY = contentEdgeY(e.clientY); if (edgeY === null) return; - const el = container as HTMLElement; + const el = container; if (edgeY < EDGE_THICKNESS && el.scrollTop > 0) { const factor = 1 - edgeY / EDGE_THICKNESS; const speed = BASE_SCROLL_SPEED + (MAX_SCROLL_SPEED - BASE_SCROLL_SPEED) * factor; diff --git a/src/lib/components/storage/explorer/StorageBreadcrumb.svelte b/src/lib/components/storage/explorer/StorageBreadcrumb.svelte index dc42ba69..fab11c26 100644 --- a/src/lib/components/storage/explorer/StorageBreadcrumb.svelte +++ b/src/lib/components/storage/explorer/StorageBreadcrumb.svelte @@ -175,9 +175,9 @@ const ctx = breadcrumbCtx; if (!ctx) return; if (key === 'copy-filename') { - storage.copyFilename(ctx.prefix); + void storage.copyFilename(ctx.prefix); } else if (key === 'copy-path') { - storage.copyPath(ctx.bucket, ctx.prefix); + void storage.copyPath(ctx.bucket, ctx.prefix); } else if (key === 'pin-toggle') { if (storage.bookmarks.isPinned(ctx.bucket, ctx.prefix)) { storage.bookmarks.unpin(ctx.bucket, ctx.prefix); @@ -468,7 +468,7 @@ if (storage.archive.nestedArchivePath) { storage.archive.navigateToOuterArchiveRoot(); } else { - storage.archive.navigateInArchive(''); + void storage.archive.navigateInArchive(''); } }} > @@ -632,7 +632,7 @@ ? uid + '-create-name-error' : undefined} onkeydown={(e) => { - if (e.key === 'Enter') handleCreate(); + if (e.key === 'Enter') void handleCreate(); if (e.key === 'Escape') closeCreate(); }} /> diff --git a/src/lib/components/storage/explorer/TabBar.svelte b/src/lib/components/storage/explorer/TabBar.svelte index 262352e3..700f1e85 100644 --- a/src/lib/components/storage/explorer/TabBar.svelte +++ b/src/lib/components/storage/explorer/TabBar.svelte @@ -122,10 +122,10 @@ tabsState.closeTab(tabId); } else if (key === 'copy-filename') { const tab = tabsState.tabs.find((t) => t.id === tabId); - if (tab) storage.copyFilename(tab.snapshot.prefix); + if (tab) void storage.copyFilename(tab.snapshot.prefix); } else if (key === 'copy-path') { const tab = tabsState.tabs.find((t) => t.id === tabId); - if (tab) storage.copyPath(tab.snapshot.bucket, tab.snapshot.prefix); + if (tab) void storage.copyPath(tab.snapshot.bucket, tab.snapshot.prefix); } } diff --git a/src/lib/components/storage/explorer/__tests__/StorageBreadcrumb.svelte.spec.ts b/src/lib/components/storage/explorer/__tests__/StorageBreadcrumb.svelte.spec.ts index 50111caa..83c115e8 100644 --- a/src/lib/components/storage/explorer/__tests__/StorageBreadcrumb.svelte.spec.ts +++ b/src/lib/components/storage/explorer/__tests__/StorageBreadcrumb.svelte.spec.ts @@ -248,7 +248,7 @@ describe('StorageBreadcrumb', () => { render(StorageBreadcrumbWrapper, { state }); const pinButton = page.getByRole('button', { name: 'Pin' }).last(); - ((await pinButton.element()) as HTMLElement).click(); + (pinButton.element() as HTMLElement).click(); expect(spy).toHaveBeenCalledWith('test-bucket', 'data/'); }); @@ -262,7 +262,7 @@ describe('StorageBreadcrumb', () => { render(StorageBreadcrumbWrapper, { state }); const unpinButton = page.getByRole('button', { name: 'Unpin' }); - ((await unpinButton.element()) as HTMLElement).click(); + (unpinButton.element() as HTMLElement).click(); expect(spy).toHaveBeenCalledWith('test-bucket', 'data/'); }); }); @@ -398,7 +398,7 @@ describe('StorageBreadcrumb', () => { // The backdrop is a fixed inset-0 div that's a sibling before the context menu // Dispatch mousedown on it to trigger closeBreadcrumbCtx - const menuEl = (await ctxMenuItems.first().element()) as HTMLElement; + const menuEl = ctxMenuItems.first().element() as HTMLElement; const menuUl = menuEl.closest('ul[role="menu"]')!; const backdrop = menuUl.previousElementSibling as HTMLElement; backdrop.dispatchEvent(new MouseEvent('mousedown', { bubbles: true })); diff --git a/src/lib/components/storage/landing/StorageConnectForm.svelte.spec.ts b/src/lib/components/storage/landing/StorageConnectForm.svelte.spec.ts index 4b998b9c..f1ee2c65 100644 --- a/src/lib/components/storage/landing/StorageConnectForm.svelte.spec.ts +++ b/src/lib/components/storage/landing/StorageConnectForm.svelte.spec.ts @@ -89,9 +89,8 @@ function createMockForm(overrides: Record = {}): ConnectionForm constraints: {}, shape: {}, message: undefined, - tainted: undefined, ...restOverrides - } as unknown as ConnectionFormProp; + }; } function makeConnection(overrides: Partial = {}): ConnectionMetadata { diff --git a/src/lib/components/storage/modals/DeleteConnectionModal.svelte b/src/lib/components/storage/modals/DeleteConnectionModal.svelte index f47766e3..3b5fdd1f 100644 --- a/src/lib/components/storage/modals/DeleteConnectionModal.svelte +++ b/src/lib/components/storage/modals/DeleteConnectionModal.svelte @@ -22,11 +22,16 @@ } function copyField(value: string, field: string) { - navigator.clipboard.writeText(value); - copiedField = field; - setTimeout(() => { - copiedField = null; - }, 1500); + navigator.clipboard.writeText(value).then( + () => { + copiedField = field; + setTimeout(() => { + copiedField = null; + }, 1500); + }, + // Without clipboard access, just don't show the checkmark. + () => {} + ); } function copyAll(conn: SavedConnection) { @@ -36,11 +41,7 @@ ...(conn.credentials?.accessKey ? [`Access key: ${conn.credentials.accessKey}`] : []), `Region: ${conn.region.name}` ]; - navigator.clipboard.writeText(lines.join('\n')); - copiedField = 'all'; - setTimeout(() => { - copiedField = null; - }, 1500); + copyField(lines.join('\n'), 'all'); } diff --git a/src/lib/components/storage/modals/details/BucketDetails.svelte b/src/lib/components/storage/modals/details/BucketDetails.svelte index fed13b19..fc2debad 100644 --- a/src/lib/components/storage/modals/details/BucketDetails.svelte +++ b/src/lib/components/storage/modals/details/BucketDetails.svelte @@ -163,15 +163,15 @@
{m.storage_details_lifecycle_filter()}: - {#if rule.filter && typeof rule.filter === 'object' && 'prefix' in (rule.filter as Record) && (rule.filter as Record).prefix} + {#if typeof rule.filter.prefix === 'string' && rule.filter.prefix} {m.storage_details_lifecycle_prefix_filter({ - prefix: String((rule.filter as Record).prefix) + prefix: rule.filter.prefix })} - {:else if rule.filter && typeof rule.filter === 'object' && 'and' in (rule.filter as Record)} + {:else if rule.filter && typeof rule.filter === 'object' && 'and' in rule.filter} - AND ({(rule.filter as Record).and as string}) + AND ({rule.filter.and as string}) {:else if rule.filter && typeof rule.filter === 'object' && Object.keys(rule.filter).length > 0} diff --git a/src/lib/components/storage/modals/details/Treemap.svelte b/src/lib/components/storage/modals/details/Treemap.svelte index 33a1c3ba..c53bc85f 100644 --- a/src/lib/components/storage/modals/details/Treemap.svelte +++ b/src/lib/components/storage/modals/details/Treemap.svelte @@ -89,8 +89,8 @@ const isContainer = !!(children && children.length > 0); // Collapse single-child containers to avoid padding exhaustion from deep nesting - if (isContainer && children!.length === 1) { - layoutNode(children![0], x, y, w, h, depth + 1, rects); + if (isContainer && children.length === 1) { + layoutNode(children[0], x, y, w, h, depth + 1, rects); return; } @@ -126,7 +126,7 @@ let remH = innerH; let horizontal = remW >= remH; - for (const child of children!) { + for (const child of children) { const area = (child.size / total) * innerW * innerH; let cw: number; let ch: number; @@ -302,7 +302,7 @@ class="btn btn-ghost btn-sm w-full justify-start gap-2" onclick={() => { const t = ctxMenu!.target; - copy(t.name); + void copy(t.name); }} >