From 5aac3fe9f9ccd18d86f7b82130da6d79211a8eae Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 26 Sep 2023 09:11:11 -0500 Subject: [PATCH 1/5] Add linting --- .github/workflows/ci.yaml | 3 +- bun.lockb | Bin 1269 -> 1638 bytes lint.ts | 61 ++++++++++++++++++++++++++++++++++++++ package.json | 6 ++-- tsconfig.json | 1 + 5 files changed, 68 insertions(+), 3 deletions(-) create mode 100644 lint.ts diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 9ee005c5..96bb4e56 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -21,7 +21,7 @@ jobs: with: bun-version: latest - run: bun test - fmt: + pretty: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -29,3 +29,4 @@ jobs: with: bun-version: latest - run: bun fmt:ci + - run: bun lint diff --git a/bun.lockb b/bun.lockb index dfed91948022558cca9901420988b9f7b8ce4291..8a29fd78271797e5e89e0faa97f21da167f2e17d 100755 GIT binary patch delta 588 zcmey$`HW|Ro@UvT3#I01t9MIy8CPo+d^@#5V|lddv|yI*rAa2C@#Z1dSQ)^8d1AP{ zbvZMH!@!W6pHiBWTFj7}Sd^Wb!oa`HFlJZ3Nk7{m z^je8=G9#n-#2*@hOi&XPfV2rv1Lwq#`kXMqkcls?SwVI%Py8s%3uZu-Gf%c;Eb&>= z|Kw54LFwQltAom80@;s7KkhvKc>1Xa8OK%?Md?W@^SAk3xZ`pA=9I$Y-vTU;n11(n zKN}^+5vKL3>A{wLj7x!rF*5w)|HsI{z%+RwW4MXS@8WH%Rzd6lIRfS#VIZ3q=sJ)L zy4d7EMuW*7Oh%Iv7!A1&KttpT^W+vL2U(!q!sKh77&YpfrDl8Jtj3ikdOsb z$OR;%Bn6TM=>bUrUB*xWl|IHY*@;&VDl!sGU`wKz#<5f1gQnFnI_L;HcS2A0Vi8I324FdK0lfEsXxX>ud8gVewO5CBpP)(&+a z3-jcA%xYW)P_6}tt0V+c3sRK<6`sR9*^fnQat({R5ZqnQpmNV9H!zD%e!`-|B>)Y^ jSeD6BtO`OUl?AEA$wiq3CBVSZ1@R`wv&u|f&$=A|LHlIX diff --git a/lint.ts b/lint.ts new file mode 100644 index 00000000..235cf358 --- /dev/null +++ b/lint.ts @@ -0,0 +1,61 @@ +import { readFile, readdir, stat } from "fs/promises"; +import * as path from "path"; +import * as marked from "marked"; + +const files = await readdir(".", { withFileTypes: true }); +const dirs = files.filter( + (f) => f.isDirectory() && !f.name.startsWith(".") && f.name !== "node_modules" +); + +let badExit = false + +// Ensures that each README has the proper format. +// Exits with 0 if all is good! +for (const dir of dirs) { + const readme = path.join(dir.name, "README.md"); + // Ensure exists + try { + await stat(readme); + } catch (ex) { + throw new Error(`Missing README.md in ${dir.name}`); + } + const content = await readFile(readme, "utf8"); + const tokens = marked.lexer(content); + // Ensure there is an h1 and some text, then a code block + + let h1 = false; + let code = false; + let paragraph = false; + + for (const token of tokens) { + if (token.type === "heading" && token.depth === 1) { + h1 = true; + continue; + } + if (h1 && token.type === "heading") { + break; + } + if (token.type === "paragraph") { + paragraph = true; + continue; + } + if (token.type === "code") { + code = true; + continue; + } + } + if (!h1) { + console.error(dir.name, "missing h1") + } + if (!paragraph) { + console.error(dir.name, "missing paragraph after h1") + } + if (!code) { + console.error(dir.name, "missing example code block after paragraph") + } + badExit = true +} + +if (badExit) { + process.exit(1) +} diff --git a/package.json b/package.json index c42b502b..9dacc268 100644 --- a/package.json +++ b/package.json @@ -3,10 +3,12 @@ "scripts": { "test": "bun test", "fmt": "bun x prettier -w **/*.ts **/*.md *.md && terraform fmt **/*.tf", - "fmt:ci": "bun x prettier --check **/*.ts **/*.md *.md && terraform fmt -check **/*.tf" + "fmt:ci": "bun x prettier --check **/*.ts **/*.md *.md && terraform fmt -check **/*.tf", + "lint": "bun run lint.ts" }, "devDependencies": { - "bun-types": "^1.0.3" + "bun-types": "^1.0.3", + "marked": "^9.0.3" }, "peerDependencies": { "typescript": "^5.0.0" diff --git a/tsconfig.json b/tsconfig.json index 86140a5d..dfa1fff7 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "target": "esnext", "module": "esnext", + "moduleResolution": "nodenext", "types": ["bun-types"] } } From 68ef2970b819c0d5c890d9be1073bb808b47f517 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 26 Sep 2023 09:16:45 -0500 Subject: [PATCH 2/5] 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!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h zt^-gPTw$J^%1SX85ey6*ER*-~YH?XWxh^2C(qtPx4k3^#Mj)<$ zN*!aF+{C9fc?F+|3e0lWAeFf;3mCIGz$Su>6MzPT0PAEq0S7JzDEA!ei diff --git a/lint.ts b/lint.ts index 235cf358..76a52afc 100644 --- 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 9dacc268..c9d3a81b 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 dfa1fff7..e7b89cde 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -2,6 +2,7 @@ "compilerOptions": { "target": "esnext", "module": "esnext", + "allowSyntheticDefaultImports": true, "moduleResolution": "nodenext", "types": ["bun-types"] } From 91be83eb43e9e32dbbf5590e513ba6a03bb4bb42 Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 26 Sep 2023 09:17:23 -0500 Subject: [PATCH 3/5] Fix linting --- lint.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lint.ts b/lint.ts index 76a52afc..12e733cf 100644 --- a/lint.ts +++ b/lint.ts @@ -10,6 +10,8 @@ const dirs = files.filter( let badExit = false; +// error reports an error to the console and sets badExit to true +// so that the process will exit with a non-zero exit code. const error = (...data: any[]) => { console.error(...data); badExit = true; @@ -87,7 +89,6 @@ for (const dir of dirs) { if (!code) { error(dir.name, "missing example code block after paragraph"); } - badExit = true; } if (badExit) { From 7810d480ae9d9c1598d06e8a61791e54d1bf348e Mon Sep 17 00:00:00 2001 From: Kyle Carberry Date: Tue, 26 Sep 2023 09:18:40 -0500 Subject: [PATCH 4/5] Fix install --- .github/workflows/ci.yaml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 96bb4e56..60a760be 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -28,5 +28,7 @@ jobs: - uses: oven-sh/setup-bun@v1 with: bun-version: latest - - run: bun fmt:ci - - run: bun lint + - name: Format + run: bun fmt:ci + - name: Lint + run: bun install && bun lint From 96937988f440fe07d17fa502323548a751de269c Mon Sep 17 00:00:00 2001 From: Muhammad Atif Ali Date: Wed, 27 Sep 2023 21:52:31 +0300 Subject: [PATCH 5/5] move screesnhot after example code --- .sample/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.sample/README.md b/.sample/README.md index ebc3e496..387d45b6 100644 --- a/.sample/README.md +++ b/.sample/README.md @@ -11,14 +11,14 @@ tags: [helper] - - ```hcl module "MODULE_NAME" { source = "https://registry.coder.com/modules/MODULE_NAME" } ``` + + ## Examples ### Example 1