Check a project
In this unit, you install Ashlar in a small TypeScript project, run ashlar check, watch a rule fail with the
message an agent reads, and fix what it found. At the end, the check passes again:
$ pnpm exec ashlar checkAshlar checked 1 file in 0.1 s: no count rose.There is no baseline, so every count must stay at zero.Before you begin
Section titled “Before you begin”- Node 22.18 or later. Ashlar loads
ashlar.config.tswith Node's own type stripping, so the config needs no build step. - Git.
- pnpm, npm or Yarn. Each command on this page shows all three.
Check a project
Section titled “Check a project”-
Make a project with Git.
Terminal mkdir shopcd shopgit initGive it a
package.json, with"type": "module"so Node readsashlar.config.tsas a module.package.json {"name": "shop","private": true,"type": "module"}If a project can't have
"type": "module", name the configashlar.config.mtsinstead.Add one file of code.
src/total.ts export function total(prices: number[]): number {return prices.reduce((sum, price) => sum + price, 0);} -
Install Ashlar as a dev dependency, from its release.
Terminal pnpm add -D https://github.com/kurvball/ashlar/releases/download/v1.2.1/kurvball-ashlar-1.2.1.tgzTerminal npm install -D https://github.com/kurvball/ashlar/releases/download/v1.2.1/kurvball-ashlar-1.2.1.tgzTerminal yarn add -D https://github.com/kurvball/ashlar/releases/download/v1.2.1/kurvball-ashlar-1.2.1.tgz -
Write
ashlar.config.tsat the root of the project.ashlar.config.ts import { defineConfig } from '@kurvball/ashlar';export default defineConfig({include: ['src'],});includenames the folders Ashlar checks. It is the only key a config needs. The config reference lists the others. -
Run the check.
Terminal pnpm exec ashlar checkTerminal npx --no-install ashlar checkTerminal yarn ashlar checkAshlar prints what it checked, and exits with 0.
Terminal $ pnpm exec ashlar checkAshlar checked 1 file in 0.1 s: no count rose.There is no baseline, so every count must stay at zero.A project with no baseline holds every rule at zero breaks.
-
Break a rule. Add a comment to
src/total.ts, as an agent might.src/total.ts // Adds up the prices in the cart.export function total(prices: number[]): number {return prices.reduce((sum, price) => sum + price, 0);}Run the check again. This time it fails, and exits with 1.
Terminal $ pnpm exec ashlar checkAshlar checked 1 file in 0.1 s: 1 count rose.no-comment in src/total.ts: 1, up from 0src/total.ts:1:1Comments go stale and nothing checks them. Rename it, or write a test. Git leads from any line to the item or task that wrote it.The check names the rule, the file, its count against the baseline, and where each break is. The last line is the rule's message: what an agent reads, and what to do instead.
-
Do what the message says. The comment said what the function adds up, so let the name say it.
src/total.ts export function cartTotal(prices: number[]): number {return prices.reduce((sum, price) => sum + price, 0);}Run the check once more. It passes.
Terminal $ pnpm exec ashlar checkAshlar checked 1 file in 0.1 s: no count rose.There is no baseline, so every count must stay at zero.
On a repository that already has breaks
Section titled “On a repository that already has breaks”Most code isn't at zero. In a repository with breaks, take a baseline once.
$ pnpm exec ashlar check --shrinkAshlar checked 2 files in 0.1 s and took the baseline: 3 breaks in ashlar.baseline.json.Commit ashlar.baseline.json. From then on, ashlar check fails when a file's count rises above what the
baseline holds for it, and --shrink only ever lowers it. The ratchet explains how, and
Adopt Ashlar in an existing repository walks through it.
Ashlar exits with 0 when all is well, 1 when a check or a drive fails, and 2 when a command or the config is
wrong. Every command but skill takes --json.