mirror of
https://github.com/cloudflare/cloudflare-docs.git
synced 2026-01-11 20:06:58 +00:00
* [Docs Site] Adopt eslint * Demonstrate a fixable suggestion, add VSCode plugin and package.json script * Fix slice in ModelCatalog * Remove test error in AnchorHeading * recreate package-lock.json * update new .jsx components to .tsx * amend deps, fix react types, organise ec plugins * another attempt at fixing platform-specific deps * fix FieldCatalog filters, remove test block from code.mdx * use opacity instead of brightness for ruleid * fix lockfile * amend ruleid opacity styling * test onetrust * enable prefer const rule, remove onetrust test * add save-dev
57 lines
1.4 KiB
TypeScript
57 lines
1.4 KiB
TypeScript
import { readFile } from "fs/promises";
|
|
|
|
async function main() {
|
|
const redirects = await readFile("public/_redirects", { encoding: "utf-8" });
|
|
|
|
let numInfiniteRedirects = 0;
|
|
let numUrlsWithFragment = 0;
|
|
let numDuplicateRedirects = 0;
|
|
|
|
const redirectSourceUrls: string[] = [];
|
|
|
|
for (const line of redirects.split("\n")) {
|
|
if (line.startsWith("#") || line.trim() === "") continue;
|
|
|
|
const [from, to] = line.split(" ");
|
|
|
|
if (from === to) {
|
|
console.log(`✘ Found infinite redirect:\n ${from} -> ${to}`);
|
|
numInfiniteRedirects++;
|
|
}
|
|
|
|
if (from.includes("#")) {
|
|
console.log(`✘ Found source URL with fragment:\n ${from}`);
|
|
numUrlsWithFragment++;
|
|
}
|
|
|
|
if (redirectSourceUrls.includes(from)) {
|
|
console.log(`✘ Found repeated source URL:\n ${from}`);
|
|
numDuplicateRedirects++;
|
|
} else {
|
|
redirectSourceUrls.push(from);
|
|
}
|
|
}
|
|
|
|
if (numInfiniteRedirects || numUrlsWithFragment || numDuplicateRedirects) {
|
|
console.log("\nDetected errors:");
|
|
|
|
if (numInfiniteRedirects > 0) {
|
|
console.log(`- ${numInfiniteRedirects} infinite redirect(s)`);
|
|
}
|
|
|
|
if (numUrlsWithFragment > 0) {
|
|
console.log(`- ${numUrlsWithFragment} source URL(s) with a fragment`);
|
|
}
|
|
|
|
if (numDuplicateRedirects > 0) {
|
|
console.log(`- ${numDuplicateRedirects} repeated source URL(s)`);
|
|
}
|
|
|
|
console.log("\nPlease fix the errors above before merging :)");
|
|
process.exit(1);
|
|
} else {
|
|
console.log("\nDone!");
|
|
}
|
|
}
|
|
|
|
main();
|