Skip to content

Commit d315978

Browse files
jedudenclaude
andauthored
Enforce terminal Meta-Information and sync bullets from frontmatter (plan 169) (#315)
* Enforce terminal Meta-Information and sync bullets from frontmatter (plan 169) - Drop trailing ## ... wildcard from internal/rules/proto.md so any section after ## Meta-Information fails mdsmith check - Replace hand-kept CATEGORY literal with {category} placeholder in proto.md Meta-Information body - Implement fixBodySyncIn in MDS020 Fix path: rewrites body lines whose {field} template matches but value disagrees with front matter - Move ## See also sections before ## Meta-Information in ten rule READMEs that had content after the terminal section - Update docs/guides/schemas.md and docs/reference/section-schema.md to document wired frontmatter-body {field} sync https://claude.ai/code/session_0185djJjm6owY8d9JCwsEJas * Address PR #315 review comments - resolveBodySyncLine: continue (not break) on correct lines so stale duplicates later in the range are still patched - docs/guides/schemas.md, docs/reference/section-schema.md: qualify Fix body-sync as single file-source only; composed schemas skip it - internal/rules/proto.md: update guidance comment — Concept bullet is optional, not a template placeholder to delete - Add 6 unit tests covering edge cases: no front matter, non-body sync point, missing field, no matching line, multi-source skip, correct-then-stale duplicate scan https://claude.ai/code/session_0185djJjm6owY8d9JCwsEJas * Fix patch coverage: remove dead branches, add 4 more unit tests - buildFieldPattern: use MustCompile (pattern from QuoteMeta+.+ is always valid, error branch was dead code) - resolveBodySyncLine: remove re == nil guard (MustCompile never panics with this input) - Add TestFix_BodySync_WildcardBeforeSection, _RequiredHeadingAbsent, _HeadingFollowedByAnother, TestResolveBodySyncLine_NilPath to reach fixBodySyncIn/resolveBodySyncLine branches now at 100% coverage https://claude.ai/code/session_0185djJjm6owY8d9JCwsEJas --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 4c8041c commit d315978

17 files changed

Lines changed: 382 additions & 96 deletions

File tree

PLAN.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ footer: |
9595
| 166 | 🔲 | opus | [Schema-driven data extraction (mdsmith extract)](plan/166_schema-driven-data-extraction.md) |
9696
| 167 | 🔲 | opus | [Custom binding overrides for mdsmith extract](plan/167_custom-binding-overrides.md) |
9797
| 168 | 🔲 | sonnet | [Obsidian Flavored Markdown support](plan/168_obsidian-markdown-support.md) |
98-
| 169 | 🔲 | opus | [Enforce terminal Meta-Information and render it from frontmatter](plan/169_rule-readme-meta-information-sync.md) |
98+
| 169 | | opus | [Enforce terminal Meta-Information and render it from frontmatter](plan/169_rule-readme-meta-information-sync.md) |
9999
| 170 || opus | [Audit link handling across mdsmith and the website](plan/170_link-handling-audit.md) |
100100
| 171 | 🔲 | opus | [MDS027 link-integrity hardening](plan/171_mds027-link-integrity-hardening.md) |
101101
| 172 | 🔲 | opus | [Link-style rule and shared links config](plan/172_link-style-rule-and-config.md) |

docs/guides/schemas.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,18 +408,26 @@ title placeholder. `## ...` rows mark wildcard slots.
408408
Front-matter keys map directly to CUE expressions.
409409
`<?require?>` declares the filename pattern.
410410

411-
MDS020's file-schema check still routes through
412-
its legacy parser today: `{field}` in a proto.md
413-
heading row matches a non-empty run rather than
414-
resolving the document's frontmatter value via
415-
`fmvar(...)`. The schema package parses proto.md
416-
into the new Matcher shape (used by tests), and a
417-
follow-up plan will wire MDS020 through that
418-
parser. Until then, treat `{field}` in proto.md
419-
heading rows as a wildcard placeholder, not as a
420-
frontmatter substitution. The
411+
MDS020's file-schema check routes through its
412+
legacy parser: `{field}` in a proto.md heading row
413+
matches a non-empty run rather than resolving the
414+
document's frontmatter value via `fmvar(...)`.
415+
Heading rows are wildcards, not substitutions.
416+
417+
`{field}` in a proto.md **body** is fully wired:
418+
MDS020 resolves the placeholder against the
419+
document's front matter and flags any mismatch.
420+
`mdsmith fix` rewrites stale body lines to the
421+
current front-matter value for files that match a
422+
**single file-based schema source**. Composed or
423+
multi-source schemas do not get Fix body rewrites.
424+
The rule-readme `Meta-Information` body uses this
425+
to keep `ID`, `Name`, `Status`, and `Category`
426+
bullets in sync with front matter.
427+
428+
The
421429
[section-schema reference](../reference/section-schema.md#protomd-file-syntax)
422-
records the eventual mapping.
430+
records the heading-row wildcard mapping.
423431

424432
## Choosing a source
425433

docs/reference/section-schema.md

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,16 @@ schema:
255255

256256
## `proto.md` file syntax
257257

258-
> **Migration status.** MDS020's file-schema
259-
> check still uses the legacy `parseSchema`
260-
> pipeline today: `## ?` and `## ...` already
261-
> behave as wildcards, and `{field}` in a
262-
> heading row matches a non-empty run rather
263-
> than resolving the frontmatter value via
264-
> `fmvar(...)`. The mapping below is what the
265-
> schema package parses. Tests exercise it so a
266-
> follow-up cutover plan can wire MDS020
267-
> through without docs churn. Until then,
268-
> proto.md authors should treat `{field}` as a
269-
> wildcard, not a frontmatter substitution.
258+
> **Heading rows vs body lines.** In heading
259+
> rows, `{field}` is a wildcard — not resolved
260+
> against front matter. The table below shows
261+
> the equivalent inline entry for each row.
262+
>
263+
> In **body lines**, `{field}` is fully wired:
264+
> MDS020 checks each placeholder against front
265+
> matter and `mdsmith fix` rewrites stale lines
266+
> for a **single file-based schema source**.
267+
> Composed schemas skip the Fix body rewrite.
270268

271269
Proto.md files use a literal-template surface
272270
distinct from the inline `regex:` form. Heading

internal/rules/MDS003-heading-increment/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ Body text.
6969

7070
<?/include?>
7171

72+
## See also
73+
74+
- [Placeholder grammar](../../../docs/background/concepts/placeholder-grammar.md)
75+
7276
## Meta-Information
7377

7478
- **ID**: MDS003
@@ -79,7 +83,3 @@ Body text.
7983
- **Implementation**:
8084
[source](./)
8185
- **Category**: heading
82-
83-
## See also
84-
85-
- [Placeholder grammar](../../../docs/background/concepts/placeholder-grammar.md)

internal/rules/MDS004-first-line-heading/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ Some content here.
102102
| `first line should be a level {level} heading, found blank line` | First child is a heading but preceded by blank line |
103103
| `first heading should be level {level}, got {n}` | First heading on line 1 has the wrong level |
104104

105+
## See also
106+
107+
- [Placeholder grammar](../../../docs/background/concepts/placeholder-grammar.md)
108+
105109
## Meta-Information
106110

107111
- **ID**: MDS004
@@ -112,7 +116,3 @@ Some content here.
112116
- **Implementation**:
113117
[source](./)
114118
- **Category**: heading
115-
116-
## See also
117-
118-
- [Placeholder grammar](../../../docs/background/concepts/placeholder-grammar.md)

internal/rules/MDS018-no-emphasis-as-heading/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ This is a normal paragraph.
6767

6868
<?/include?>
6969

70+
## See also
71+
72+
- [Placeholder grammar](../../../docs/background/concepts/placeholder-grammar.md)
73+
7074
## Meta-Information
7175

7276
- **ID**: MDS018
@@ -77,7 +81,3 @@ This is a normal paragraph.
7781
- **Implementation**:
7882
[source](./)
7983
- **Category**: heading
80-
81-
## See also
82-
83-
- [Placeholder grammar](../../../docs/background/concepts/placeholder-grammar.md)

internal/rules/MDS020-required-structure/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,11 @@ Hints fire on string disjunctions (Levenshtein ≤ 2 of a valid
343343
literal) and integer ranges (nearest bound when just outside).
344344
Other shapes get no hint.
345345

346+
## See also
347+
348+
- [Placeholder grammar](../../../docs/background/concepts/placeholder-grammar.md)
349+
- [Schema field types](../../../docs/reference/schema-types.md)
350+
346351
## Meta-Information
347352

348353
- **ID**: MDS020
@@ -354,8 +359,3 @@ Other shapes get no hint.
354359
- **Guide**:
355360
[directive guide](../../../docs/guides/directives/enforcing-structure.md)
356361
- **Category**: structural
357-
358-
## See also
359-
360-
- [Placeholder grammar](../../../docs/background/concepts/placeholder-grammar.md)
361-
- [Schema field types](../../../docs/reference/schema-types.md)

internal/rules/MDS023-paragraph-readability/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ The implementation of concurrent distributed systems requires sophisticated unde
8383

8484
<?/include?>
8585

86+
## See also
87+
88+
- [Placeholder grammar](../../../docs/background/concepts/placeholder-grammar.md)
89+
8690
## Meta-Information
8791

8892
- **ID**: MDS023
@@ -93,7 +97,3 @@ The implementation of concurrent distributed systems requires sophisticated unde
9397
- **Implementation**:
9498
[source](./)
9599
- **Category**: prose
96-
97-
## See also
98-
99-
- [Placeholder grammar](../../../docs/background/concepts/placeholder-grammar.md)

internal/rules/MDS024-paragraph-structure/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ Dogs bark. Cats meow. Birds sing. Fish swim. Frogs croak. Snakes hiss. Bees buzz
7979
| too many sentences | `paragraph has too many sentences (8 > 6)` |
8080
| sentence too long | `sentence too long (45 > 40 words)` |
8181

82+
## See also
83+
84+
- [Placeholder grammar](../../../docs/background/concepts/placeholder-grammar.md)
85+
8286
## Meta-Information
8387

8488
- **ID**: MDS024
@@ -89,7 +93,3 @@ Dogs bark. Cats meow. Birds sing. Fish swim. Frogs croak. Snakes hiss. Bees buzz
8993
- **Implementation**:
9094
[source](./)
9195
- **Category**: prose
92-
93-
## See also
94-
95-
- [Placeholder grammar](../../../docs/background/concepts/placeholder-grammar.md)

internal/rules/MDS027-cross-file-reference-integrity/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,10 @@ See [guide](bad/ref/guide.md#missing-section).
122122
| missing file | broken link target "x.md" not found |
123123
| missing heading | broken link target "x.md#section" has no matching heading anchor |
124124

125+
## See also
126+
127+
- [Placeholder grammar](../../../docs/background/concepts/placeholder-grammar.md)
128+
125129
## Meta-Information
126130

127131
- **ID**: MDS027
@@ -132,7 +136,3 @@ See [guide](bad/ref/guide.md#missing-section).
132136
- **Implementation**:
133137
[source](./)
134138
- **Category**: link
135-
136-
## See also
137-
138-
- [Placeholder grammar](../../../docs/background/concepts/placeholder-grammar.md)

0 commit comments

Comments
 (0)