xonecas.io
6533
Yo

yoctomarkdown / commit 3b692bf

chore: add biome linting and prettier formatting

xonecas2026-03-15 3b692bfb443cb987e32d65e79e6ddb3ebf9e584d parent 6e616eb

9 files changed

.prettierrc+1−0
@@ -0,0 +1 @@
1+{ "singleQuote": false }
AGENTS.md+3−0
@@ -1,2 +1,5 @@
11 - [spec.md](spec.md) is maintained by the user, only edit when asked directly by the user. It contains the specification for the project. Use it as the source of truth
22 - Run `bun run check` before committing to run jscpd, knip, and typescript typecheck.
3+- Run `bun run format` to format code using prettier.
4+- Clean temporary files before commiting.
5+- Use convential commits message formatting.
biome.json+34−0
@@ -0,0 +1,34 @@
1+{
2+ "$schema": "https://biomejs.dev/schemas/2.4.7/schema.json",
3+ "vcs": {
4+ "enabled": true,
5+ "clientKind": "git",
6+ "useIgnoreFile": true
7+ },
8+ "files": {
9+ "ignoreUnknown": false
10+ },
11+ "formatter": {
12+ "enabled": false,
13+ "indentStyle": "tab"
14+ },
15+ "linter": {
16+ "enabled": true,
17+ "rules": {
18+ "recommended": true
19+ }
20+ },
21+ "javascript": {
22+ "formatter": {
23+ "quoteStyle": "double"
24+ }
25+ },
26+ "assist": {
27+ "enabled": true,
28+ "actions": {
29+ "source": {
30+ "organizeImports": "on"
31+ }
32+ }
33+ }
34+}
bun.lock+22−0
@@ -8,10 +8,12 @@
88 "yoctocolors": "^2.1.2",
99 },
1010 "devDependencies": {
11+ "@biomejs/biome": "^2.4.7",
1112 "@types/bun": "latest",
1213 "husky": "^9.1.7",
1314 "jscpd": "^4.0.8",
1415 "knip": "^5.86.0",
16+ "prettier": "^3.8.1",
1517 },
1618 "peerDependencies": {
1719 "typescript": "^5.9.3",
@@ -27,6 +29,24 @@
2729
2830 "@babel/types": ["@babel/types@7.29.0", "", { "dependencies": { "@babel/helper-string-parser": "^7.27.1", "@babel/helper-validator-identifier": "^7.28.5" } }, "sha512-LwdZHpScM4Qz8Xw2iKSzS+cfglZzJGvofQICy7W7v4caru4EaAmyUuO6BGrbyQ2mYV11W0U8j5mBhd14dd3B0A=="],
2931
32+ "@biomejs/biome": ["@biomejs/biome@2.4.7", "", { "optionalDependencies": { "@biomejs/cli-darwin-arm64": "2.4.7", "@biomejs/cli-darwin-x64": "2.4.7", "@biomejs/cli-linux-arm64": "2.4.7", "@biomejs/cli-linux-arm64-musl": "2.4.7", "@biomejs/cli-linux-x64": "2.4.7", "@biomejs/cli-linux-x64-musl": "2.4.7", "@biomejs/cli-win32-arm64": "2.4.7", "@biomejs/cli-win32-x64": "2.4.7" }, "bin": { "biome": "bin/biome" } }, "sha512-vXrgcmNGZ4lpdwZSpMf1hWw1aWS6B+SyeSYKTLrNsiUsAdSRN0J4d/7mF3ogJFbIwFFSOL3wT92Z …
33+
34+ "@biomejs/cli-darwin-arm64": ["@biomejs/cli-darwin-arm64@2.4.7", "", { "os": "darwin", "cpu": "arm64" }, "sha512-Oo0cF5mHzmvDmTXw8XSjhCia8K6YrZnk7aCS54+/HxyMdZMruMO3nfpDsrlar/EQWe41r1qrwKiCa2QDYHDzWA=="],
35+
36+ "@biomejs/cli-darwin-x64": ["@biomejs/cli-darwin-x64@2.4.7", "", { "os": "darwin", "cpu": "x64" }, "sha512-I+cOG3sd/7HdFtvDSnF9QQPrWguUH7zrkIMMykM3PtfWU9soTcS2yRb9Myq6MHmzbeCT08D1UmY+BaiMl5CcoQ=="],
37+
38+ "@biomejs/cli-linux-arm64": ["@biomejs/cli-linux-arm64@2.4.7", "", { "os": "linux", "cpu": "arm64" }, "sha512-om6FugwmibzfP/6ALj5WRDVSND4H2G9X0nkI1HZpp2ySf9lW2j0X68oQSaHEnls6666oy4KDsc5RFjT4m0kV0w=="],
39+
40+ "@biomejs/cli-linux-arm64-musl": ["@biomejs/cli-linux-arm64-musl@2.4.7", "", { "os": "linux", "cpu": "arm64" }, "sha512-I2NvM9KPb09jWml93O2/5WMfNR7Lee5Latag1JThDRMURVhPX74p9UDnyTw3Ae6cE1DgXfw7sqQgX7rkvpc0vw=="],
41+
42+ "@biomejs/cli-linux-x64": ["@biomejs/cli-linux-x64@2.4.7", "", { "os": "linux", "cpu": "x64" }, "sha512-bV8/uo2Tj+gumnk4sUdkerWyCPRabaZdv88IpbmDWARQQoA/Q0YaqPz1a+LSEDIL7OfrnPi9Hq1Llz4ZIGyIQQ=="],
43+
44+ "@biomejs/cli-linux-x64-musl": ["@biomejs/cli-linux-x64-musl@2.4.7", "", { "os": "linux", "cpu": "x64" }, "sha512-00kx4YrBMU8374zd2wHuRV5wseh0rom5HqRND+vDldJPrWwQw+mzd/d8byI9hPx926CG+vWzq6AeiT7Yi5y59g=="],
45+
46+ "@biomejs/cli-win32-arm64": ["@biomejs/cli-win32-arm64@2.4.7", "", { "os": "win32", "cpu": "arm64" }, "sha512-hOUHBMlFCvDhu3WCq6vaBoG0dp0LkWxSEnEEsxxXvOa9TfT6ZBnbh72A/xBM7CBYB7WgwqboetzFEVDnMxelyw=="],
47+
48+ "@biomejs/cli-win32-x64": ["@biomejs/cli-win32-x64@2.4.7", "", { "os": "win32", "cpu": "x64" }, "sha512-qEpGjSkPC3qX4ycbMUthXvi9CkRq7kZpkqMY1OyhmYlYLnANnooDQ7hDerM8+0NJ+DZKVnsIc07h30XOpt7LtQ=="],
49+
3050 "@colors/colors": ["@colors/colors@1.5.0", "", {}, "sha512-ooWCrlZP11i8GImSjTHYHLkvFDP48nS4+204nGb1RiX/WXYHmJA2III9/e2DWVabCESdW7hBAEzHRqUn9OUVvQ=="],
3151
3252 "@emnapi/core": ["@emnapi/core@1.9.0", "", { "dependencies": { "@emnapi/wasi-threads": "1.2.0", "tslib": "^2.4.0" } }, "sha512-0DQ98G9ZQZOxfUcQn1waV2yS8aWdZ6kJMbYCJB3oUBecjWYO1fqJ+a1DRfPF3O5JEkwqwP1A9QEN/9mYm2Yd0w=="],
@@ -261,6 +281,8 @@
261281
262282 "picomatch": ["picomatch@4.0.3", "", {}, "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q=="],
263283
284+ "prettier": ["prettier@3.8.1", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg=="],
285+
264286 "promise": ["promise@7.3.1", "", { "dependencies": { "asap": "~2.0.3" } }, "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg=="],
265287
266288 "pug": ["pug@3.0.4", "", { "dependencies": { "pug-code-gen": "^3.0.4", "pug-filters": "^4.0.0", "pug-lexer": "^5.0.1", "pug-linker": "^4.0.0", "pug-load": "^3.0.0", "pug-parser": "^6.0.0", "pug-runtime": "^3.0.1", "pug-strip-comments": "^2.0.0" } }, "sha512-kFfq5mMzrS7+wrl5pLJzZEzemx34OQ0w4SARfhy/3yxTlhbstsudDwJzhf1hP02yHzbjoVMSXUj/Sz6RNfMyXg=="],
cli.ts+9−7
@@ -1,7 +1,7 @@
11 #!/usr/bin/env bun
2-import { parseArgs } from "util";
3-import { highlightSync, createHighlighter, type Options } from "./index";
4-import { readFileSync } from "fs";
2+import { readFileSync } from "node:fs";
3+import { parseArgs } from "node:util";
4+import { createHighlighter, type Options } from "./index";
55
66 const { values, positionals } = parseArgs({
77 args: Bun.argv.slice(2),
@@ -38,7 +38,7 @@ if (wrapVal === "auto" || wrapVal === "0") {
3838 wordWrap = wrapVal === "auto" ? "auto" : 0;
3939 } else {
4040 const n = parseInt(wrapVal, 10);
41- if (isNaN(n) || n < 0) {
41+ if (Number.isNaN(n) || n < 0) {
4242 console.error(`Invalid wrap value: ${wrapVal}`);
4343 process.exit(1);
4444 }
@@ -46,7 +46,7 @@ if (wrapVal === "auto" || wrapVal === "0") {
4646 }
4747
4848 const options: Options = {
49- theme: themeName as any,
49+ theme: themeName as Options["theme"],
5050 wordWrap,
5151 };
5252
@@ -59,8 +59,10 @@ async function run() {
5959 const content = readFileSync(file, "utf8");
6060 process.stdout.write(highlighter.write(content));
6161 process.stdout.write(highlighter.end());
62- } catch (err: any) {
63- console.error(`Error reading file: ${err.message}`);
62+ } catch (err: unknown) {
63+ console.error(
64+ `Error reading file: ${err instanceof Error ? err.message : String(err)}`,
65+ );
6466 process.exit(1);
6567 }
6668 } else {
index.ts+26−21
@@ -15,7 +15,7 @@ export interface Highlighter {
1515 function resolveTheme(options?: Options): Theme {
1616 const t = options?.theme || "16";
1717 if (typeof t === "string") {
18- return (themes[t] || themes["none"]) as Theme;
18+ return (themes[t] || themes.none) as Theme;
1919 }
2020 return t as Theme;
2121 }
@@ -32,21 +32,20 @@ export function createHighlighter(options?: Options): Highlighter {
3232 let inCodeBlock = false;
3333
3434 function parseInline(text: string): string {
35-
3635 let result = "";
3736 let i = 0;
3837 while (i < text.length) {
3938 if (text.startsWith("`", i) && !text.startsWith("``", i)) {
40- let end = text.indexOf("`", i + 1);
39+ const end = text.indexOf("`", i + 1);
4140 if (end !== -1) {
4241 result += theme.code(`\`${text.slice(i + 1, end)}\``);
4342 i = end + 1;
4443 continue;
4544 }
4645 }
47-
46+
4847 if (text.startsWith("**", i)) {
49- let end = text.indexOf("**", i + 2);
48+ const end = text.indexOf("**", i + 2);
5049 if (end !== -1) {
5150 result += theme.bold(`**${text.slice(i + 2, end)}**`);
5251 i = end + 2;
@@ -55,7 +54,7 @@ export function createHighlighter(options?: Options): Highlighter {
5554 }
5655
5756 if (text.startsWith("*", i) && !text.startsWith("**", i)) {
58- let end = text.indexOf("*", i + 1);
57+ const end = text.indexOf("*", i + 1);
5958 if (end !== -1 && !text.startsWith("**", end)) {
6059 result += theme.italic(`*${text.slice(i + 1, end)}*`);
6160 i = end + 1;
@@ -64,11 +63,13 @@ export function createHighlighter(options?: Options): Highlighter {
6463 }
6564
6665 if (text.startsWith("[", i)) {
67- let bracketEnd = text.indexOf("]", i + 1);
66+ const bracketEnd = text.indexOf("]", i + 1);
6867 if (bracketEnd !== -1 && text.charAt(bracketEnd + 1) === "(") {
69- let parenEnd = text.indexOf(")", bracketEnd + 2);
68+ const parenEnd = text.indexOf(")", bracketEnd + 2);
7069 if (parenEnd !== -1) {
71- result += theme.link(`[${text.slice(i + 1, bracketEnd)}](${text.slice(bracketEnd + 2, parenEnd)})`);
70+ result += theme.link(
71+ `[${text.slice(i + 1, bracketEnd)}](${text.slice(bracketEnd + 2, parenEnd)})`,
72+ );
7273 i = parenEnd + 1;
7374 continue;
7475 }
@@ -78,11 +79,11 @@ export function createHighlighter(options?: Options): Highlighter {
7879 result += text[i];
7980 i++;
8081 }
81-
82+
8283 return result;
8384 }
8485
85- function parseLine(line: string, isLastLine: boolean): string {
86+ function parseLine(line: string, _isLastLine: boolean): string {
8687 if (inCodeBlock) {
8788 if (line.trim().startsWith("```")) {
8889 inCodeBlock = false;
@@ -103,24 +104,24 @@ export function createHighlighter(options?: Options): Highlighter {
103104
104105 const headingMatch = line.match(/^(#{1,3})\s+(.*)$/);
105106 if (headingMatch) {
106- const hashes = headingMatch[1]!;
107- const text = headingMatch[2]!;
107+ const hashes = headingMatch[1] ?? "";
108+ const text = headingMatch[2] ?? "";
108109 return theme.heading(`${hashes} ${parseInline(text)}`);
109110 }
110111
111112 const bqMatch = line.match(/^(>\s+)(.*)$/);
112113 if (bqMatch) {
113- return theme.blockquote(bqMatch[1]!) + parseInline(bqMatch[2]!);
114+ return theme.blockquote(bqMatch[1] ?? "") + parseInline(bqMatch[2] ?? "");
114115 }
115116
116117 const ulMatch = line.match(/^([-*]\s+)(.*)$/);
117118 if (ulMatch) {
118- return theme.listMarker(ulMatch[1]!) + parseInline(ulMatch[2]!);
119+ return theme.listMarker(ulMatch[1] ?? "") + parseInline(ulMatch[2] ?? "");
119120 }
120121
121122 const olMatch = line.match(/^(\d+\.\s+)(.*)$/);
122123 if (olMatch) {
123- return theme.listMarker(olMatch[1]!) + parseInline(olMatch[2]!);
124+ return theme.listMarker(olMatch[1] ?? "") + parseInline(olMatch[2] ?? "");
124125 }
125126
126127 return parseInline(line);
@@ -128,13 +129,17 @@ export function createHighlighter(options?: Options): Highlighter {
128129
129130 return {
130131 write(chunk: string | Uint8Array): string {
131- const text = typeof chunk === "string" ? chunk : new TextDecoder().decode(chunk);
132+ const text =
133+ typeof chunk === "string" ? chunk : new TextDecoder().decode(chunk);
132134 buffer += text;
133-
135+
134136 const lines = buffer.split("\n");
135137 buffer = lines.pop() ?? "";
136-
137- return lines.map((line) => parseLine(line, false)).join("\n") + (lines.length > 0 ? "\n" : "");
138+
139+ return (
140+ lines.map((line) => parseLine(line, false)).join("\n") +
141+ (lines.length > 0 ? "\n" : "")
142+ );
138143 },
139144 end(): string {
140145 if (buffer.length > 0) {
@@ -143,6 +148,6 @@ export function createHighlighter(options?: Options): Highlighter {
143148 return out;
144149 }
145150 return "";
146- }
151+ },
147152 };
148153 }
new.txt+5−5
@@ -1,21 +1,21 @@
11 const headingMatch = line.match(/^(#{1,3})\s+(.*)$/);
22 if (headingMatch) {
3- const hashes = headingMatch[1]!;
4- const text = headingMatch[2]!;
3+ const hashes = headingMatch[1] ?? "";
4+ const text = headingMatch[2] ?? "";
55 return theme.heading(`${hashes} ${parseInline(text)}`);
66 }
77
88 const bqMatch = line.match(/^(>\s+)(.*)$/);
99 if (bqMatch) {
10- return theme.blockquote(bqMatch[1]!) + parseInline(bqMatch[2]!);
10+ return theme.blockquote(bqMatch[1] ?? "") + parseInline(bqMatch[2] ?? "");
1111 }
1212
1313 const ulMatch = line.match(/^([-*]\s+)(.*)$/);
1414 if (ulMatch) {
15- return theme.listMarker(ulMatch[1]!) + parseInline(ulMatch[2]!);
15+ return theme.listMarker(ulMatch[1] ?? "") + parseInline(ulMatch[2] ?? "");
1616 }
1717
1818 const olMatch = line.match(/^(\d+\.\s+)(.*)$/);
1919 if (olMatch) {
20- return theme.listMarker(olMatch[1]!) + parseInline(olMatch[2]!);
20+ return theme.listMarker(olMatch[1] ?? "") + parseInline(olMatch[2] ?? "");
2121 }
old.txt+5−5
@@ -1,21 +1,21 @@
11 const headingMatch = line.match(/^(#{1,3})\s+(.*)$/);
22 if (headingMatch) {
3- const hashes = headingMatch[1];
4- const text = headingMatch[2];
3+ const hashes = headingMatch[1]!;
4+ const text = headingMatch[2]!;
55 return theme.heading(`${hashes} ${parseInline(text)}`);
66 }
77
88 const bqMatch = line.match(/^(>\s+)(.*)$/);
99 if (bqMatch) {
10- return theme.blockquote(bqMatch[1]) + parseInline(bqMatch[2]);
10+ return theme.blockquote(bqMatch[1]!) + parseInline(bqMatch[2]!);
1111 }
1212
1313 const ulMatch = line.match(/^([-*]\s+)(.*)$/);
1414 if (ulMatch) {
15- return theme.listMarker(ulMatch[1]) + parseInline(ulMatch[2]);
15+ return theme.listMarker(ulMatch[1]!) + parseInline(ulMatch[2]!);
1616 }
1717
1818 const olMatch = line.match(/^(\d+\.\s+)(.*)$/);
1919 if (olMatch) {
20- return theme.listMarker(olMatch[1]) + parseInline(olMatch[2]);
20+ return theme.listMarker(olMatch[1]!) + parseInline(olMatch[2]!);
2121 }
package.json+8−3
@@ -4,10 +4,12 @@
44 "type": "module",
55 "private": true,
66 "devDependencies": {
7+ "@biomejs/biome": "^2.4.7",
78 "@types/bun": "latest",
89 "husky": "^9.1.7",
910 "jscpd": "^4.0.8",
10- "knip": "^5.86.0"
11+ "knip": "^5.86.0",
12+ "prettier": "^3.8.1"
1113 },
1214 "peerDependencies": {
1315 "typescript": "^5.9.3"
@@ -22,7 +24,10 @@
2224 "typecheck": "tsc --noEmit",
2325 "knip": "knip",
2426 "jscpd": "jscpd . --ignore \"node_modules/**\"",
25- "check": "bun run typecheck && bun run knip && bun run jscpd",
26- "prepare": "husky"
27+ "check": "bun run format:check && bun run lint && bun run typecheck && bun run knip && bun run jscpd",
28+ "prepare": "husky",
29+ "lint": "biome lint .",
30+ "format": "prettier --write .",
31+ "format:check": "prettier --check ."
2732 }
2833 }