A ratchet test fails on any new exported function without a JSDoc block and keeps the list of the 496 older ones only shrinking. Every Sass sheet must now start with its role header, not only the listed ones. The root, website, styles and tests AGENTS.md files say to document new declarations at once and to complete an undocumented one whenever it is modified. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
53 lines
2.5 KiB
JavaScript
53 lines
2.5 KiB
JavaScript
/**
|
|
* @file Repère les fonctions exportées sans bloc JSDoc au-dessus, pour le cliquet de tests/function-docs.test.mjs.
|
|
*
|
|
* Usage : `node tests/helpers/exported-functions.mjs --write` réécrit la liste des exceptions
|
|
* (tests/fixtures/undocumented-exports.json) d'après les sources. À lancer seulement pour la raccourcir après avoir
|
|
* documenté des fonctions, jamais pour y ajouter une fonction nouvelle.
|
|
* Attention : les composants React (nom en majuscule) ne sont pas comptés, l'en-tête de leur fichier les décrit déjà.
|
|
* Une directive `// eslint-…` peut séparer le bloc JSDoc de la fonction.
|
|
* @see website/AGENTS.md
|
|
*/
|
|
|
|
import { readdir, readFile, writeFile } from "node:fs/promises";
|
|
import { join } from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
|
|
const ROOTS = ["website/src", "services", "scripts"];
|
|
const ROOT_FILES = ["server.mjs"];
|
|
const SOURCE = /\.(js|jsx|mjs)$/;
|
|
const EXPORTED = /^export\s+(?:default\s+)?(?:async\s+)?(?:function\*?\s+(\w+)|const\s+(\w+)\s*=\s*(?:async\s+)?(?:\([^)]*\)|\w+)\s*=>|const\s+(\w+)\s*=\s*(?:async\s+)?function)/;
|
|
export const BASELINE_PATH = "tests/fixtures/undocumented-exports.json";
|
|
|
|
async function sourceFiles() {
|
|
const files = [...ROOT_FILES];
|
|
for (const root of ROOTS) {
|
|
const entries = await readdir(root, { recursive: true });
|
|
files.push(...entries.filter((entry) => SOURCE.test(entry) && !entry.includes("node_modules")).map((entry) => join(root, entry)));
|
|
}
|
|
return files.sort();
|
|
}
|
|
|
|
/** Fonctions exportées (hors composants React) sans bloc JSDoc au-dessus, sous la forme `chemin: nom`, triées. */
|
|
export async function undocumentedExports() {
|
|
const missing = [];
|
|
for (const file of await sourceFiles()) {
|
|
const lines = (await readFile(file, "utf8")).split("\n");
|
|
lines.forEach((line, index) => {
|
|
const match = line.match(EXPORTED);
|
|
if (!match) return;
|
|
const name = match.slice(1).find(Boolean);
|
|
if (/^[A-Z]/.test(name)) return;
|
|
let above = index - 1;
|
|
while (above >= 0 && lines[above].trimStart().startsWith("// eslint")) above -= 1;
|
|
if (!lines[above]?.trimEnd().endsWith("*/")) missing.push(`${file}: ${name}`);
|
|
});
|
|
}
|
|
return missing.sort();
|
|
}
|
|
|
|
if (process.argv[1] === fileURLToPath(import.meta.url) && process.argv.includes("--write")) {
|
|
const missing = await undocumentedExports();
|
|
await writeFile(BASELINE_PATH, `${JSON.stringify(missing, null, 2)}\n`);
|
|
console.log(`${missing.length} fonctions exportées sans JSDoc enregistrées dans ${BASELINE_PATH}`);
|
|
}
|