Skip to content
Ashlarv1.2.1

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:

Terminal
$ pnpm exec ashlar check
Ashlar checked 1 file in 0.1 s: no count rose.
There is no baseline, so every count must stay at zero.
  • Node 22.18 or later. Ashlar loads ashlar.config.ts with 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.
  1. Make a project with Git.

    Terminal
    mkdir shop
    cd shop
    git init

    Give it a package.json, with "type": "module" so Node reads ashlar.config.ts as a module.

    package.json
    {
    "name": "shop",
    "private": true,
    "type": "module"
    }

    If a project can't have "type": "module", name the config ashlar.config.mts instead.

    Add one file of code.

    src/total.ts
    export function total(prices: number[]): number {
    return prices.reduce((sum, price) => sum + price, 0);
    }
  2. 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.tgz
  3. Write ashlar.config.ts at the root of the project.

    ashlar.config.ts
    import { defineConfig } from '@kurvball/ashlar';
    export default defineConfig({
    include: ['src'],
    });

    include names the folders Ashlar checks. It is the only key a config needs. The config reference lists the others.

  4. Run the check.

    Terminal
    pnpm exec ashlar check

    Ashlar prints what it checked, and exits with 0.

    Terminal
    $ pnpm exec ashlar check
    Ashlar 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.

  5. 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 check
    Ashlar checked 1 file in 0.1 s: 1 count rose.
    no-comment in src/total.ts: 1, up from 0
    src/total.ts:1:1
    Comments 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.

  6. 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 check
    Ashlar checked 1 file in 0.1 s: no count rose.
    There is no baseline, so every count must stay at zero.

Most code isn't at zero. In a repository with breaks, take a baseline once.

Terminal
$ pnpm exec ashlar check --shrink
Ashlar 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.