From 68ef2970b819c0d5c890d9be1073bb808b47f517 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 26 Sep 2023 09:16:45 -0500 Subject: [PATCH] Add linting for README --- bun.lockb | Bin 1638 -> 5351 bytes lint.ts | 46 ++++++++++++++++++++++++++++++++++++++++------ package.json | 1 + tsconfig.json | 1 + 4 files changed, 42 insertions(+), 6 deletions(-) diff --git a/bun.lockb b/bun.lockb index 8a29fd78271797e5e89e0faa97f21da167f2e17d..0d30fe9494123fdcff452dfe5aad97c98b945c05 100755 GIT binary patch literal 5351 zcmeHLdsLH07XJdFBITu`C{UX%EiGWe8^vW&5DFd_Q4rXQq5(caNJwH51j4GR7Av4g z7hLec5i9rrbbTODMOQ70Rnco`N)(D|ZlYA4!dG%vyP6nK6y;z{ z+ocC=o89H%nBSMs=TTAN`M{%%QNDN9uB5aTpCFReDt?BcTec|moJ zNAmMKH$E_SNVk6TZJVyM@mJo?$&FO|box)8dqj0GKd(L4;@^9#48AP*;t=1TeZ#=w z!M9Q8yBZ6k_On9DS@oHHf-9RQe)kTTrMCpW$nLGE7#cFNjjN2s8GfE%H`uNzhKw9d z5c~=l=m&T<0~jm*6yQPtKiYgo+C%gk0xHqW!syeqzt-&V!7<4uAmA zkLnRSR{RVgnhAJZcktgaDn0x(S(4~F~d;K%AeK>(Qj z6Y!`U=S=2J>bj8xZ6xzSiF1UQp(!Y_p9C0`*pGXFg-EOuZr%DXuV=twfNTOP`h^OM z((>w3v&**j-umM?+lYqB@U&%%$Nep)C;LKA(WUOB#tQjT-ZXoQjSHKvhjg|VuDZ~_ z$fv>UX;|=;rBjTfobIjfu0F#m2ipiQ@dGrMeS6>--8J4hZL|HV?)PPjVj5fn_Sn!{gdVLGK2~`jPF$?~rtYQ=udW}l>o_$_ zGMj^P&lG-@?%~pB)t=QcKj>0iTN~?QMn%N*uzP0ZmgkLSA7}L)i4;Yg z%5AsL7G2yF{qFZVyu@EL_MU$9bYH>`HamB3d7t%Z$yB?lhEu{-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644 --- a/lint.ts +++ b/lint.ts @@ -1,13 +1,19 @@ import { readFile, readdir, stat } from "fs/promises"; import * as path from "path"; import * as marked from "marked"; +import grayMatter from "gray-matter"; const files = await readdir(".", { withFileTypes: true }); const dirs = files.filter( (f) => f.isDirectory() && !f.name.startsWith(".") && f.name !== "node_modules" ); -let badExit = false +let badExit = false; + +const error = (...data: any[]) => { + console.error(...data); + badExit = true; +} // Ensures that each README has the proper format. // Exits with 0 if all is good! @@ -20,6 +26,34 @@ for (const dir of dirs) { throw new Error(`Missing README.md in ${dir.name}`); } const content = await readFile(readme, "utf8"); + const matter = grayMatter(content); + const data = matter.data as { + display_name?: string; + description?: string; + icon?: string; + maintainer_github?: string; + partner_github?: string; + verified?: boolean; + tags?: string[]; + }; + if (!data.display_name) { + error(dir.name, "missing display_name"); + } + if (!data.description) { + error(dir.name, "missing description"); + } + if (!data.icon) { + error(dir.name, "missing icon"); + } + if (!data.maintainer_github) { + error(dir.name, "missing maintainer_github"); + } + try { + await stat(path.join(".", dir.name, data.icon)); + } catch (ex) { + error(dir.name, "icon does not exist", data.icon); + } + const tokens = marked.lexer(content); // Ensure there is an h1 and some text, then a code block @@ -45,17 +79,17 @@ for (const dir of dirs) { } } if (!h1) { - console.error(dir.name, "missing h1") + error(dir.name, "missing h1"); } if (!paragraph) { - console.error(dir.name, "missing paragraph after h1") + error(dir.name, "missing paragraph after h1"); } if (!code) { - console.error(dir.name, "missing example code block after paragraph") + error(dir.name, "missing example code block after paragraph"); } - badExit = true + badExit = true; } if (badExit) { - process.exit(1) + process.exit(1); } diff --git a/package.json b/package.json index 9dacc26..c9d3a81 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ }, "devDependencies": { "bun-types": "^1.0.3", + "gray-matter": "^4.0.3", "marked": "^9.0.3" }, "peerDependencies": { diff --git a/tsconfig.json b/tsconfig.json index dfa1fff..e7b89cd 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "target": "esnext", "module": "esnext", + "allowSyntheticDefaultImports": true, "moduleResolution": "nodenext", "types": ["bun-types"] }