Skip to content

feat: lint the repository layout section - #19

Merged
webern merged 5 commits into
mainfrom
m/repo-layout
Sep 24, 2026
Merged

webern merged 5 commits into
mainfrom
m/repo-layout

Conversation

@webern

@webern webern commented Sep 24, 2026 •

Copy link
Copy Markdown
Owner

Summary

Adds a third lint, repo_layout. It checks that a Markdown file, usually AGENTS.md, has a short index of the repo whose paths all exist.

The index is the first code block in the ## Repository layout section. The heading can be changed in the config, and it matches at any level and in any case. The section ends at the next heading of the same level or higher. Each line of the block is an entry: a path, then <- and a description.

deslag/
  Makefile             <- every build, test and check; `make help` lists the targets
  src/lint/            <- running the lints; one module per lint, e.g. max_size_bytes.rs
  tests/corpus/        <- quoted Markdown, each fixture with a JSON sidecar: core/ is hand-picked,
                          human/, llm/ and mixed/ are collected, one directory per source repo

The format is strict so that it stays tidy:

  • The first line may name the root (deslag/). It is not an entry.
  • Every path starts in the same column as the first entry's, and every <- sits in the same column as the first entry's.
  • Every entry needs a description.
  • No line may be wider than max_width characters, 100 by default, not counting trailing whitespace.
  • A description too long for one line continues on the next, starting under the description above. The advice does not show this, so that an agent does not read wrapping as a good way to say more.
  • Paths are relative to the directory the Markdown file is in, and must exist on disk. A path ending in / must be a directory.

A file fails when the section or its code block is missing, when the number of entries is outside min_entries to max_entries, when a line is too wide or breaks the format, or when a path does not exist. The report lists every problem with its line number, so an agent can fix them one by one. The advice shows an example layout under the configured heading, so an agent that has never seen the format has one to copy instead of guessing from a description:

ERROR: deslag detected a broken repository layout!

AGENTS.md has 3 problems in its "Repository layout" section.

<advice: what the section is for, an example layout to copy, the format, and not to change the limits>

The problems:
  the layout lists 3 entries; it must list between 1 and 2
  line 7: `<-` is in column 12; the first entry's is in column 13
  line 7: gone.rs does not exist

The config:

[[md.overrides]]
globs = ["/AGENTS.md"]
lints.repo_layout = { min_entries = 5, max_entries = 12 }

The defaults are 5 to 15 entries, and max_width defaults to 100. The other lints only run when one of their limits is set, but for this one the table alone turns it on, because requiring the section is the point. Overrides and message work as they do for the other lints.

Because of the defaults, min_entries and max_entries can contradict each other only once they are merged for a particular file. For example, min_entries = 20 alone conflicts with the default maximum of 15, and so does a section-wide minimum paired with a smaller maximum in an override. The run checks each file's merged settings and stops with a config error that names the file. It does not produce a report the agent could never satisfy.

This repo's config turns the lint on for AGENTS.md with 5 to 12 entries. I cut the layout there from 16 entries to 12:

  • dropped AGENTS.md <- you are here and _typos.toml;
  • moved src/main.rs into the description of src/lib.rs;
  • moved .claude/skills into the description of .agents/skills/.

As the issue suggested, the lint uses the Markdown parser. pulldown-cmark was already a dependency. The options it is set up with, and the lookup from byte offset to line number, move out of max_emphasis into src/parse/markdown.rs, so both Markdown lints share them.

The lint is in two parts. repo_layout::read works from the text alone: it finds the section, and returns the entries, any lines that break the format, and the width of each line. repo_layout::check adds the entry limits and the width limit, and looks the paths up on disk. The split exists so the test corpus can exercise the lint. The corpus has none of the repos its fixtures describe, so the parts that need the disk are tested on small directory trees the tests create. The as-built doc now states this as a rule for every lint: whatever a lint decides from the text alone lives in a function of the text, so the corpus can run it. max_emphasis::measure already works this way.

There is one limitation. Paths are looked up on disk, so a path that git ignores, such as a build directory, passes on a machine that has built it and fails on a clean checkout.

README and deslag.asbuilt.md are updated.

Testing

  • make ci: exit 0
  • tests/corpus.rs: a new test runs read on every fixture, under eight headings real repos use for a layout. It reads 12 real layouts: lists, tree drawings and prose. Every line it reports must fall inside the section, and an entry's line must hold its path. core/rt-agents.md is the one fixture written in deslag's format, and it must read with no format problems.
  • tests/layout.rs: 22 new tests covering:
    • read working from the text alone, with no files on disk;
    • how the heading is matched, and where the section ends;
    • that frontmatter is never mistaken for a heading;
    • the default limits and custom limits;
    • an empty block;
    • each format problem, including continuation lines;
    • lines wider than max_width, and its default of 100;
    • paths that are missing, and a file where a directory is expected;
    • paths relative to an AGENTS.md in a subdirectory;
    • the full report, the short report for a missing section, a custom message, and both kinds of contradictory limits;
    • the example in the advice: the report is rendered, read as Markdown, and must pass the lint. Misaligning one <- in the example fails it.
  • make check-deslag on this repo: it failed on the 16-entry AGENTS.md and passes after the trim

References

Add a repo_layout lint. A file it applies to must have a section,
"Repository layout" by default, whose first code block lists the
paths that matter most, one per line, as `path  <- description`,
with every path and every `<-` in one column.

The lint fails the file when the section or the block is missing,
when the number of entries is outside min_entries to max_entries (5
to 15 by default), when a line is out of format, or when a listed
path does not exist relative to the Markdown file. The report lists
every problem with its line.

Turn it on for this repo's AGENTS.md with 5 to 12 entries, and trim
the layout there from 16 entries to 12.

Move the pulldown-cmark options and the line lookup into
parse/markdown.rs so both Markdown lints share them.
@webern webern added enhancement New feature or request area/lint Deals with the linting algorithms themselves, how they work. labels Sep 24, 2026
Split repo_layout into read, which finds the section and reads the
layout from the text alone, and check, which adds the limits and
looks the paths up on disk. The corpus has none of the repos its
fixtures describe, so it can run only the part that needs no disk.

Add a corpus test that reads the layout of every fixture under a few
headings real repos use. The lines it reports must fall in the
section, an entry's line must hold its path, and core/rt-agents.md,
the one fixture in deslag's format, must read with no malformed line.

The as-built doc now says each lint keeps what it decides from the
text alone in a function of the text, so the corpus can run it.
@webern
webern added this pull request to stack #21 September 24, 2026 11:44
Comment thread src/lint/repo_layout.rs Resolved
An agent told only the rules of the layout format can guess wrong and
keep guessing. The default advice now shows a layout to copy, under
the configured heading, and the prose around it is shorter.

A test renders the report, reads it as Markdown, and checks that the
example in it passes the lint, so the example cannot drift out of
format.
Comment thread src/lint/repo_layout.rs Resolved
The example in the advice wrapped a description onto a second line,
which shows an agent that wrapping is a fine way to say more. Drop
the wrap. A continuation still passes, but the advice no longer shows
one.

No line of the layout may be wider than 100 characters now, not
counting trailing whitespace. A wider line is malformed, and its
problem asks for it to be shortened. The advice, the README and the
as-built doc state the limit.
The widest line a layout may have is now the max_width setting, 100
by default, and a config message can name it with {max_width}.

read still works from the text alone. It returns the width of each
line, and check compares them with the setting, as it does the entry
count. A line that is too wide is now its own problem rather than a
format problem, since whether it fails depends on the settings.
@webern
webern merged commit 96c3343 into main Sep 24, 2026
2 checks passed
@webern
webern deleted the m/repo-layout branch September 24, 2026 14:24
webern added a commit that referenced this pull request Sep 24, 2026
## Summary

Adds a second kind of test data next to the corpus: cases, written for
one lint and shipped with whatever they need on disk.

The corpus can't do this job. Its fixtures are quoted from other repos
and never edited, and the repos they describe aren't there. A lint like
`repo_layout` needs a directory tree to check paths against, and its
report is only worth pinning on a document written to break it in known
ways.

A case is a directory under `tests/cases/<lint>/` that is a whole repo
root: the Markdown, a `deslag.toml`, and any files the lint looks for.
Beside it, `<case>.stderr` holds exactly what `deslag check` prints
there:

```
tests/cases/repo_layout/
  broken/
    deslag.toml
    AGENTS.md
    Makefile
    src/lib.rs
    ...
  broken.stderr     <- the exact report
  clean/
    ...
  clean.stderr      <- empty: the run must pass
```

`tests/cases.rs` copies each case to a temp directory, runs the binary
there, and compares its stderr with the file. Some other details:

- The exit code isn't stored. An empty `.stderr` means the run must exit
0, and any other means exit 1. That is the contract the binary already
has.
- Config errors print absolute paths, so the temp root is written as
`[ROOT]`.
- A `.stderr` file with no case beside it, or any other stray file,
fails the test, so renaming a case can't leave a stale file behind.
- On a mismatch, the test prints the first line that differs, both
outputs, and the command to accept the new output.

Accepting new output is `make fix-test-output`, which runs the test with
`DESLAG_FIX_TEST_OUTPUT=1`. It is part of `make fix`, and the build
doctrine's definition of `fix` now says so. It accepts whatever deslag
prints, so the diff has to be read.

The first cases replace the tests in `tests/layout.rs` that ran the
binary. Those tests checked pieces of the report with `contains`, while
the cases pin all of it:

- `broken`: one layout with every kind of problem, so every message's
wording is pinned. It sets `max_width = 80`, so the advice and the width
problem must both show the configured width.
- `clean`: a good layout passes on the default limits
- `no_section`, `no_block`: the short report, and a heading with no code
block (not covered before)
- `custom_message`: a config `message` replaces the advice, with every
placeholder filled in
- `nested`: paths are relative to `src/AGENTS.md`, not the repo root
- `min_over_max`, `min_over_default_max`: the two ways the limits can
contradict each other

The tests of `read` and `check` stay in `tests/layout.rs`.

`tests/cases/` isn't excluded from the spell check: cases are ours,
unlike the corpus. The self-lint globs are anchored, so the cases'
`AGENTS.md` files aren't linted as this repo's own.

A case can't hold a `.git` directory, or a `.gitignore` that ignores its
own files, because git would apply it to this repo too. The harness's
doc comment says so.

`AGENTS.md` and the as-built doc are updated.

## Testing

- [x] `make ci`: exit 0
- [x] Ran the harness before any `.stderr` existed: every case reported
its file as missing. Then ran `make fix-test-output` and checked each
`.stderr` line by line against its source: line numbers, columns, entry
counts and file counts.
- [x] Changed one line of `nested.stderr` and added a stray
`orphan.stderr`: the test failed on both, naming line 10 as the first
difference. Restored both.

## References

- Stacked on #19. The cases use the `repo_layout` lint it adds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/lint Deals with the linting algorithms themselves, how they work. enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Lint AGENTS.md (or any Markdown file, I guess) for a Repository layout section.

1 participant