ci: syntax-check fenced code blocks on changed docs - #3267
Open
chaitanyas-maker wants to merge 1 commit into
Open
ci: syntax-check fenced code blocks on changed docs#3267chaitanyas-maker wants to merge 1 commit into
chaitanyas-maker wants to merge 1 commit into
Conversation
An audit of the SmartUI doc set found 118 code blocks that could not parse or
compile. Every one would have been caught on the commit that introduced it by
a check this simple.
Adds scripts/lint-code-blocks.js and a PR workflow that runs it over the docs
changed by that PR.
What it checks, using the real toolchains:
javascript node --check python ast.parse
ruby ruby -c bash bash -n
json JSON.parse yaml yaml.safe_load_all
plus two whole-file checks that caught real defects in the audit:
- unbalanced code fences (an unclosed block silently inverts every block
after it, so prose renders as code and code as prose)
- typographic quotes inside code blocks, which are a hard syntax error in
every language
Deliberately scoped to files changed by the PR. The repo has pre-existing debt
and a repo-wide gate would block every PR on unrelated pages; this stops new
breakage landing while the backlog is worked down. `--all` sweeps everything.
Care taken to avoid false positives, which would train reviewers to ignore it:
- block content is dedented before parsing, because Markdown nests blocks
inside lists and TabItems and every indented Python block would otherwise
look like an IndentationError
- deliberate partial snippets (bare object literals, `key: {` fragments,
elision markers) are skipped
- JSON samples carrying // comments are stripped before parsing, so the
house convention is tolerated while genuinely malformed JSON still fails
- languages with no runtime on the runner are skipped, not failed
Verified both directions: clean pages report zero, and the known-bad pages
still report their real defects.
Also fixes the defects this linter found immediately on already-audited pages,
which the earlier passes had missed:
- `npx smartui exec -P 5000 -- <command">` in 9 SDK pages (stray quote makes
it an unterminated shell string)
- 23 unbalanced `set`/`export`/`$env:` credential lines across 10 pages
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0197inyHsQ3V3CxPicLLvFJy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The documentation audit found 118 code blocks that could not parse or compile. Every one would have been caught on the commit that introduced it by a check this simple.
This adds
scripts/lint-code-blocks.jsand a PR workflow that runs it over the docs changed by that PR.What it checks
Using the real toolchains, not regexes:
javascriptnode --checkpythonast.parserubyruby -cbashbash -njsonJSON.parseyamlyaml.safe_load_allPlus two whole-file checks that both caught real defects in the audit:
smartui-cli-env-variables.mdright now, where sections 5–8 render backwards.‘ ’ “ ”are a hard syntax error in every language. Currently live in 12 Cypress snippets.Scoped to changed files, on purpose
The repo has pre-existing debt — a repo-wide gate would block every PR on unrelated pages. This stops new breakage landing while the backlog is worked down.
node scripts/lint-code-blocks.js --allsweeps everything when you want the full picture.False positives were the main design concern
A noisy linter trains reviewers to ignore it, so:
<TabItem>s, so content arrives uniformly indented. Without this, every indented Python block looks like anIndentationError— I hit exactly this trap during the audit and reported false defects because of it.'LT:Options': { ... },key: {fragments, and elision markers.//comments are stripped before parsing, so the house convention is tolerated while genuinely malformed JSON still fails.Verified in both directions: clean pages report zero problems, and the known-bad pages still report their real defects.
It found defects immediately
Running it against pages the audit had already been through surfaced residual issues the earlier passes missed, now fixed here:
npx smartui exec -P 5000 -- <command">in 9 SDK pages — the stray quote makes it an unterminated shell stringset/export/$env:credential lines across 10 pagesIt also swept the 25 pages the audit had never reached and found 28 more defects there, including
set LT_USERNAME=YOUR_USERNAME"on the k6 page and//used as a shell comment across the git-branching pages. Those are filed separately.Suggested follow-up
Once the open fix PRs land, consider flipping to
--allin a non-blocking scheduled job to track the remaining backlog.