docs: prevent em dashes in public copy (#2516)
This commit is contained in:
@@ -2,6 +2,7 @@ import { createHash } from "node:crypto";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath, pathToFileURL } from "node:url";
|
||||
import { scanPublicDocsEmDashViolations } from "../apps/web/scripts/check-no-em-dash-ui.mjs";
|
||||
|
||||
const repoRoot = path.resolve(
|
||||
path.dirname(fileURLToPath(import.meta.url)),
|
||||
@@ -17,6 +18,19 @@ const defaultDocsDir = path.join(repoRoot, "docs/public");
|
||||
* @returns {Promise<{pageCount: number}>} Number of validated published pages.
|
||||
*/
|
||||
export async function validatePublicDocs(docsDir = defaultDocsDir) {
|
||||
const emDashViolations = scanPublicDocsEmDashViolations({
|
||||
docsRoot: docsDir,
|
||||
root: docsDir,
|
||||
});
|
||||
if (emDashViolations.length > 0) {
|
||||
const locations = emDashViolations.map(
|
||||
({ file, line }) => `${file}:${line}`,
|
||||
);
|
||||
throw new Error(
|
||||
`public docs contain em dash (U+2014): ${locations.join(", ")}`,
|
||||
);
|
||||
}
|
||||
|
||||
const meta = await readMeta(docsDir);
|
||||
const files = await collectMarkdownFiles(docsDir);
|
||||
const pagesBySlug = new Map();
|
||||
|
||||
@@ -214,6 +214,18 @@ test("accepts explicitly ordered pages with required frontmatter", async () => {
|
||||
await assert.doesNotReject(validatePublicDocs(dir));
|
||||
});
|
||||
|
||||
test("rejects public pages that contain an em dash", async () => {
|
||||
const dir = await createDocs(
|
||||
{ "index.md": validPage.replace("Page body.", "Public — copy.") },
|
||||
{ pages: ["index"] },
|
||||
);
|
||||
|
||||
await assert.rejects(
|
||||
validatePublicDocs(dir),
|
||||
/public docs contain em dash \(U\+2014\): index\.md:8/,
|
||||
);
|
||||
});
|
||||
|
||||
test("rejects published pages omitted from meta.json", async () => {
|
||||
const dir = await createDocs(
|
||||
{ "index.md": validPage, "cli.md": validPage },
|
||||
|
||||
Reference in New Issue
Block a user