-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tools: add a linter for markdown lists (#892)
- Loading branch information
Showing
4 changed files
with
76 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|