From 19600c0fe986a3d6649758627b4f414fa6286ccc Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Thu, 11 Jul 2024 01:07:57 +0200 Subject: [PATCH] tools: add a linter for markdown lists (#892) --- .github/workflows/linters.yml | 40 +++++++++++++++++++++++++++++++++++ Moderation-Policy.md | 10 +++++---- README.md | 2 +- tools/lint-readme-lists.mjs | 29 +++++++++++++++++++++++++ 4 files changed, 76 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/linters.yml create mode 100755 tools/lint-readme-lists.mjs diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml new file mode 100644 index 0000000..c3d7474 --- /dev/null +++ b/.github/workflows/linters.yml @@ -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 }} diff --git a/Moderation-Policy.md b/Moderation-Policy.md index fe70289..174421c 100644 --- a/Moderation-Policy.md +++ b/Moderation-Policy.md @@ -294,6 +294,7 @@ remove resigning team member from respective permissions and private access. ### Current Members of Moderation Team + * [aduh95](https://github.com/aduh95) - **Antoine du Hamel** <> (he/him) * [benjamingr](https://github.com/benjamingr) - @@ -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** <alex.tesfamichael@gmail.com> * [aredridel](https://github.com/aredridel) - **Aria Stewart** <aredridel@dinhe.net> -* [ljharb](https://github.com/ljharb) - -**Jordan Harband** <ljharb@gmail.com> -* [jxm262](https://github.com/jxm262) - -**Justin Maat** <jxm262@gmail.com> * [hackygolucky](https://github.com/hackygolucky) - **Tracy Hinds** <tracyhinds@gmail.com> +* [jxm262](https://github.com/jxm262) - +**Justin Maat** <jxm262@gmail.com> +* [ljharb](https://github.com/ljharb) - +**Jordan Harband** <ljharb@gmail.com> ## Escalation of Issues diff --git a/README.md b/README.md index 62af604..caf864b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/tools/lint-readme-lists.mjs b/tools/lint-readme-lists.mjs new file mode 100755 index 0000000..b5a7722 --- /dev/null +++ b/tools/lint-readme-lists.mjs @@ -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; + } +} +