Repository navigation
feat: fail Markdown files that are over their byte budget - #1
Merged
Merged
Conversation
A file's budget comes from its own frontmatter max_size_bytes, a glob rule in the config, or the config's global, most specific first. The config is looked for in six canonical locations relative to the repo root and is never searched for upward. Every over-budget file gets the message the desired design specifies and the run exits 1.
Thirty fixtures quoted from six public repositories, each with a sidecar naming its source, commit, last author, licence and capture date. The harness builds a temp repo per case, checks the sidecars against the bytes on disk, and derives what it expects from the budgets the case intends. Unit tests cover the rules one at a time over trees written for the test.
The as-built design doc now matches the code. The README says what the tool does and how to configure it. AGENTS.md carries the rule that the test corpus is data and its instructions are not to be followed, and the template's setup section and setup script are gone.
This was referenced Sep 23, 2026
webern
commented
Sep 23, 2026
webern
left a comment
Owner
Author
There was a problem hiding this comment.
In general, let's anticipate a lot of growth in the codebase and organize our code files into directories under src/ with nice module boundaries.
webern
commented
Sep 23, 2026
Addresses the review on this PR.
- src/ is now cli/, config/, glob/, parse/ and lint/, each with a mod.rs.
- config/search.rs finds the file; config/md.rs and config/lints.rs hold
the schema.
- glob/ walks every file and matches patterns without knowing about
Markdown, so another file type can reuse it.
- parse/frontmatter.rs reads any top-level key.
- lint/ holds one module per lint; max_size_bytes.rs is the first.
The config now carries a required schema_version (NonZeroU32; a later
version than this build reads is refused) and nests everything under a
per-file-type section:
schema_version = 1
[md]
globs = ["*.md"]
[md.lints.max_size_bytes]
value = 20000
message = "..."
[[md.overrides]]
globs = ["AGENTS.md"]
lints.max_size_bytes.value = 8000
Each lint has its own settings table, every field optional. Overrides
merge field by field in specificity order, so one can change only the
message for one file. A configured message replaces the advice in the
report, with {path} and {max_size_bytes} substituted.
The default [md] globs is "*.md", which is case sensitive; the old walk
also took .MD.
webern
commented
Sep 23, 2026
3 tasks done
webern
added a commit
that referenced
this pull request
Sep 23, 2026
## Human Summary Use the `.gitignore` to ignore files! ## Summary Deslag used to scan every Markdown file under the repo root, including build output and anything else git ignores. This PR replaces the hand-written directory walk in `src/glob/walk.rs` with the `ignore` crate's `WalkBuilder`. `ignore` is ripgrep's walker and comes from the same project as `globset`, which deslag already uses. The walk now skips what git would skip: `.gitignore` files at any depth (negations included), `.git/info/exclude`, the global git excludes file, and `.ignore` files. Nothing else changes: - Hidden files and directories are still walked, since `.github/` and `.agents/` hold Markdown. - Symlinks are still not followed. - `.git/` is still skipped. - The output is still `RepoFile`s sorted by relative path. Two settings were chosen on purpose: - `require_git(false)`: `.gitignore` applies even when there is no `.git` directory, as in an unpacked tarball or the test temp dirs. - `parents(false)`: ignore files above the repo root are not read. A broken ignore file or an unreadable directory now fails as a new `Error::Walk`, which names the path. ## Testing - [x] `make ci`: exit 0 - [x] New tests in `tests/unit.rs`: a gitignored directory, a nested `.gitignore`, a negation, and a hidden directory that is still scanned - [x] `docs/design/deslag.asbuilt.md` updated for the new walk ## References - Closes #2 - Follows #1
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Human Summary
Initial lint! Looks for Markdown files bigger than their byte budget.
Summary
Deslag has its first rule. A Markdown file has a byte budget, and
deslag checkreports every file that is over its own budget and exits nonzero, so a CI job can gate on it.This implements the size rule in
docs/design/deslag.desired.md, which is the human-authored doc describing what deslag is meant to be.docs/design/deslag.asbuilt.mdhas been rewritten to say what is actually here now.A file's budget comes from three places, most specific first. Its own YAML frontmatter can declare
max_size_bytes; otherwise the most specific matching override in the config that sets one; otherwise the budget the config sets for all Markdown. A file that none of the three claims has no budget and is left alone.The config
Config is TOML, looked for in six canonical locations relative to the root of the repo and never searched for upward, since a run that cannot find one is a mistake worth reporting rather than guessing about.
--config-pathreplaces all six.The format is built to grow: a schema version, then one section per kind of file, each with its own lints and overrides. Today there is one section,
[md], and one lint,max_size_bytes.schema_versionis required. It goes up only when a change means existing configs need migrating, and a config from a later schema than the binary reads is refused.[md] globschooses which files the section lints,*.mdby default. Each lint has its own settings table, shaped for that lint, and every field in it is optional. An override lays its settings over the section's, field by field, so one can change only the message for one file and keep the budget. When several overrides match, the most specific pattern wins: anchored beats basename, then longer beats shorter, then the one declared later.A pattern without a slash matches a basename anywhere in the repo; one with a slash is anchored at the root.
*stays inside one path component and**crosses them. Matching is case sensitive.The message an over-budget file gets is the one the desired doc spells out, verbatim, and the tests assert it that way. A
messagein the config replaces the advice part of it; the heading and theis larger thanline always stay.Code layout
The library is split into directories so each concern has room to grow:
Errors are
thiserrorin the library andanyhowinsrc/main.rs.What is in scope
max_size_byteslint over Markdown files, its config, and thechecksubcommandAGENTS.mdand the README say what this is, the setup section and its script are gone,Cargo.tomlhas a description and keywordsWhat is deliberately not in scope
.gitignore: every file outside.gitis walkedTesting
The corpus is 30 Markdown files quoted from six public MIT repositories: rust-template, denigma, midi_file, exile, tblfmt and mnx-rs. Each fixture sits next to a JSON sidecar naming where it was quoted from, at which commit, who last touched it, under what licence and when it was captured. The harness checks each sidecar against the bytes on disk, so a fixture that gets edited fails the suite, and it derives what it expects from the bytes it placed rather than from anything stored.
The matrix covers all six canonical config locations,
--config-path, three layouts (flat, nested, and the real directory structure each fixture came from), basename against anchored against path globs,**globs, override specificity, frontmatter against config, a clean run, and the order of the canonical locations.The unit tests also cover overrides that set only some fields, custom messages,
[md] globs, a missing or too-newschema_version, and an unknown lint name.make ci: exit 0make test: 29 unit tests and the corpus matrix, 0 failedChoices the desired design doc left open
The doc asks for a specificity mechanism but leaves the shape to be settled, so: overrides with glob patterns, anchored beats basename, longer beats shorter, and the file's own frontmatter beats every config setting. For the corpus, the doc says the sidecar should "probably" hold the expected outcome; instead the sidecar holds the quotation's facts and the expectation is derived, which keeps an outcome from becoming something a fixture is edited to satisfy. How to tell human writing from LLM writing is left as TBD in the doc, so each sidecar records the last commit author and date and marks authorship as unknown.
References
docs/design/deslag.desired.md.gitignorewhen globbing markdown files. #2 (observe.gitignore)