lint-showcase
One deliberate warning for each lint rule (duolith lint examples/lint-showcase, then --fix), with a duolith.yaml that sets rule levels. It is the one example that does not lint clean.
Run it
cargo run -p duolith-cli -- dev examples/lint-showcase # live, reloads on save
cargo run -p duolith-cli -- build examples/lint-showcase # static output in examples/lint-showcase/dist
The folder on the web: examples/lint-showcase.
Source
components/Tag.duo
---
// W0041 unused-prop: tone is accepted but never used.
import { props } from "@duolith/client";
let { label, tone = "quiet" } = props<{ label: string; tone?: string }>();
---
<view class="self-start px-2 py-1 rounded-full bg-primary">
<text class="text-caption text-on-primary">{label}</text>
</view>duolith.yaml
# Project settings. lint: sets each lint rule, by name or code, to off,
# warning (the default) or error (duolith lint then fails). Decision 0080.
lint:
large-inline-literal: warning
# list-without-key: error
# W0061: offpages/index.duo
---
// Every lint rule, tripped once on purpose. `duolith lint examples/lint-showcase`
// reports each; `duolith lint examples/lint-showcase --fix` fixes the ones with
// a safe fix. The page builds and runs: lint warnings are advice, not errors.
import { effect, state } from "@duolith/client";
import Tag from "../components/Tag.duo";
type Todo = { id: number; title: string };
let todos = state<Todo[]>([
{ id: 1, title: "Buy oat milk" },
{ id: 2, title: "Water the plants" },
]);
let budget = state(3);
let todo = state("");
let presses = state(0);
let renders = state(0);
// W0040 unused-state: nothing reads or writes it.
let forgotten = state(0);
// W0022 effect-writes-what-it-reads: the effect follows renders and assigns it.
effect(() => {
if (renders < 1) renders = renders + 1;
});
---
<screen title="Lint showcase" class="p-4 gap-4 bg-canvas">
<text class="text-title text-ink">Lint showcase</text>
<Tag label="One warning per rule" tone="quiet" />
<!-- W0001 press-without-role: a keyboard cannot reach a pressable view. -->
<view class="p-3 rounded-lg bg-surface border" on:press={() => (presses = presses + 1)}>
<text class="text-body text-ink">Pressed {presses} times</text>
</view>
<!-- W0002 field-without-label: a placeholder is not a label. -->
<input
class="px-3 py-2 rounded-md bg-surface border text-body text-ink"
placeholder="Search todos"
bind:value={todo}
/>
<!-- W0003 low-contrast: muted text on a border-coloured background. -->
<view class="p-3 rounded-lg bg-border">
<text class="text-caption text-muted">Quiet text, hard to read</text>
</view>
<!-- W0004 nested-pressable: a button inside a link. -->
<view class="row items-center justify-between p-3 rounded-lg bg-surface border" href="/">
<text class="text-body text-ink">Open the list</text>
<button
class="px-3 py-1 rounded-md bg-primary text-on-primary text-label"
on:press={() => (presses = 0)}
>
Reset
</button>
</view>
<!-- W0020 list-without-key and W0043 shadowed-name (todo is also state). -->
<list each={todos} as="todo" class="gap-2">
<text class="text-body text-ink">{todo.title}</text>
</list>
<!-- W0021 large-inline-literal: built again whenever budget changes. -->
<text class="text-body text-ink">
{[{ name: "Espresso", price: 2 }, { name: "Flat white", price: 3 }, { name: "Cortado", price: 3 }, { name: "Filter", price: 2 }, { name: "Mocha", price: 4 }, { name: "Chai", price: 3 }].filter((drink) => drink.price <= budget).length}
drinks within budget
</text>
<!-- W0042 unreachable-otherwise: the show is always true. -->
<show when={true}>
<text class="text-body text-ink">Always shown</text>
</show>
<otherwise>
<text class="text-body text-ink">Never shown</text>
</otherwise>
<!-- W0060 conflicting-utilities: p-4 overrides p-2. -->
<view class="p-2 p-4 rounded-lg bg-surface border">
<text class="text-body text-ink">Padded twice</text>
</view>
<!-- W0061 hard-coded-colour, twice: in the style block below. -->
<text class="note">Colours written out</text>
</screen>
<style>
.note { color: #4b5bdc; border-bottom: 1px solid #e2dfd8; }
</style>