Repository navigation
fix(validator): exempt fenced examples from the references/ link check - #517
Conversation
`validate-reference-links.js` scans every line of a SKILL.md, so a `references/…md` path shown inside a fenced code block is treated as a link to resolve. The rule this validator enforces therefore cannot be documented: its own failure message tells authors to write `../../references/<file>.md` rather than `references/<file>.md`, and a skill showing that contrast as an example fails the check that is explaining it. Reproduced on main by appending a fenced markdown example to using-agent-skills/SKILL.md — exit 1, with the guidance text printed underneath the very link it had just rejected. Lines inside a fence are now skipped. The scan is line-by-line rather than one regex over the document so the three CommonMark fence forms all hold: tilde fences, up to three spaces of indent, and a closing fence longer than its opener — and a ``` line inside a ~~~ block does not close it. Line numbers are preserved by collecting fenced line indices and skipping them during the scan, rather than stripping the text first, so the L<n> in an error still points at the real line. Deliberately local rather than shared with scripts/lib/skill-lint.js: that module's stripFencedCodeBlocks is the single regex with the gaps described in addyosmani#437, and addyosmani#444 is already rewriting it. Forking a rewrite in flight costs more than the duplication; once addyosmani#444 lands the two should collapse into one helper under scripts/lib/. Three tests added. All three fail against the current validator; the third pins that a genuinely broken link outside a fence is still reported, so the exemption cannot silently swallow real breakage.
addyosmani
left a comment
There was a problem hiding this comment.
Nice, and the reasoning in the comment is the right call. The ref-links check would otherwise flag a skill that documents the ../../references/ convention by showing references/... as the wrong example, which is a real false positive. Scanning fenced blocks line by line handles the tilde and mismatched-length fence forms, and keeping it local rather than sharing skill-lint's stripFencedCodeBlocks (which #437 flagged and #444 is rewriting) is the right sequencing; collapse them into one helper once #444 lands. Verified: validator, its test, and validate-skills all pass. Approving.
addyosmani
left a comment
There was a problem hiding this comment.
Nice, and the negative test (a broken link outside the fence still fails) is the part that makes this safe to take. Merging. One follow-up worth doing later, not a blocker: this fence scanner and the one in skill-lint should collapse into a single shared helper.
The bug
validate-reference-links.jsscans every line of aSKILL.md, so areferences/…mdpath shown inside a fenced code block is treated as a link to resolve. That makes this rule undocumentable: the validator's own failure message saysand a skill that shows that contrast as an example fails the check that is explaining it.
Reproduced on
mainby appending a fenced markdown example tousing-agent-skills/SKILL.md:— the guidance printed directly underneath the link it had just rejected for demonstrating it.
The fix
Lines inside a fence are skipped. The scan is line-by-line rather than one regex over the document, so the three CommonMark fence forms all hold: tilde fences, up to three spaces of indent, and a closing fence longer than its opener — and a ``` line inside a
~~~block does not close it.Line numbers are preserved by collecting fenced line indices and skipping them during the scan, rather than stripping the text first, so the
L<n>in a real error still points at the real line.On not touching
skill-lint.jsscripts/lib/skill-lint.jsalready has astripFencedCodeBlocks, and sharing one helper would be the better end state. I deliberately did not do that here: it is the single-regex version with the gaps described in #437, and #444 is already rewriting it. Forking a rewrite that is in flight costs more than the duplication, and it would put this PR into the same near-duplicate cluster CONTRIBUTING warns about.Flagging it explicitly so it is a decision rather than an oversight — once #444 lands, the correct follow-up is to collapse both into one helper under
scripts/lib/, and I am happy to send that.Tests
Three added to
scripts/validate-reference-links-test.js. All three fail against the current validator, verified by swapping the base file back in and confirming the swap took effect before running:The third is the important one — it pins that a genuinely broken link outside a fence is still reported, so the exemption cannot quietly swallow the breakage this validator exists to catch. (It fails on
maintoo, because there the fenced example is counted as a second error.)With the fix: 10/10, and all five validators pass —
validate-skills,validate-reference-links,validate-commands,validate-artifact-paths,validate-versions— plusrun-evals-test.jsandrun-evals.js --min-rank1 80(86%, 67/78).Screening
No open PR touches
validate-reference-links.js. #437 and #444 concernskill-lint.js's stripper, and #387's heuristic list is about section checks and cross-reference patterns in the same file — a different validator and a different rule from this one.