Skip to content

Commit 08665c7

Browse files
committed
plan 88: conform error style, handle [TOC] link-ref ambiguity
Address Copilot review: - Error message: drop trailing period and capital leading 'For', matching the mdsmith CLAUDE.md convention (lowercase, no trailing punctuation). New message keeps both pointers — the missing heading-TOC generator and MDS019 for file indexes. - Detection: `[TOC]` is a valid CommonMark shortcut reference link. The earlier design would false-positive when a matching `[TOC]: <url>` definition is present. Add an explicit link-reference map lookup (case-insensitive label) before emitting the diagnostic for this pattern; the other three patterns keep their simple regex match. - Tasks: add a step for the link-reference suppression and a good fixture exercising it.
1 parent c878ad9 commit 08665c7

1 file changed

Lines changed: 40 additions & 7 deletions

File tree

plan/88_toc-directive-migration.md

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,30 @@ per-variant walkers; raw-line regex is simpler
105105
and avoids false positives by restricting the
106106
match to paragraph-only regions.
107107

108+
#### Link reference exception for `[TOC]`
109+
110+
`[TOC]` is syntactically a valid CommonMark
111+
shortcut reference link. If the document
112+
contains a matching link reference definition
113+
(`[TOC]: <url>`), `[TOC]` resolves to a
114+
legitimate link and must not be flagged.
115+
116+
Before emitting a diagnostic for the `[TOC]`
117+
pattern, consult the goldmark parser context's
118+
link reference map for a definition with the
119+
label `TOC` (case-insensitive, per the
120+
[CommonMark matching rules][cm-refs]). If one
121+
exists, suppress the diagnostic.
122+
123+
[cm-refs]: https://spec.commonmark.org/0.31.2/#matches
124+
125+
The other three patterns do not have this
126+
ambiguity: `[[_TOC_]]`, `[[toc]]`, and `${toc}`
127+
do not form valid link references in CommonMark
128+
and always render as literal text in a
129+
paragraph. No exception handling is needed for
130+
them.
131+
108132
### Configuration
109133

110134
Rule `toc-directive`, category `meta`, disabled
@@ -114,10 +138,12 @@ opt-in posture. No settings.
114138
### Error message
115139

116140
```text
117-
[TOC] does not render on CommonMark or goldmark; mdsmith has no heading-TOC generator. For file-index use cases, see <?catalog?> (MDS019).
141+
[TOC] does not render on CommonMark or goldmark; mdsmith has no heading TOC equivalent; use <?catalog?> for file indexes (MDS019)
118142
```
119143

120-
Severity: `warning`.
144+
Severity: `warning`. Lowercase start, no trailing
145+
punctuation — consistent with the mdsmith error
146+
message convention in [CLAUDE.md](../CLAUDE.md).
121147

122148
### No auto-fix
123149

@@ -133,12 +159,19 @@ alone.
133159
with `rule.go`, `README.md`
134160
2. Implement paragraph-scoped line scanning for
135161
the four directive patterns
136-
3. Implement `rule.Defaultable` with
162+
3. For the `[TOC]` pattern, consult the goldmark
163+
parser context's link reference definition
164+
map; suppress the diagnostic when a label
165+
`TOC` (case-insensitive) is defined
166+
4. Implement `rule.Defaultable` with
137167
`EnabledByDefault` returning `false`
138-
4. Register as MDS035 in category `meta`
139-
5. Add good/bad fixtures with front-matter
140-
specifying the expected diagnostics
141-
6. Document the rule in the flavor comparison
168+
5. Register as MDS035 in category `meta`
169+
6. Add good/bad fixtures with front-matter
170+
specifying the expected diagnostics, including
171+
a good fixture that has `[TOC]: https://x` as
172+
a reference definition alongside a `[TOC]`
173+
line
174+
7. Document the rule in the flavor comparison
142175
table in
143176
[docs/background/markdown-linters.md](../docs/background/markdown-linters.md)
144177

0 commit comments

Comments
 (0)