Skip to content

feat: read each file once into a document - #26

Merged
webern merged 1 commit into
mainfrom
m/document-layer
Sep 26, 2026
Merged

webern merged 1 commit into
mainfrom
m/document-layer

Conversation

@webern

@webern webern commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Human Summary

Mostly a refactor, but also with couple of bugs found and fixed. Gives a parser and a document model.

Summary

The lints that are coming next judge sentences and words, not Markdown structure. Until now each lint parsed Markdown on its own and kept only what it needed. This PR adds deslag::document, a public module that reads a file once into layers every lint can share:

  • Blocks, nested as Markdown nests them: a list holds items, an item holds paragraphs and lists. Code blocks, HTML blocks and frontmatter keep their kind and raw text but hold no prose.
  • Pieces of text, spans (emphasis, links, images) and points (soft and hard line breaks, and the gaps between blocks). Every position is a byte offset into the file, and a point records the whitespace it stands for, so one blank line and two differ.
  • A flat row of tokens. Words come from the Unicode word rules in unicode-segmentation, a new dependency with no dependencies of its own. Inline code, inline HTML, images and bare URLs are one token each, never split into words.
  • Sentences over the tokens, split at terminal punctuation, a hard break or the end of a block.

banned_chars, density, max_emphasis and repo_layout now read the document instead of parsing Markdown themselves, and src/parse/markdown.rs is gone. max_size_bytes still reads raw bytes. No lint reads tokens or sentences yet; they are the ground the list lint in #16 will stand on.

Two TODO comments record known gaps. The sentence splitter ends a sentence after "Dr.". Prose inside a code block, HTML block or frontmatter is invisible to prose rules.

Two bugs fixed

The old parsing had two bugs that the document does not have. Each gets a regression test that fails on main.

  • density skipped the text of a tight list item that opens with markup: - **bold** rest counted 5 characters, and - [a link](x) was not measured at all. On the corpus, 2,283 more list items are now measured, 82 files get a different report, and 12 more files fail at the default limits (8 LLM, 4 mixed, 0 human). No file that failed now passes.
  • max_emphasis counted the indentation of an indented HTML block as prose. This touches 8 corpus files. No span changes, and the largest move in a share is 0.09 points.

banned_chars and repo_layout read exactly what they did before on all 1,257 corpus files.

Testing

  • make ci: exit 0
  • Every tests/cases stderr is byte-identical, and the corpus tests pass unchanged
  • New tests for the document layer, and a corpus test that every block sits inside its parent and every token and sentence sits inside its block, in file order
  • Each lint's readings dumped for every corpus file on main and on this branch, then compared
  • The two regression tests run against main, where both fail

References

Add deslag::document, which reads a Markdown file once into layers
that the lints share:

- Blocks, nested as Markdown nests them. Code blocks, HTML blocks
  and frontmatter keep their raw text and hold no prose.
- Pieces of text, spans such as emphasis and links, and points such
  as line breaks and the gaps between blocks. Each is a byte range
  in the file.
- A flat row of tokens. Words come from the Unicode rules in the
  unicode-segmentation crate. Inline code, inline HTML, images and
  URLs are one token each.
- Sentences over the tokens.

banned_chars, density, max_emphasis and repo_layout now read the
document instead of parsing Markdown on their own, and
src/parse/markdown.rs is gone. max_size_bytes still reads raw bytes.
No lint reads tokens or sentences yet.

Two bugs go away with the old parsing, each with a regression test:

- density skipped the text of a tight list item that opens with
  markup, such as "- **bold** rest".
- max_emphasis counted the indentation of an indented HTML block as
  prose.
@webern webern added enhancement New feature or request area/parse Deals with parsing the files we are linting. area/lint Deals with the linting algorithms themselves, how they work. labels Sep 25, 2026
@webern
webern merged commit 9f1fea1 into main Sep 26, 2026
2 checks passed
@webern
webern deleted the m/document-layer branch September 26, 2026 06:32
@webern webern added the ai Primarily authored by AI (whether PR, Issue, Whatever) label Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai Primarily authored by AI (whether PR, Issue, Whatever) area/lint Deals with the linting algorithms themselves, how they work. area/parse Deals with parsing the files we are linting. enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant