Skip to content

Commit 1a005ce

Browse files
committed
Add a general linter that also lints markdown
Signed-off-by: Adam Gutglick <adam@spiraldb.com>
1 parent 1521c4f commit 1a005ce

File tree

7 files changed

+145
-44
lines changed

7 files changed

+145
-44
lines changed

.github/workflows/ci.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ on:
66
- develop
77

88
jobs:
9+
lint:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Setup Bun
18+
uses: oven-sh/setup-bun@v2
19+
20+
- name: Lint all code
21+
run: bunx prettier check .
22+
923
build:
1024
env:
1125
GH_TOKEN: ${{ github.token }}

.prettierrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

README.md

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ This is a great process for bug fixes, simple features and purely additive chang
1212

1313
However, if you are making a significant change to the way Vortex functions, you may need to write an RFC first. Some example changes that would require an RFC:
1414

15-
* Making a risky change to the format, such as adding new required fields to file metadata
16-
* Rearchitecting core components of Vortex, or wide-ranging refactors that might break language bindings
17-
* Creating new libraries or SDKs that we expect others to adopt
18-
* Making changes to subsystems that are likely to affect performance if not done thoughfully, such as the core IO traits
15+
- Making a risky change to the format, such as adding new required fields to file metadata
16+
- Rearchitecting core components of Vortex, or wide-ranging refactors that might break language bindings
17+
- Creating new libraries or SDKs that we expect others to adopt
18+
- Making changes to subsystems that are likely to affect performance if not done thoughfully, such as the core IO traits
1919

2020
## Process
2121

@@ -70,3 +70,14 @@ Remove the build output:
7070
```sh
7171
bun run clean
7272
```
73+
74+
### Formatting
75+
76+
We use [`prettiest`](https://prettier.io/) to format the code and documents, and check it in CI.
77+
78+
Running it is as easy as:
79+
80+
```sh
81+
bunx prettier --write .
82+
bunx prettier check .
83+
```

bun.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.ts

Lines changed: 63 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,17 @@ const LIVE_RELOAD_SCRIPT = `
7474
})();
7575
`;
7676

77-
function baseHTML(title: string, content: string, cssPath: string = "styles.css", liveReload: boolean = false, repoUrl: string | null = null): string {
77+
function baseHTML(
78+
title: string,
79+
content: string,
80+
cssPath: string = "styles.css",
81+
liveReload: boolean = false,
82+
repoUrl: string | null = null,
83+
): string {
7884
const basePath = cssPath === "styles.css" ? "./" : "../";
79-
const githubLink = repoUrl ? `<a href="${repoUrl}" class="github-link" aria-label="View on GitHub" target="_blank" rel="noopener">${ICON_GITHUB}</a>` : "";
85+
const githubLink = repoUrl
86+
? `<a href="${repoUrl}" class="github-link" aria-label="View on GitHub" target="_blank" rel="noopener">${ICON_GITHUB}</a>`
87+
: "";
8088
return `<!DOCTYPE html>
8189
<html lang="en">
8290
<head>
@@ -119,32 +127,40 @@ function escapeHTML(str: string): string {
119127
.replace(/"/g, "&quot;");
120128
}
121129

122-
function indexPage(rfcs: RFC[], repoUrl: string | null, liveReload: boolean = false): string {
130+
function indexPage(
131+
rfcs: RFC[],
132+
repoUrl: string | null,
133+
liveReload: boolean = false,
134+
): string {
123135
// Sort in reverse numeric order (newest first)
124136
const sorted = [...rfcs].sort((a, b) => b.number.localeCompare(a.number));
125137

126-
const list = sorted.map(rfc => {
127-
const dateStr = rfc.git.accepted ? formatDate(rfc.git.accepted.date) : "";
138+
const list = sorted
139+
.map((rfc) => {
140+
const dateStr = rfc.git.accepted ? formatDate(rfc.git.accepted.date) : "";
128141

129-
let authorHTML = "";
130-
if (rfc.git.author && rfc.git.accepted) {
131-
const commitUrl = repoUrl ? `${repoUrl}/commit/${rfc.git.accepted.hash}` : `https://github.com/${rfc.git.author.login}`;
132-
authorHTML = `
142+
let authorHTML = "";
143+
if (rfc.git.author && rfc.git.accepted) {
144+
const commitUrl = repoUrl
145+
? `${repoUrl}/commit/${rfc.git.accepted.hash}`
146+
: `https://github.com/${rfc.git.author.login}`;
147+
authorHTML = `
133148
<a href="${commitUrl}" class="rfc-author-link" title="${rfc.git.author.login}">
134149
<img src="${rfc.git.author.avatarUrl}" alt="${rfc.git.author.login}" class="rfc-author-avatar">
135150
<span class="rfc-author-name">${rfc.git.author.login}</span>
136151
</a>`;
137-
}
152+
}
138153

139-
return `
154+
return `
140155
<li>
141156
<a href="rfc/${rfc.number}.html" class="rfc-item">
142157
<span class="rfc-number">RFC ${rfc.number}</span>
143158
<span class="rfc-title">${escapeHTML(rfc.title)}</span>
144159
<span class="rfc-date">${dateStr}</span>
145160
</a>${authorHTML}
146161
</li>`;
147-
}).join("\n");
162+
})
163+
.join("\n");
148164

149165
const content = `
150166
<h1>Request for Comments</h1>
@@ -164,7 +180,11 @@ function formatDate(date: Date): string {
164180
});
165181
}
166182

167-
function rfcPage(rfc: RFC, repoUrl: string | null, liveReload: boolean = false): string {
183+
function rfcPage(
184+
rfc: RFC,
185+
repoUrl: string | null,
186+
liveReload: boolean = false,
187+
): string {
168188
let gitHeader = "";
169189

170190
if (rfc.git.accepted || rfc.git.author) {
@@ -218,7 +238,13 @@ function rfcPage(rfc: RFC, repoUrl: string | null, liveReload: boolean = false):
218238
${rfc.html}
219239
</article>`;
220240

221-
return baseHTML(`RFC ${rfc.number} - ${rfc.title}`, content, "../styles.css", liveReload, repoUrl);
241+
return baseHTML(
242+
`RFC ${rfc.number} - ${rfc.title}`,
243+
content,
244+
"../styles.css",
245+
liveReload,
246+
repoUrl,
247+
);
222248
}
223249

224250
function parseRFCNumber(filename: string): string {
@@ -245,10 +271,14 @@ async function getGitHubRepoUrl(): Promise<string | null> {
245271
}
246272
}
247273

248-
async function getGitHubAuthor(repoPath: string, commitHash: string): Promise<GitHubAuthor | null> {
274+
async function getGitHubAuthor(
275+
repoPath: string,
276+
commitHash: string,
277+
): Promise<GitHubAuthor | null> {
249278
try {
250279
// Use gh CLI to fetch commit info from GitHub API
251-
const result = await $`gh api repos/${repoPath}/commits/${commitHash} --jq '.author.login, .author.avatar_url, .author.html_url'`.quiet();
280+
const result =
281+
await $`gh api repos/${repoPath}/commits/${commitHash} --jq '.author.login, .author.avatar_url, .author.html_url'`.quiet();
252282
const lines = result.stdout.toString().trim().split("\n");
253283

254284
if (lines.length >= 3 && lines[0] && lines[1] && lines[2]) {
@@ -264,9 +294,13 @@ async function getGitHubAuthor(repoPath: string, commitHash: string): Promise<Gi
264294
}
265295
}
266296

267-
async function getGitHistory(filepath: string, repoPath: string | null): Promise<RFCGitInfo> {
297+
async function getGitHistory(
298+
filepath: string,
299+
repoPath: string | null,
300+
): Promise<RFCGitInfo> {
268301
try {
269-
const result = await $`git log --follow --format=%H\ %aI -- ${filepath}`.quiet();
302+
const result =
303+
await $`git log --follow --format=%H\ %aI -- ${filepath}`.quiet();
270304
const lines = result.stdout.toString().trim().split("\n").filter(Boolean);
271305

272306
if (lines.length === 0) {
@@ -284,7 +318,9 @@ async function getGitHistory(filepath: string, repoPath: string | null): Promise
284318
const oldest = parseCommit(lines[lines.length - 1]!);
285319

286320
// Fetch author info from the first commit
287-
const author = repoPath ? await getGitHubAuthor(repoPath, oldest.hash) : null;
321+
const author = repoPath
322+
? await getGitHubAuthor(repoPath, oldest.hash)
323+
: null;
288324

289325
// If only one commit, or same commit, don't show lastUpdated
290326
if (lines.length === 1 || mostRecent.hash === oldest.hash) {
@@ -479,7 +515,7 @@ async function startDevServer() {
479515
headers: {
480516
"Content-Type": "text/event-stream",
481517
"Cache-Control": "no-cache",
482-
"Connection": "keep-alive",
518+
Connection: "keep-alive",
483519
},
484520
});
485521
}
@@ -503,9 +539,11 @@ async function startDevServer() {
503539
if (isDev) {
504540
startDevServer().catch(console.error);
505541
} else {
506-
build().then(count => {
507-
if (count > 0) {
508-
console.log("Output directory: ./dist/");
509-
}
510-
}).catch(console.error);
542+
build()
543+
.then((count) => {
544+
if (count > 0) {
545+
console.log("Output directory: ./dist/");
546+
}
547+
})
548+
.catch(console.error);
511549
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
"clean": "rm -rf dist"
1010
},
1111
"devDependencies": {
12-
"@types/bun": "latest"
12+
"@types/bun": "latest",
13+
"prettier": "^3.8.1"
1314
},
1415
"peerDependencies": {
1516
"typescript": "^5"

styles.css

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,16 @@ html {
5959
}
6060

6161
body {
62-
font-family: "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
62+
font-family:
63+
"Inter",
64+
"SF Pro Display",
65+
-apple-system,
66+
BlinkMacSystemFont,
67+
"Segoe UI",
68+
Roboto,
69+
Helvetica,
70+
Arial,
71+
sans-serif;
6372
background: var(--bg);
6473
color: var(--fg);
6574
line-height: 1.6;
@@ -130,7 +139,9 @@ header h1 a:hover {
130139
height: 36px;
131140
border-radius: 50%;
132141
color: var(--fg-muted);
133-
transition: color 0.15s ease, box-shadow 0.15s ease;
142+
transition:
143+
color 0.15s ease,
144+
box-shadow 0.15s ease;
134145
}
135146

136147
.github-link:hover {
@@ -174,17 +185,33 @@ main {
174185
min-height: calc(100vh - 200px);
175186
}
176187

177-
h1, h2, h3, h4, h5, h6 {
188+
h1,
189+
h2,
190+
h3,
191+
h4,
192+
h5,
193+
h6 {
178194
font-weight: 600;
179195
margin-top: 2rem;
180196
margin-bottom: 1rem;
181197
color: var(--accent);
182198
}
183199

184-
h1 { font-size: 1.75rem; margin-top: 0; }
185-
h2 { font-size: 1.375rem; }
186-
h3 { font-size: 1.125rem; }
187-
h4, h5, h6 { font-size: 1rem; }
200+
h1 {
201+
font-size: 1.75rem;
202+
margin-top: 0;
203+
}
204+
h2 {
205+
font-size: 1.375rem;
206+
}
207+
h3 {
208+
font-size: 1.125rem;
209+
}
210+
h4,
211+
h5,
212+
h6 {
213+
font-size: 1rem;
214+
}
188215

189216
p {
190217
margin-bottom: 1rem;
@@ -200,7 +227,8 @@ a:hover {
200227
text-decoration: underline;
201228
}
202229

203-
ul, ol {
230+
ul,
231+
ol {
204232
margin-bottom: 1rem;
205233
padding-left: 1.5rem;
206234
}
@@ -210,15 +238,17 @@ li {
210238
}
211239

212240
code {
213-
font-family: "IBM Plex Mono", "SF Mono", "Menlo", "Monaco", "Consolas", monospace;
241+
font-family:
242+
"IBM Plex Mono", "SF Mono", "Menlo", "Monaco", "Consolas", monospace;
214243
background: var(--code-bg);
215244
padding: 0.125rem 0.375rem;
216245
border-radius: 3px;
217246
font-size: 0.875em;
218247
}
219248

220249
pre {
221-
font-family: "IBM Plex Mono", "SF Mono", "Menlo", "Monaco", "Consolas", monospace;
250+
font-family:
251+
"IBM Plex Mono", "SF Mono", "Menlo", "Monaco", "Consolas", monospace;
222252
background: var(--code-bg);
223253
border: 1px solid var(--border);
224254
border-radius: 4px;
@@ -254,7 +284,8 @@ table {
254284
margin-bottom: 1rem;
255285
}
256286

257-
th, td {
287+
th,
288+
td {
258289
border: 1px solid var(--border);
259290
padding: 0.5rem 0.75rem;
260291
text-align: left;
@@ -278,7 +309,9 @@ th {
278309
padding: 0.75rem 1rem;
279310
margin: 0 -1rem;
280311
border-radius: 4px;
281-
transition: box-shadow 0.15s ease, background 0.15s ease;
312+
transition:
313+
box-shadow 0.15s ease,
314+
background 0.15s ease;
282315
}
283316

284317
.rfc-list li:hover {
@@ -306,7 +339,8 @@ th {
306339
}
307340

308341
.rfc-item .rfc-number {
309-
font-family: "IBM Plex Mono", "SF Mono", "Menlo", "Monaco", "Consolas", monospace;
342+
font-family:
343+
"IBM Plex Mono", "SF Mono", "Menlo", "Monaco", "Consolas", monospace;
310344
color: var(--fg-muted);
311345
font-size: 0.875rem;
312346
flex-shrink: 0;

0 commit comments

Comments
 (0)