Repository navigation
fix(validator): strip every CommonMark fence form from linted prose (#437) - #568
Conversation
…ddyosmani#437) stripFencedCodeBlocks matched fences with a single whole-document regex that only recognised a column-zero backtick fence closed by a run of exactly the same length. Three CommonMark-legal forms slipped through and their contents were linted as prose: tilde fences, fences indented one to three spaces, and closing fences longer than their opener. This is live on main today — spec-driven-development's list-nested examples use indented fences, so the linter has been reading their contents as skill text. Replace the regex with a line scanner that tracks the opener's marker and length, closes only on a same-marker run at least as long, treats an unterminated fence as running to end of file (so sections after it fail loud), and follows the CommonMark rule that a backtick fence's info string may not contain backticks. Stripped lines become empty lines so positions are preserved. Add unit coverage for each form plus CRLF input, and run scripts/lib/skill-lint-test.js in CI — it was the only test file the workflow did not execute. Revives the approach from addyosmani#444 by @ujjwalks, which was approved and then closed after a rebase conflict. Closes addyosmani#437
|
Verified rather than read, and it holds up on the boundaries the description doesn't mention. 27 pass on the head. Reverting only Every one of them red before, green after. That's the shape that makes a stripper fix reviewable. The boundary I went looking for, and you'd already handled
Four spaces is an indented code block in CommonMark, not a fence, so keeping it is correct — and it's the case where an over-eager The info-string rule at // CommonMark: the info string of a backtick fence may not contain backticks,
// so a line like ````js``` is inline code` is prose, not an opener.That's a genuine spec detail, it's cited, and it prevents a line of prose containing inline code from opening a fence that then eats the rest of the document. On the test designObserving stripping through the required-section rule rather than asserting on LGTM. |
abhisheksharma2411
left a comment
There was a problem hiding this comment.
The line scanner is the right shape, and the details that are easy to miss are already handled: closing only on the same marker at least as long as the opener, the info-string rule that a backtick fence's info may not contain backticks, unterminated fences running to EOF, and blanking lines rather than deleting them so positions stay valid. I probed it 18 ways in both directions and couldn't break it.
Nothing leaks — heading hidden inside the fence, checked via the required-section rule:
backtick basic · tilde · 3-space indent · longer closer · tilde info with
backticks · unterminated · closer with trailing spaces · marker mismatch · CRLF
-> all stripped
And nothing is over-stripped — heading outside the fence must survive:
after a closed backtick/tilde/indented/longer-closer fence · prose with inline
```code``` · a ```js``` line · tilde closer for a backtick opener · 3-tick line
inside a 4-tick block
-> all survived
One thing worth adding to the PR description, because it's stronger than what's written there. "Their contents were linted as prose" undersells it — the failure direction is a false negative in a gate. A skill genuinely missing a required section passes validation if its example text happens to contain that heading:
main this PR
tilde fence NO YES <- "missing ## Red Flags" reported?
longer closer NO YES
backtick (control) YES YES
On main the example silences the check. That's the argument for landing this.
One precision note on the spec-driven-development evidence. The three-space fences at L89–104 are real and are being mis-stripped, but the consequence there is currently latent, not live: the content inside those fences is itself indented, so it never matches the column-zero heading rule. node scripts/validate-skills.js gives 25 skills checked — 0 error(s), 0 warning(s) on both main and this branch. The bug bites when fenced content sits at column zero inside a tilde or longer-closer fence, which is what the table above uses. Worth saying "latent on main today, and here is the shape that makes it bite" rather than "live" — it's a fix that prevents a false negative, and that's a good enough reason on its own.
Disclosure on the workflow step: your Test skill lint rules step is the same three lines I added in #577 (mine says Test skill validator rules). Yours is the earlier PR, so it should keep it — I'll rebase mine onto this and drop the duplicate rather than leave @addyosmani with a conflict. Entirely my miss for not checking open PRs by the files they touch before opening mine.
addyosmani#568 adds the identical three lines (its step is named "Test skill lint rules"). That PR is older and its own new tests need the step just as much, so it should carry it; keeping a duplicate here only hands the maintainer a conflict on the same hunk. Leaves this PR to the thing that is actually its own: the Context Efficiency line-budget check. Note the consequence — until addyosmani#568 lands, the tests added here do not run in CI.
addyosmani#568 adds the identical `node --test scripts/lib/skill-lint-test.js` step at the same anchor, and is the older PR. Three PRs carrying the same three lines only hands the maintainer a conflict on one hunk. Leaves this PR to the skill-anatomy rules themselves. Consequence worth naming: until addyosmani#568 lands, the tests added here do not run in CI.
addyosmani
left a comment
There was a problem hiding this comment.
This is the right fix for #437: a proper CommonMark scanner instead of the single regex, and it also wires skill-lint-test.js into CI, which wasn't running before. Passes clean on all 25 skills. Merging.
Summary
Fixes #437.
stripFencedCodeBlocksinscripts/lib/skill-lint.jsmatched fences with one whole-document regex that only recognised a column-zero backtick fence closed by a run of exactly the same length. Three CommonMark-legal forms slipped through, so their contents were linted as prose:~~~)This is live on
main, not hypothetical:skills/spec-driven-development/SKILL.mdnests its Commands and Project Structure examples inside list items with three-space-indented fences (lines 89–104). The old stripper leaves all three example blocks in the prose the required-section and cross-reference rules read; the new one leaves none.Change
```js``` is inline codeis not mistaken for an opener.scripts/lib/skill-lint-test.jsin CI. It was the only*-test.jsfile the workflow did not execute, so the existing linter tests have never gated a merge.Verification
Credit
This revives the approach from #444 by @ujjwalks, which was approved and then closed after a rebase conflict with #505. The scanner here is the same shape; the additions are the info-string rule, line-number preservation, and the extra edge-case tests.