Skip to content

feat(rules): add items rule to validate each list item - #102

Merged
jackchuka merged 1 commit into
mainfrom
feat/list-items
Nov 11, 2026
Merged

jackchuka merged 1 commit into
mainfrom
feat/list-items

Conversation

@jackchuka

Copy link
Copy Markdown
Owner

Summary

Adds items to list rules so a schema can constrain every top-level item of a list, not just require the list to exist:

lists:
  - min: 1
    items:
      required_text:
        - pattern: '^[A-Za-z][A-Za-z0-9]*(\s.*)?$'
      forbidden_text: ["TODO"]
✗ 4:3 [list] List item '**Card**' in section 'Components' does not match '^[A-Za-z][A-Za-z0-9]*(\s.*)?$'
✗ 6:3 [list] List item 'Modal TODO' in section 'Components' contains forbidden text 'TODO'

Supersedes #89, reworked on top of #100 and #101. Thanks to @kinchoKayaba for the original proposal and implementation.

Design

  • items reuses required_text / forbidden_text, with the same literal (substring) and {pattern: ...} (regex) forms, instead of a new items_must_match key. This keeps the vocabulary users already know and leaves room for more per-item rules later.
  • Multiple required_text entries are combined with AND, as in section-level required_text. Go's regex engine has no lookahead, so AND cannot be expressed in a single pattern.
  • Items are matched against their raw Markdown, so **Card** keeps its asterisks. This matches how section-level text rules see content.
  • Only top-level items of lists matching type are checked. Sub-lists are already excluded since fix(parser): count only top-level lists in list rules #100.

Changes

  • schema.ListRule.Items (ListItemsRule); schema.json regenerated
  • parser.List.Items (ListItem{Text, Line, Column}) replaces ItemCount
  • internal/rules/list.go: per-item checks and generate hints
  • internal/rules/text_pattern.go: shared literal/regex matching for required_text, forbidden_text, and items
  • README: new "List Items" section

Test plan

  • Parser: raw text, wrapped lines, item positions
  • Rules: mismatch, AND across entries, literal form, forbidden_text, nested items skipped, type respected, generator hints
  • Loader: items loads without unknown-key warnings
  • go test ./... and go vet ./... pass; examples/* and the README self-check pass

A list rule could require a list but not constrain what its items say.
Add `items` to list rules, applying `required_text` and `forbidden_text`
to every top-level item of a matching list. Items are matched against
their raw Markdown, and one violation is reported per failing (item,
pattern) pair at the item's position.

The parser now records each list's items, replacing ItemCount with
Items. The literal/regex matching shared by required_text and
forbidden_text moves into a single helper.

Based on the design in #89.

Co-authored-by: sakanaka <[email protected]>
Claude-Session: https://claude.ai/code/session_014K1p9VkeotiX1SR8pLWJSK
@jackchuka
jackchuka marked this pull request as ready for review November 11, 2026 04:50
@jackchuka
jackchuka merged commit 2c78a3b into main Nov 11, 2026
1 check passed
@jackchuka
jackchuka deleted the feat/list-items branch November 11, 2026 04:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant