Skip to content

Commit d04f120

Browse files
TMHSDigitalclaude
andcommitted
Reject CR line endings in validate and document the LF policy
Adds checkLineEndings (V30) with fixtures, wires it into the entry loop and the markdown-roots loop, lists the normalisation commit in .git-blame-ignore-revs and adds one line to CONTRIBUTING. Closes #140 Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
1 parent 16effe0 commit d04f120

5 files changed

Lines changed: 30 additions & 3 deletions

File tree

‎.git-blame-ignore-revs‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Commits to skip in git blame (git config blame.ignoreRevsFile .git-blame-ignore-revs)
2+
# Normalise line endings to LF
3+
16effe09e64282a9ee679048df8c3a51a7fd593d

‎CONTRIBUTING.md‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ The website rebuilds from frontmatter on deploy. Node 22 or newer is all you nee
3636
4. Add a row to the matching category `README.md`. This is required: the validator fails an entry that is not listed there, and the row's licence cell must match your frontmatter.
3737
5. Run `node site/sync-counts.mjs` (`npm run counts`). It updates every place the repo restates the entry count: both category count tables, the README badge and "Browse N sources" line, and `expectedEntryCount` in [`site/config.json`](site/config.json).
3838
6. Run `npm test && npm run validate` before you push; that is quick. CI then runs `npm run check` (the tests, `node site/validate.mjs` and `node site/build.mjs`), and all of it must pass. Run `npm run check` yourself if you changed the site or want to preview your entry's page. The build renders your entry's page and fails if the body uses markdown the site does not support (tables, code fences, blockquotes, images, raw HTML, `###` headings, numbered lists) or links to a file that does not exist.
39-
7. Optional: add the `id` to `site/config.json` → `featured` to pin it under Safe starting points.
39+
7. Save files with LF line endings. `.editorconfig` and `.gitattributes` take care of it in most editors; the validator rejects a file that still contains a CR.
40+
8. Optional: add the `id` to `site/config.json` → `featured` to pin it under Safe starting points.
4041

4142
To add a starter stack (one pick per need for a kind of game), follow [`stacks/README.md`](stacks/README.md).
4243

‎site/checks.mjs‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,3 +826,15 @@ export function checkThumbManifest(manifest, entriesById, files) {
826826
}
827827
return errors;
828828
}
829+
830+
/**
831+
* V30: text files are LF-only. `.gitattributes` normalises what git stores,
832+
* but a file saved with CRLF on a machine without the attribute would reach
833+
* CI through a fork, so the policy is checked rather than assumed.
834+
*/
835+
export function checkLineEndings(rel, text) {
836+
const at = text.indexOf("\r");
837+
if (at === -1) return [];
838+
const line = text.slice(0, at).split("\n").length;
839+
return [`${rel}:${line} has a CR line ending (save the file with LF; .editorconfig and .gitattributes set this)`];
840+
}

‎site/checks.test.mjs‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
evidenceDates,
2626
markdownAnchors,
2727
checkLicenseVocabulary,
28+
checkLineEndings,
2829
checkMaintenance,
2930
maintenanceFromRepo,
3031
checkPublisherConsistency,
@@ -793,10 +794,15 @@ accepts("preview field: https url", checkPreviewField("ok.md", { preview: "https
793794
rejects("preview field: http refused", checkPreviewField("bad.md", { preview: "http://a/b.png" }), 'bad.md preview must be "none" or an https:// image URL');
794795
rejects("preview field: word refused", checkPreviewField("bad.md", { preview: "yes" }), 'bad.md preview must be "none" or an https:// image URL');
795796

797+
/* V30: line endings ------------------------------------------------------ */
798+
accepts("V30 accepts LF-only text", checkLineEndings("ok.md", "---\nid: a\n---\n\nBody\n"));
799+
rejects("V30 rejects CRLF and names the first line", checkLineEndings("bad.md", "---\nid: a\r\n---\n"), "bad.md:2 has a CR line ending");
800+
rejects("V30 rejects a lone CR", checkLineEndings("bad.md", "one\rtwo\n"), "bad.md:1 has a CR line ending");
801+
796802
/* ----------------------------------------------------------------------- */
797803
if (failures.length) {
798804
console.error(`checks.test failed (${failures.length}):`);
799805
for (const f of failures) console.error(` - ${f}`);
800806
process.exit(1);
801807
}
802-
console.log(`checks.test ok: ${passed} assertions across 27 checks`);
808+
console.log(`checks.test ok: ${passed} assertions across 28 checks`);

‎site/validate.mjs‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
checkFieldTypes,
2222
checkFormatVocabulary,
2323
checkLicenseVocabulary,
24+
checkLineEndings,
2425
checkMaintenance,
2526
checkPublisherConsistency,
2627
checkSpdxConsistency,
@@ -266,6 +267,7 @@ function main() {
266267
const rel = relFromRoot(file);
267268
const text = fs.readFileSync(file, "utf8");
268269
if (hasEmoji(text)) errors.push(`${rel} contains emoji`);
270+
errors.push(...checkLineEndings(rel, text));
269271
const ctl = text.split("\n").findIndex((line) => CONTROL_RE.test(line));
270272
if (ctl !== -1) errors.push(`${rel}:${ctl + 1} contains a control character (delete it; only tab and newlines are allowed)`);
271273

@@ -433,7 +435,10 @@ function main() {
433435
const files = fs.statSync(root).isDirectory()
434436
? walkFiles(root, [], (f) => f.endsWith(".md"))
435437
: [root];
436-
for (const file of files) checkRelativeLinks(file, errors);
438+
for (const file of files) {
439+
errors.push(...checkLineEndings(relFromRoot(file), fs.readFileSync(file, "utf8")));
440+
checkRelativeLinks(file, errors);
441+
}
437442
}
438443

439444
// Thumbnails: the manifest, the files and the licence gate must agree.

0 commit comments

Comments
 (0)