From 6c988a2ac80e693fb2fd1c05b9c41552663df322 Mon Sep 17 00:00:00 2001 From: Martin Leduc <31558169+DecimalTurn@users.noreply.github.com> Date: Sat, 18 Apr 2026 18:46:54 +0000 Subject: [PATCH] feat: ensure librairies and tools languages are listed alphabetically --- .github/workflows/check-tools-order.yml | 20 +++++++++ check-tools-order.js | 56 +++++++++++++++++++++++++ index.markdown | 23 +++++----- 3 files changed, 87 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/check-tools-order.yml create mode 100644 check-tools-order.js diff --git a/.github/workflows/check-tools-order.yml b/.github/workflows/check-tools-order.yml new file mode 100644 index 0000000..d78daa6 --- /dev/null +++ b/.github/workflows/check-tools-order.yml @@ -0,0 +1,20 @@ +name: Check Tools Order + +on: + pull_request: + +jobs: + check-tools-order: + runs-on: ubuntu-latest + + steps: + - name: Checkout + uses: actions/checkout@v5 + + - name: Setup Node.js + uses: actions/setup-node@v5 + with: + node-version: 20 + + - name: Validate tools and libraries order + run: node check-tools-order.js \ No newline at end of file diff --git a/check-tools-order.js b/check-tools-order.js new file mode 100644 index 0000000..f8b6532 --- /dev/null +++ b/check-tools-order.js @@ -0,0 +1,56 @@ +#!/usr/bin/env node + +const fs = require("fs"); +const path = require("path"); + +const filePath = path.join(__dirname, "index.markdown"); +const content = fs.readFileSync(filePath, "utf8"); + +// Extract the "Tools and Libraries" section +const sectionMatch = content.match(/## Tools and Libraries([\s\S]*?)(?=\n## |\n#+ |$)/); +if (!sectionMatch) { + console.error("Could not find the 'Tools and Libraries' section."); + process.exit(1); +} + +const section = sectionMatch[1]; + +// Extract language headers (lines like **Language**) +const languageRegex = /^\*\*(.+?)\*\*/gm; +const languages = []; +let match; +while ((match = languageRegex.exec(section)) !== null) { + languages.push(match[1]); +} + +if (languages.length === 0) { + console.error("No language headers found in the 'Tools and Libraries' section."); + process.exit(1); +} + +console.log("Languages found:"); +languages.forEach((lang, i) => console.log(` ${i + 1}. ${lang}`)); +console.log(); + +// Check alphabetical order (case-insensitive) +let inOrder = true; +for (let i = 1; i < languages.length; i++) { + const prev = languages[i - 1].toLowerCase(); + const curr = languages[i].toLowerCase(); + if (curr < prev) { + console.error( + `Ordering error: "${languages[i]}" should appear before "${languages[i - 1]}".`, + ); + inOrder = false; + } +} + +if (inOrder) { + console.log("All languages are listed in alphabetical order."); +} else { + console.error(); + console.error( + "The 'Tools and Libraries' section must stay in alphabetical order.", + ); + process.exit(1); +} diff --git a/index.markdown b/index.markdown index e0b05e0..80b9778 100644 --- a/index.markdown +++ b/index.markdown @@ -106,9 +106,6 @@ Several tools and libraries support JSONC, enabling developers to parse and gene Here is a non-exhaustive list: -**JavaScript/TypeScript**: -- [microsoft/node-jsonc-parser](https://github.com/microsoft/node-jsonc-parser) - **C++** - [stephenberry/glaze](https://github.com/stephenberry/glaze) @@ -118,25 +115,27 @@ Here is a non-exhaustive list: **Go** - [tidwall/jsonc](https://github.com/tidwall/jsonc) -**Python** -- [n-takumasa/json-with-comments](https://github.com/n-takumasa/json-with-comments) +**Java** +- [Jackson](https://github.com/FasterXML/jackson-core) `JsonFactory.enable(JsonReadFeature.ALLOW_JAVA_COMMENTS)` + +**JavaScript/TypeScript**: +- [microsoft/node-jsonc-parser](https://github.com/microsoft/node-jsonc-parser) + +**Kotlin** +- [kotlinx.serialization.json](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-json/kotlinx.serialization.json/-json-builder/allow-comments.html) **PHP** - [otar/jsonc](https://github.com/otar/jsonc) +**Python** +- [n-takumasa/json-with-comments](https://github.com/n-takumasa/json-with-comments) + **Rust** - [dprint/jsonc-parser](https://github.com/dprint/jsonc-parser) **Swift** - [steelbrain/JSONCKit](https://github.com/steelbrain/JSONCKit) -**Java** -- [Jackson](https://github.com/FasterXML/jackson-core) `JsonFactory.enable(JsonReadFeature.ALLOW_JAVA_COMMENTS)` - -**Kotlin** -- [kotlinx.serialization.json](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-json/kotlinx.serialization.json/-json-builder/allow-comments.html) - - ## APPENDIX A: Trailing Commas and JSONC ### Why Trailing Commas Are Not a Requirement?