Skip to content

Commit fbd8255

Browse files
authored
REview and adjust lint rules (#412)
* chore(lint): lint e2e/support and migrate.ts Both were excluded from ESLint. Drop the ignores, remove the now redundant detect-object-injection disables in garage.ts and log migration errors via the pino logger instead of console. Refs #344 * chore(lint): enable no-console outside CLI and E2E helper scripts Only server code had no-console enabled. Enable it everywhere and keep it off for the E2E helper processes and the ANTLR patch script, which run without the app's logger. Refs #344 * chore(lint): drop fs-filename check for tests, document production disables Tests only touch fixtures and temp files they create, so turn security/detect-non-literal-fs-filename off for unit, E2E and architecture tests instead of disabling it line by line. Give each remaining disable in production code a reason. Refs #344 * chore(lint): make no-navigation-without-resolve an error Replace the file-level overrides with disables that state why the path is already resolved. The existing disable-next-line comments in Sidebar and RecentItems sat above the element instead of the href line and had no effect. Drop the second resolve() on already resolved paths in the storage layout and the connection edit page. Refs #344 * chore(lint): fail on lint and svelte-check warnings Warnings never failed lint, so they piled up unnoticed. Resolve the remaining ones (false-positive regex findings, table-pin-rows), then run eslint with --max-warnings=0, svelte-check with --fail-on-warnings and report unused eslint-disable directives as errors. Refs #344 * fix(storage): stop resolving recent-item links twice fileHref() and locationHref() already return resolved paths. Passing them through resolve() again dropped path segments shaped like a route group, so a recent folder such as logs/(2024)/ linked to logs/. Use the helpers directly, and reuse storageHref() in the storage layout instead of a local copy. Also report unused eslint-disable comments in Svelte templates via svelte/comment-directive and remove the ones that were not needed. Refs #344
1 parent 43a33f0 commit fbd8255

21 files changed

Lines changed: 89 additions & 104 deletions

File tree

‎e2e/i18n.spec.ts‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ const DE_DASHBOARD_HEADING = 'Stackable Unified Data Platform – Übersicht';
77

88
/** Load the saved auth storage state, optionally stripping the locale cookie. */
99
function loadAuthState(authFile: string, { withoutLocale = false } = {}) {
10-
// eslint-disable-next-line security/detect-non-literal-fs-filename
1110
const state = JSON.parse(fs.readFileSync(authFile, 'utf-8'));
1211
if (withoutLocale) {
1312
state.cookies = state.cookies.filter((c: { name: string }) => c.name !== 'PARAGLIDE_LOCALE');

‎e2e/storage/recent-items.spec.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
requireGarageCredentials
66
} from '../support/garage.js';
77
import {
8+
bucketRoute,
89
connectAndOpenPrefix,
910
deleteKnownKeys,
1011
putTextObject,
@@ -68,6 +69,42 @@ test.describe('Storage S3 — Recent Items', () => {
6869
}
6970
});
7071

72+
test('links to folders with parenthesised names keep the full path', async ({
73+
page
74+
}, testInfo) => {
75+
const credentials = requireGarageCredentials();
76+
const client = createS3Client(credentials);
77+
const folder = `${uniquePrefix(testInfo, 'recent-parens')}(2024)/`;
78+
const key = `${folder}report.txt`;
79+
const folderRoute = bucketRoute(
80+
new URL(credentials.endpoint).hostname,
81+
credentials.bucket,
82+
folder
83+
);
84+
85+
try {
86+
await putTextObject(client, credentials.bucket, key, 'parenthesised folder');
87+
88+
await connectAndOpenPrefix(page, credentials, folder);
89+
await previewFile(page, 'report.txt');
90+
91+
await page.goto('/storage');
92+
await waitForStorageConnected(page);
93+
await expect(page.getByRole('link', { name: 'Open folder — report.txt' })).toHaveAttribute(
94+
'href',
95+
folderRoute
96+
);
97+
98+
await page.getByRole('tab', { name: 'Recent Locations' }).click();
99+
await expect(page.getByRole('link', { name: 'Go to location — (2024)' })).toHaveAttribute(
100+
'href',
101+
folderRoute
102+
);
103+
} finally {
104+
await deleteKnownKeys(client, credentials.bucket, [key]);
105+
}
106+
});
107+
71108
test('removes a deleted file from Recent Files', async ({ page }, testInfo) => {
72109
test.slow(); // multiple navigations + deletion; Firefox is slow in CI
73110
const credentials = requireGarageCredentials();

‎e2e/support/garage.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ function readString(value: unknown, keys: string[]): string | null {
3737
}
3838

3939
for (const key of keys) {
40-
// eslint-disable-next-line security/detect-object-injection
4140
const candidate = record[key];
4241
if (typeof candidate === 'string' && candidate.length > 0) {
4342
return candidate;
@@ -54,7 +53,6 @@ function readStringArray(value: unknown, keys: string[]): string[] {
5453
}
5554

5655
for (const key of keys) {
57-
// eslint-disable-next-line security/detect-object-injection
5856
const candidate = record[key];
5957
if (Array.isArray(candidate)) {
6058
return candidate.filter((item): item is string => typeof item === 'string');
@@ -75,7 +73,6 @@ function extractAdminList(value: unknown): JsonRecord[] {
7573
}
7674

7775
for (const key of ADMIN_LIST_KEYS) {
78-
// eslint-disable-next-line security/detect-object-injection
7976
const candidate = record[key];
8077
if (Array.isArray(candidate)) {
8178
return candidate

‎eslint.config.js‎

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,28 +15,31 @@ const gitignorePath = fileURLToPath(new URL('./.gitignore', import.meta.url));
1515

1616
export default defineConfig(
1717
includeIgnoreFile(gitignorePath),
18-
{ ignores: ['src/lib/editor/generated/**', 'src/lib/server/migrate.ts', 'e2e/support/**'] },
18+
{ ignores: ['src/lib/editor/generated/**'] },
1919
js.configs.recommended,
2020
...ts.configs.recommended,
2121
...svelte.configs.recommended,
2222
{ ...security.configs.recommended, files: ['**/*.ts'] },
2323
prettier,
2424
...svelte.configs.prettier,
2525
{
26+
linterOptions: { reportUnusedDisableDirectives: 'error' },
2627
languageOptions: {
2728
globals: { ...globals.browser, ...globals.node }
2829
},
2930
rules: {
3031
'no-undef': 'off',
31-
'no-console': 'off',
32+
// linterOptions.reportUnusedDisableDirectives does not cover comments in Svelte templates.
33+
'svelte/comment-directive': ['error', { reportUnusedDisableDirectives: true }],
34+
'no-console': 'error',
3235
// It will currently also error on external links or links with query parameters.
3336
// https://github.com/sveltejs/eslint-plugin-svelte/issues/1353
34-
'svelte/no-navigation-without-resolve': 'warn',
37+
'svelte/no-navigation-without-resolve': 'error',
3538
'svelte/no-restricted-html-elements': [
3639
'error',
3740
{ elements: ['dialog'], message: 'Use the shared Modal component instead of <dialog>.' }
3841
],
39-
// Too common occurrence in this project, disabling for now.
42+
// Flags every computed member access; nearly all hits are array indices or typed Record lookups.
4043
'security/detect-object-injection': 'off'
4144
}
4245
},
@@ -73,7 +76,8 @@ export default defineConfig(
7376
'tab-active',
7477
'tab-strip',
7578
'preview-scroll',
76-
'modal-top-search'
79+
'modal-top-search',
80+
'table-pin-rows'
7781
]
7882
}
7983
],
@@ -88,8 +92,14 @@ export default defineConfig(
8892
}
8993
},
9094
{
91-
files: ['src/lib/server/**/*.ts', 'src/routes/**/*.server.ts'],
92-
rules: { 'no-console': 'error' }
95+
// CLI scripts and E2E helper processes that run without the app's logger.
96+
files: ['e2e/support/**/*.ts', 'src/lib/editor/grammar/patch-generated.mjs'],
97+
rules: { 'no-console': 'off' }
98+
},
99+
{
100+
// Tests read and write fixtures and temp files they create themselves.
101+
files: ['**/*.{test,spec}.ts', 'e2e/**/*.ts', 'src/architecture-tests/**/*.ts'],
102+
rules: { 'security/detect-non-literal-fs-filename': 'off' }
93103
},
94104
{
95105
files: ['src/**/*.ts'],
@@ -131,15 +141,6 @@ export default defineConfig(
131141
files: ['src/lib/components/Modal.svelte'],
132142
rules: { 'svelte/no-restricted-html-elements': 'off' }
133143
},
134-
{
135-
files: [
136-
'src/lib/components/layout/sidebar/Sidebar.svelte',
137-
'src/lib/components/storage/landing/RecentItems.svelte',
138-
'src/routes/**/edit/+page.svelte',
139-
'src/routes/(app)/storage/+layout.svelte'
140-
],
141-
rules: { 'svelte/no-navigation-without-resolve': 'off' }
142-
},
143144
{
144145
files: [
145146
'src/lib/client/**/*.ts',

‎package.json‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"build": "vite build",
1010
"preview": "vite preview --host",
1111
"prepare": "svelte-kit sync || echo '' && npm run generate:antlr",
12-
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json",
12+
"check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --fail-on-warnings",
1313
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
1414
"format": "prettier --write --ignore-path .prettierignore .",
15-
"lint": "prettier --check --ignore-path .prettierignore . && eslint . && npm run check && npm run knip && npm run test:arch",
16-
"lint:fix": "prettier --write --ignore-path .prettierignore . && eslint . --fix && npm run check && npm run knip && npm run test:arch",
15+
"lint": "prettier --check --ignore-path .prettierignore . && eslint . --max-warnings=0 && npm run check && npm run knip && npm run test:arch",
16+
"lint:fix": "prettier --write --ignore-path .prettierignore . && eslint . --fix --max-warnings=0 && npm run check && npm run knip && npm run test:arch",
1717
"knip": "knip",
1818
"knip:fix": "knip --fix",
1919
"test:unit": "vitest run",

‎src/architecture-tests/helpers.ts‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,6 @@ export const defaultOptions = {
1313
logging: { enabled: false, level: 'warn' as const }
1414
};
1515

16-
// These tests deliberately inspect a discovered source tree rather than
17-
// application-controlled input paths.
18-
/* eslint-disable security/detect-non-literal-fs-filename */
1916
export function readTextFile(file: string): string {
2017
return readFileSync(file, 'utf-8');
2118
}

‎src/lib/components/layout/sidebar/Sidebar.svelte‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,9 @@
119119
{#snippet navItem(item: NavItem)}
120120
{@const active = isActive((resolve as (pathname: string) => string)(item.route))}
121121
<li>
122-
<!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- Nav item paths are dynamically generated. -->
123122
<TooltipTrigger text={collapsed ? item.label : undefined} orientation="right">
123+
<!-- The path is resolved; the rule does not recognise the cast needed for dynamic nav routes. -->
124+
<!-- eslint-disable svelte/no-navigation-without-resolve -->
124125
<a
125126
href={(resolve as (pathname: string) => string)(item.route)}
126127
data-sveltekit-preload-data="hover"
@@ -136,6 +137,7 @@
136137
aria-current={active ? 'page' : undefined}
137138
aria-disabled={item.disabled ? 'true' : undefined}
138139
>
140+
<!-- eslint-enable svelte/no-navigation-without-resolve -->
139141
{@render navIcon(item.icon)}
140142
{#if !collapsed}
141143
<span class="truncate">{item.label}</span>

‎src/lib/components/storage/landing/RecentItems.svelte‎

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script lang="ts">
2-
import { resolve } from '$app/paths';
32
import type { Snippet } from 'svelte';
43
import IconArrowForward from 'virtual:icons/material-symbols/arrow-forward';
54
import IconDescriptionOutline from 'virtual:icons/material-symbols/description-outline';
@@ -127,11 +126,8 @@
127126
</div>
128127
</td>
129128
<td>
130-
<!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- Storage paths are dynamically generated. -->
131129
<a
132-
href={(resolve as (pathname: string) => string)(
133-
fileHref(storage.connectionHostname, file)
134-
)}
130+
href={fileHref(storage.connectionHostname, file)}
135131
data-sveltekit-preload-data="off"
136132
class="text-muted hover:text-primary truncate text-xs"
137133
>
@@ -156,11 +152,8 @@
156152
</button>
157153
</div>
158154
<div class="tooltip tooltip-left" data-tip={m.storage_recent_open_folder()}>
159-
<!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- Storage paths are dynamically generated. -->
160155
<a
161-
href={(resolve as (pathname: string) => string)(
162-
fileHref(storage.connectionHostname, file)
163-
)}
156+
href={fileHref(storage.connectionHostname, file)}
164157
data-sveltekit-preload-data="off"
165158
class="btn btn-ghost btn-xs"
166159
aria-label="{m.storage_recent_open_folder()} — {keyToName(file.key)}"
@@ -196,22 +189,16 @@
196189
{:else}
197190
<IconFolderOutline class="text-warning size-4 shrink-0" aria-hidden="true" />
198191
{/if}
199-
<!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- Storage paths are dynamically generated. -->
200192
<a
201-
href={(resolve as (pathname: string) => string)(
202-
locationHref(storage.connectionHostname, loc)
203-
)}
193+
href={locationHref(storage.connectionHostname, loc)}
204194
data-sveltekit-preload-data="off"
205195
class="hover:text-primary font-medium">{locationLabel(loc)}</a
206196
>
207197
</div>
208198
</td>
209199
<td>
210-
<!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- Storage paths are dynamically generated. -->
211200
<a
212-
href={(resolve as (pathname: string) => string)(
213-
locationHref(storage.connectionHostname, loc)
214-
)}
201+
href={locationHref(storage.connectionHostname, loc)}
215202
data-sveltekit-preload-data="off"
216203
class="text-muted hover:text-primary truncate text-xs"
217204
>
@@ -223,11 +210,8 @@
223210
</td>
224211
<td>
225212
<div class="tooltip tooltip-left" data-tip={m.storage_recent_go_to_location()}>
226-
<!-- eslint-disable-next-line svelte/no-navigation-without-resolve -- Storage paths are dynamically generated. -->
227213
<a
228-
href={(resolve as (pathname: string) => string)(
229-
locationHref(storage.connectionHostname, loc)
230-
)}
214+
href={locationHref(storage.connectionHostname, loc)}
231215
data-sveltekit-preload-data="off"
232216
class="btn btn-ghost btn-xs"
233217
aria-label="{m.storage_recent_go_to_location()} — {locationLabel(loc)}"

‎src/lib/components/storage/sidebar/BucketList.svelte‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@
200200
{#each storage.bookmarks.pinnedLocations as pin (pin.bucket + '::' + pin.prefix)}
201201
{@const active = isPinnedActive(pin)}
202202
<li class="group relative">
203-
<!-- eslint-disable svelte/no-navigation-without-resolve -->
204203
<TooltipTrigger text={locationLabel(pin)} orientation="right">
205204
<a
206205
href={locationHref(storage.connectionHostname, pin)}
@@ -215,7 +214,6 @@
215214
ondragleave={handleSidebarDragLeave}
216215
ondrop={(e) => handleSidebarDrop(e, pin.bucket, pin.prefix)}
217216
>
218-
<!-- eslint-enable svelte/no-navigation-without-resolve -->
219217
{#if pin.prefix === ''}
220218
<IconBucket class="size-3.5 shrink-0 opacity-60" aria-hidden="true" />
221219
{:else}

‎src/lib/components/trino/StatementResult.svelte‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,14 +158,12 @@
158158
{#if result.trinoQueryUrl || result.columns.length > 0}
159159
<div class="flex items-center gap-2 pb-1">
160160
{#if result.trinoQueryUrl}
161-
<!-- eslint-disable svelte/no-navigation-without-resolve -->
162161
<a
163162
href={result.trinoQueryUrl}
164163
target="_blank"
165164
rel="noopener noreferrer external"
166165
class="btn btn-ghost btn-xs"
167166
>
168-
<!-- eslint-enable svelte/no-navigation-without-resolve -->
169167
{m.trino_view_in_trino()}
170168
<IconOpenInNew class="size-3.5" aria-hidden="true" />
171169
</a>

0 commit comments

Comments
 (0)