Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools: add a linter for markdown lists #892

Merged
merged 9 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/linters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Linters

on:
pull_request:
types: [opened, synchronize, reopened, ready_for_review]
paths:
- README.md
- Moderation-Policy.md
- .github/workflows/linters.yml
push:
branches:
- main
paths:
- README.md
- Moderation-Policy.md
- .github/workflows/linters.yml

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
cancel-in-progress: false

permissions:
contents: read

jobs:
lint-md-lists:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
file:
- README.md
- Moderation-Policy.md
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
persist-credentials: false
- run: tools/lint-readme-lists.mjs "$FILE"
env:
FILE: ${{ matrix.file }}
10 changes: 6 additions & 4 deletions Moderation-Policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ remove resigning team member from respective permissions and private access.
<!-- referenced from the CoC page -->
<a id="current-members"></a>
### Current Members of Moderation Team

* [aduh95](https://github.com/aduh95) -
**Antoine du Hamel** <<duhamelantoine1995@gmail.com>> (he/him)
* [benjamingr](https://github.com/benjamingr) -
Expand All @@ -309,16 +310,17 @@ remove resigning team member from respective permissions and private access.


### Admins for Node.js Slack community

* [alextes](https://github.com/alextes) -
**Alexander Tesfamichael** &lt;alex.tesfamichael@gmail.com&gt;
* [aredridel](https://github.com/aredridel) -
**Aria Stewart** &lt;aredridel@dinhe.net&gt;
* [ljharb](https://github.com/ljharb) -
**Jordan Harband** &lt;ljharb@gmail.com&gt;
* [jxm262](https://github.com/jxm262) -
**Justin Maat** &lt;jxm262@gmail.com&gt;
* [hackygolucky](https://github.com/hackygolucky) -
**Tracy Hinds** &lt;tracyhinds@gmail.com&gt;
* [jxm262](https://github.com/jxm262) -
**Justin Maat** &lt;jxm262@gmail.com&gt;
* [ljharb](https://github.com/ljharb) -
**Jordan Harband** &lt;ljharb@gmail.com&gt;

## Escalation of Issues

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ action requiring consensus and voting will abide by the TSC process for that.

### Contacts for assistance

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

### Admin members

Expand Down
29 changes: 29 additions & 0 deletions tools/lint-readme-lists.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env node

// Validates the list in the markdown file passed as CLI argument are in the correct order.

import { open } from 'node:fs/promises';

const [,,markdownFile] = process.argv;

const readme = await open(markdownFile, 'r');

let currentList = null;
let previousGithubHandle;
let lineNumber = 0;

for await (const line of readme.readLines()) {
lineNumber++;
if (line.startsWith('##')) {
currentList = line.slice(line.indexOf(' '));
previousGithubHandle = null;
} else if (currentList && (line.startsWith('- [') || line.startsWith('* ['))) {
const currentGithubHandle = line.slice(3, line.indexOf(']')).toLowerCase();
if (previousGithubHandle && previousGithubHandle >= currentGithubHandle) {
throw new Error(`${currentGithubHandle} should be listed before ${previousGithubHandle} in the ${currentList} list (${markdownFile}:${lineNumber})`);
}

previousGithubHandle = currentGithubHandle;
}
}