From 9f0feccc35f40392d828fdaa1bd739e493487478 Mon Sep 17 00:00:00 2001 From: "coderabbitai[bot]" <136622811+coderabbitai[bot]@users.noreply.github.com> Date: Mon, 18 May 2026 12:37:32 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=9D=20Add=20docstrings=20to=20`feat/re?= =?UTF-8?q?move-turnstile-and-fixes`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Docstrings generation was requested by @Silentely. The following files were modified: * `scripts/pre-commit-check.js` These file types are not supported: * `CLAUDE.md` * `netlify.toml` * `netlify/edge-functions/CLAUDE.md` * `netlify/functions/CLAUDE.md` * `src/giffgaff/giffgaff_modular.html` * `src/simyo/simyo_modular.html` --- scripts/pre-commit-check.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/scripts/pre-commit-check.js b/scripts/pre-commit-check.js index f56aefd..0dd4cdc 100644 --- a/scripts/pre-commit-check.js +++ b/scripts/pre-commit-check.js @@ -56,6 +56,10 @@ function getStagedFiles() { return output.split('\0').filter(Boolean); } +/** + * Get the list of protected file paths that currently have staged changes. + * @returns {string[]} Array of relative paths for protected files that are staged; empty if none. + */ function getTouchedProtectedFiles() { const output = git([ 'diff', @@ -68,6 +72,11 @@ function getTouchedProtectedFiles() { return output.split('\0').filter(Boolean); } +/** + * Determine whether a file should be normalized (text formatting enforced) based on its path. + * @param {string} relPath - File path relative to the repository root. + * @returns {boolean} `true` if the file extension is in TEXT_EXTENSIONS or the basename is `.gitignore` or `.gitattributes`, `false` otherwise. + */ function shouldFormat(relPath) { const ext = path.extname(relPath).toLowerCase(); if (TEXT_EXTENSIONS.has(ext)) { @@ -177,6 +186,19 @@ function runChecks(stagedFiles) { return failures; } +/** + * Run pre-commit validation and normalization for staged files, aborting the commit on violations. + * + * Checks for changes to protected files and exits with status 1 if any are touched. If there are no + * staged files, exits with status 0. For staged text files, normalizes line endings, trims trailing + * whitespace, ensures a trailing newline, writes changes back to the working tree and re-stages them. + * Then validates staged JavaScript and JSON files for smart-quote characters and syntax errors; + * any validation failures are printed and cause an exit with status 1. On success, prints a pass message. + * + * Exit codes: + * - 0: no staged files (early exit) or checks passed + * - 1: protected file touched or one or more validation failures + */ function main() { const touchedProtectedFiles = PROTECTED_FILES.length > 0 ? getTouchedProtectedFiles() : []; if (touchedProtectedFiles.length > 0) {