Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions docs/HARNESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ ideally one rule per PR so the diff is reviewable:

| Rule | Why warn today | Promote when |
|---|---|---|
| `svelte/require-each-key` | ~10 unkeyed `{#each}` blocks | Each route owns its fix |
| `svelte/no-navigation-without-resolve` | ~10 `<a href>` / `goto()` without `resolve()` | Svelte 5 routing migration |
| `svelte/prefer-svelte-reactivity` | `new Set()` instead of `SvelteSet` in 2 files | Replace inline |
| `no-useless-escape` | bash-template strings escape `\$` for shell interpolation | False-positive review — likely stay warn |

## What's intentionally NOT in the harness
Expand Down
17 changes: 9 additions & 8 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,12 @@ export default [
'no-useless-assignment': 'error',
'svelte/no-useless-mustaches': ['error', { ignoreStringEscape: true }],

// Style/best-practice rules that flag real-but-stylistic issues
// across the existing codebase. Soft-landed as warn so `validate`
// stays green; HARNESS.md documents the path to promote them.
'svelte/require-each-key': 'warn',
'svelte/no-navigation-without-resolve': 'warn',
'svelte/prefer-svelte-reactivity': 'warn',
'svelte/no-at-html-tags': 'warn',
'svelte/require-each-key': 'error',
'svelte/no-navigation-without-resolve': 'error',
'svelte/prefer-svelte-reactivity': 'error',
'svelte/no-at-html-tags': 'error',
'no-useless-escape': 'warn',
'prefer-const': 'warn'
'prefer-const': 'error'
}
},

Expand All @@ -82,6 +79,10 @@ export default [
languageOptions: {
parser: svelteParser,
parserOptions: { parser: tseslint.parser, extraFileExtensions: ['.svelte'] }
},
rules: {
// One $props() destructuring can contain both bindable and readonly props.
'prefer-const': ['error', { destructuring: 'all' }]
}
},

Expand Down
8 changes: 5 additions & 3 deletions src/lib/components/Button.svelte
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
<script lang="ts">
import { resolve } from '$app/paths';
import type { Pathname } from '$app/types';
import type { Snippet } from 'svelte';

interface Props {
variant?: 'primary' | 'secondary' | 'danger' | 'ghost';
href?: string;
href?: Pathname;
type?: 'button' | 'submit';
onclick?: () => void;
children: Snippet;
}

let { variant = 'secondary', href, type = 'button', onclick, children }: Props = $props();
const { variant = 'secondary', href, type = 'button', onclick, children }: Props = $props();
</script>

{#if href}
<a {href} class="btn btn-{variant}">
<a href={resolve(href)} class="btn btn-{variant}">
{@render children()}
</a>
{:else}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/components/ConfigCard.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
install_count?: number;
}

let { config, username, onaction }: {
const { config, username, onaction }: {
config: Config;
username: string;
onaction: (action: string, slug: string) => void;
Expand Down
70 changes: 40 additions & 30 deletions src/lib/components/ConfigDetail.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { resolve } from '$app/paths';
import { normalizePackages, resolvePackages, type PackageInput } from '$lib/packages';
import type { ConfigSnapshot, SnapshotMacOSPref } from '$lib/types';
import { getCatalogItem } from '$lib/macos-prefs-catalog';
Expand All @@ -24,7 +25,7 @@
snapshot?: ConfigSnapshot | null;
}

let {
const {
configUser,
config,
packageDescriptions = {}
Expand Down Expand Up @@ -91,7 +92,7 @@
forking = false;
return;
}
goto('/dashboard');
goto(resolve('/dashboard'));
} catch {
forkError = 'Network error. Please try again.';
forking = false;
Expand Down Expand Up @@ -123,17 +124,6 @@
return new Date(ms).toLocaleDateString('en-US', { month: 'short', day: 'numeric' });
}

function escapeHtml(str: string): string {
return str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
}

/** Color comments muted and the leading command token accent, comp-style. */
function scriptLine(line: string): string {
const esc = escapeHtml(line);
if (/^\s*#/.test(line)) return `<span class="cmt">${esc}</span>`;
return esc.replace(/^(\s*)([\w./-]+)/, (_m, sp, cmd) => `${sp}<span class="cmd">${cmd}</span>`);
}

const dotfilesLabel = $derived(
config.dotfiles_repo ? config.dotfiles_repo.replace(/^https?:\/\//, '').replace(/\.git$/, '') : ''
);
Expand Down Expand Up @@ -188,7 +178,7 @@
<div class="page">
<div class="container">
<div class="topbar">
<a href="/explore" class="back">
<a href={resolve('/explore')} class="back">
<svg
width="15"
height="15"
Expand Down Expand Up @@ -238,7 +228,8 @@
{:else}
<span class="avatar avatar-ph">{configUser.username.charAt(0).toLowerCase()}</span>
{/if}
<a href="/{configUser.username}" class="user">@{configUser.username}</a>
<a href={resolve('/[username]', { username: configUser.username })} class="user">@{configUser.username}</a
>
<span class="vis-badge" class:public={visibility === 'public'}>{visibility}</span>
</div>

Expand Down Expand Up @@ -272,7 +263,7 @@
{/if}
{#if dnaLegend.length > 0}
<span class="counts">
{#each dnaLegend as l}
{#each dnaLegend as l (l.color)}
<span class="count" title={l.label}
><span class="swatch" style="background:{l.color};"></span>{l.n}</span
>
Expand Down Expand Up @@ -314,7 +305,7 @@
class="v link"
href={config.dotfiles_repo}
target="_blank"
rel="noopener noreferrer">{dotfilesLabel}</a
rel="external noopener noreferrer">{dotfilesLabel}</a
>
</div>
{/if}
Expand All @@ -331,8 +322,13 @@
<span class="count">{configCli.length}</span>
</h3>
<div class="pkg-grid">
{#each configCli as p}
<a class="pkg-card" href={getPackageUrl(p.name, 'formula')} target="_blank" rel="noopener noreferrer">
{#each configCli as p (p.name)}
<a
class="pkg-card"
href={getPackageUrl(p.name, 'formula')}
target="_blank"
rel="external noopener noreferrer"
>
<span class="pkg-name accent">{displayName(p.name)}</span>
{#if packageDescriptions[p.name]}<span class="pkg-desc">{packageDescriptions[p.name]}</span>{/if}
</a>
Expand All @@ -348,8 +344,13 @@
<span class="count">{configApps.length}</span>
</h3>
<div class="pkg-grid">
{#each configApps as p}
<a class="pkg-card" href={getPackageUrl(p.name, 'cask')} target="_blank" rel="noopener noreferrer">
{#each configApps as p (p.name)}
<a
class="pkg-card"
href={getPackageUrl(p.name, 'cask')}
target="_blank"
rel="external noopener noreferrer"
>
<span class="pkg-name amber">{displayName(p.name)}</span>
{#if packageDescriptions[p.name]}<span class="pkg-desc">{packageDescriptions[p.name]}</span>{/if}
</a>
Expand All @@ -365,8 +366,8 @@
<span class="count">{configNpm.length}</span>
</h3>
<div class="chips">
{#each configNpm as p}
<a class="chip npm" href={getPackageUrl(p.name, 'npm')} target="_blank" rel="noopener noreferrer"
{#each configNpm as p (p.name)}
<a class="chip npm" href={getPackageUrl(p.name, 'npm')} target="_blank" rel="external noopener noreferrer"
>{p.name}</a
>
{/each}
Expand All @@ -381,7 +382,7 @@
<span class="count">{configTaps.length}</span>
</h3>
<div class="chips">
{#each configTaps as p}
{#each configTaps as p (p.name)}
<span class="chip">{p.name}</span>
{/each}
</div>
Expand All @@ -394,8 +395,17 @@
<div class="term">
<div class="term-head">runs after packages install</div>
<div class="term-body">
{#each config.custom_script.split('\n') as line}
<div>{@html scriptLine(line)}</div>
{#each config.custom_script.split('\n') as line, i (i)}
{@const command = /^(\s*)([\w./-]+)/.exec(line)}
<div>
{#if /^\s*#/.test(line)}
<span class="cmt">{line}</span>
{:else if command}
{command[1]}<span class="cmd">{command[2]}</span>{line.slice(command[0].length)}
{:else}
{line}
{/if}
</div>
{/each}
</div>
</div>
Expand All @@ -422,7 +432,7 @@
{#if shell.theme}<div class="kv-row">
<span class="k">Theme</span><span class="v">{shell.theme}</span>
</div>{/if}
{#each Object.entries(git) as [key, value]}
{#each Object.entries(git) as [key, value] (key)}
<div class="kv-row"><span class="k">git.{key}</span><span class="v">{value}</span></div>
{/each}
</div>
Expand All @@ -433,7 +443,7 @@
<section class="pkg-section">
<h3 class="pkg-head">Dev tools <span class="count">{devTools.length}</span></h3>
<div class="chips">
{#each devTools as tool}
{#each devTools as tool, i (i)}
<span class="chip">{tool}</span>
{/each}
</div>
Expand Down Expand Up @@ -925,11 +935,11 @@
overflow-x: auto;
}

.term-body :global(.cmd) {
.term-body .cmd {
color: var(--accent);
}

.term-body :global(.cmt) {
.term-body .cmt {
color: var(--text-muted);
}

Expand Down
46 changes: 22 additions & 24 deletions src/lib/components/ConfigEditor.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script lang="ts">
import { onMount } from 'svelte';
import { goto } from '$app/navigation';
import { resolve } from '$app/paths';
import { SvelteMap } from 'svelte/reactivity';
import { auth } from '$lib/stores/auth';
import PackageManager from './PackageManager.svelte';
import MacOSPreferencesEditor from './MacOSPreferencesEditor.svelte';
Expand Down Expand Up @@ -29,7 +31,7 @@
snapshot?: ConfigSnapshot | null;
}

let { slug, skipAuth = false }: { slug?: string; skipAuth?: boolean } = $props();
const { slug, skipAuth = false }: { slug?: string; skipAuth?: boolean } = $props();
const isNew = $derived(!slug);

let loading = $state(true);
Expand All @@ -52,8 +54,8 @@
dotfiles_repo: ''
});

let selectedPackages = $state(new Map<string, string>());
let packageDescs = $state(new Map<string, string>());
let selectedPackages = $state.raw(new SvelteMap<string, string>());
let packageDescs = $state.raw(new SvelteMap<string, string>());

function pkgKey(name: string, type: string): string {
return `${type}:${name}`;
Expand Down Expand Up @@ -98,7 +100,7 @@
function initPackagesForPreset(preset: string) {
const p = PRESET_PACKAGES[preset];
if (!p) return;
const newMap = new Map<string, string>();
const newMap = new SvelteMap<string, string>();
for (const pkg of p.cli) newMap.set(pkgKey(pkg, 'formula'), 'formula');
for (const pkg of p.cask) newMap.set(pkgKey(pkg, 'cask'), 'cask');
if (p.npm) for (const pkg of p.npm) newMap.set(pkgKey(pkg, 'npm'), 'npm');
Expand All @@ -108,26 +110,22 @@
function handlePresetChange(preset: string) {
formData.base_preset = preset;
if (preset === 'scratch') {
selectedPackages = new Map();
packageDescs = new Map();
selectedPackages = new SvelteMap();
packageDescs = new SvelteMap();
} else {
initPackagesForPreset(preset);
}
}

function togglePackage(name: string, type: string, desc: string = '') {
const key = pkgKey(name, type);
const newMap = new Map(selectedPackages);
const newDescs = new Map(packageDescs);
if (newMap.has(key)) {
newMap.delete(key);
newDescs.delete(key);
if (selectedPackages.has(key)) {
selectedPackages.delete(key);
packageDescs.delete(key);
} else {
newMap.set(key, type);
if (desc) newDescs.set(key, desc);
selectedPackages.set(key, type);
if (desc) packageDescs.set(key, desc);
}
selectedPackages = newMap;
packageDescs = newDescs;
}

function normalizePrefValue(type: string, value: string): string {
Expand All @@ -154,7 +152,7 @@
if (!skipAuth) {
await auth.check();
if (!$auth.user && !$auth.loading) {
goto('/login?return_to=/dashboard');
goto(resolve('/login?return_to=/dashboard'));
return;
}
}
Expand All @@ -175,8 +173,8 @@
dotfiles_repo: data.dotfiles_repo || ''
};
if (data.packages?.length) {
const map = new Map<string, string>();
const descs = new Map<string, string>();
const map = new SvelteMap<string, string>();
const descs = new SvelteMap<string, string>();
for (const pkg of normalizePackages(data.packages, data.snapshot?.packages)) {
const t = pkg.type || 'formula';
const k = pkgKey(pkg.name, t);
Expand Down Expand Up @@ -214,8 +212,8 @@
macosPrefs = Array.isArray(config.snapshot?.macos_prefs) ? mapPrefs(config.snapshot.macos_prefs) : [];
const savedPkgs = config.packages || [];
if (Array.isArray(config.packages)) {
const newMap = new Map<string, string>();
const newDescs = new Map<string, string>();
const newMap = new SvelteMap<string, string>();
const newDescs = new SvelteMap<string, string>();
for (const pkg of normalizePackages(savedPkgs, config.snapshot?.packages)) {
const t = pkg.type || 'formula';
const k = pkgKey(pkg.name, t);
Expand Down Expand Up @@ -267,8 +265,8 @@
custom_script: parsed.custom_script || '',
dotfiles_repo: parsed.dotfiles_repo || ''
};
const newMap = new Map<string, string>();
const newDescs = new Map<string, string>();
const newMap = new SvelteMap<string, string>();
const newDescs = new SvelteMap<string, string>();
for (const pkg of normalizePackages(parsed.packages || [], parsed.snapshot?.packages, false)) {
const t = pkg.type || 'formula';
const k = pkgKey(pkg.name, t);
Expand Down Expand Up @@ -348,7 +346,7 @@
error = result.error || 'Failed to save';
return;
}
goto('/dashboard');
goto(resolve('/dashboard'));
} catch (e) {
error = 'Failed to save: ' + (e as Error).message;
} finally {
Expand All @@ -367,7 +365,7 @@
<div class="editor">
<!-- save bar -->
<div class="savebar">
<button class="back" onclick={() => goto('/dashboard')}>
<button class="back" onclick={() => goto(resolve('/dashboard'))}>
<svg
width="15"
height="15"
Expand Down
Loading
Loading