Skip to content

Commit 19600c0

Browse files
authored
tools: add a linter for markdown lists (#892)
1 parent 30b3260 commit 19600c0

File tree

4 files changed

+76
-5
lines changed

4 files changed

+76
-5
lines changed

.github/workflows/linters.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Linters
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize, reopened, ready_for_review]
6+
paths:
7+
- README.md
8+
- Moderation-Policy.md
9+
- .github/workflows/linters.yml
10+
push:
11+
branches:
12+
- main
13+
paths:
14+
- README.md
15+
- Moderation-Policy.md
16+
- .github/workflows/linters.yml
17+
18+
concurrency:
19+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
20+
cancel-in-progress: false
21+
22+
permissions:
23+
contents: read
24+
25+
jobs:
26+
lint-md-lists:
27+
runs-on: ubuntu-latest
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
file:
32+
- README.md
33+
- Moderation-Policy.md
34+
steps:
35+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
36+
with:
37+
persist-credentials: false
38+
- run: tools/lint-readme-lists.mjs "$FILE"
39+
env:
40+
FILE: ${{ matrix.file }}

Moderation-Policy.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ remove resigning team member from respective permissions and private access.
294294
<!-- referenced from the CoC page -->
295295
<a id="current-members"></a>
296296
### Current Members of Moderation Team
297+
297298
* [aduh95](https://github.com/aduh95) -
298299
**Antoine du Hamel** <<duhamelantoine1995@gmail.com>> (he/him)
299300
* [benjamingr](https://github.com/benjamingr) -
@@ -309,16 +310,17 @@ remove resigning team member from respective permissions and private access.
309310

310311

311312
### Admins for Node.js Slack community
313+
312314
* [alextes](https://github.com/alextes) -
313315
**Alexander Tesfamichael** &lt;alex.tesfamichael@gmail.com&gt;
314316
* [aredridel](https://github.com/aredridel) -
315317
**Aria Stewart** &lt;aredridel@dinhe.net&gt;
316-
* [ljharb](https://github.com/ljharb) -
317-
**Jordan Harband** &lt;ljharb@gmail.com&gt;
318-
* [jxm262](https://github.com/jxm262) -
319-
**Justin Maat** &lt;jxm262@gmail.com&gt;
320318
* [hackygolucky](https://github.com/hackygolucky) -
321319
**Tracy Hinds** &lt;tracyhinds@gmail.com&gt;
320+
* [jxm262](https://github.com/jxm262) -
321+
**Justin Maat** &lt;jxm262@gmail.com&gt;
322+
* [ljharb](https://github.com/ljharb) -
323+
**Jordan Harband** &lt;ljharb@gmail.com&gt;
322324

323325
## Escalation of Issues
324326

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ action requiring consensus and voting will abide by the TSC process for that.
2929

3030
### Contacts for assistance
3131

32-
- [@mhdawson](https://github.com/mhdawson) - **Michael Dawson**, TSC Chair
3332
- [@mcollina](https://github.com/mcollina) - **Matteo Collina**, TSC Vice Chair
33+
- [@mhdawson](https://github.com/mhdawson) - **Michael Dawson**, TSC Chair
3434

3535
### Admin members
3636

tools/lint-readme-lists.mjs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env node
2+
3+
// Validates the list in the markdown file passed as CLI argument are in the correct order.
4+
5+
import { open } from 'node:fs/promises';
6+
7+
const [,,markdownFile] = process.argv;
8+
9+
const readme = await open(markdownFile, 'r');
10+
11+
let currentList = null;
12+
let previousGithubHandle;
13+
let lineNumber = 0;
14+
15+
for await (const line of readme.readLines()) {
16+
lineNumber++;
17+
if (line.startsWith('##')) {
18+
currentList = line.slice(line.indexOf(' '));
19+
previousGithubHandle = null;
20+
} else if (currentList && (line.startsWith('- [') || line.startsWith('* ['))) {
21+
const currentGithubHandle = line.slice(3, line.indexOf(']')).toLowerCase();
22+
if (previousGithubHandle && previousGithubHandle >= currentGithubHandle) {
23+
throw new Error(`${currentGithubHandle} should be listed before ${previousGithubHandle} in the ${currentList} list (${markdownFile}:${lineNumber})`);
24+
}
25+
26+
previousGithubHandle = currentGithubHandle;
27+
}
28+
}
29+

0 commit comments

Comments
 (0)