Auto-sanitize + gate translation quote artifacts#355
Merged
Conversation
Auto-translation periodically emits nested unescaped double-quotes that break the deploy: inside JSX string attributes (caught by check-mdx-parse) and inside double-quoted YAML frontmatter scalars (previously only caught by the slow Astro build). Both recur whenever a source article changes and is re-translated, so a one-off locale fix never sticks. - lint-mdx.mjs: new fixable `nested-quote` rule. Converts raw inner " to ' in JSX attributes and frontmatter scalars, with fix-then-verify (only writes when the result parses; otherwise leaves it for the strict gate). Runs as auto-fix in the translate apply job and as a strict deploy gate for free. Code-fence-aware; never touches valid content. - check-mdx-parse.mjs: validate frontmatter YAML (the gap that let bad-YAML translations reach the build), reporting file:line at the fast gate. - Both scripts refactored behind a run-directly guard so their logic is importable; add node:test unit tests (14 cases).
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.
Summary
Auto-translation periodically emits nested unescaped double-quotes that break the production deploy. This happened three times in quick succession on
mainand recurs whenever a translated source article changes, because the translator wraps UI terms in"even when the English source uses single quotes (or none). A one-off locale fix never sticks.Two failure classes, two pipeline stages:
alt="配置了"打开 URL"操作"→ MDX parse error (caught today bycheck-mdx-parse).description: "…"显示所有方案"…"→ frontmatter YAML error (previously only caught by the slow Astro build).Changes
scripts/lint-mdx.mjs— new fixablenested-quoterule. Converts raw inner"→'in JSX attributes and frontmatter scalars, with fix-then-verify: it only writes the repair if the result parses cleanly; otherwise it leaves the file and reports it so the strict gate blocks it. Code-fence-aware; recognizes valued/boolean attributes,{…}expressions, and tag close so it never touches valid content. Auto-repairs in the translateapplyjob (which already runslint-mdx --fix) and acts as a strict deploy gate for free.scripts/check-mdx-parse.mjs— validates frontmatter YAML (the gap that let bad-YAML translations reach the build), reportingfile:lineat the fast pre-build gate.node:testunit tests.No workflow files changed — the existing wiring (
lint-mdx --fixin translate, strictlint-mdx+check-mdx-parseat deploy) picks both up automatically.Test Plan
node --test 'scripts/__tests__/*.test.mjs'→ 14/14 pass (frontmatter fixer, JSX fixer incl. boolean-attr/code-fence cases, combiner,parsesCleanfix-then-verify, frontmatter validator)node scripts/lint-mdx.mjs→all files OK(zero false positives across the full tree)node scripts/lint-mdx.mjs --fix→ no modifications on the clean treenode scripts/check-mdx-parse.mjs→ 3378 files parsed cleanlylint-mdxdetects +--fixrepairs the JSX one;check-mdx-parseflags the frontmatter one with correctfile:line🤖 Generated with Claude Code