From 31350e3203806aed1f6a746b4b903d864caa79f5 Mon Sep 17 00:00:00 2001 From: Richard Littauer Date: Tue, 18 Feb 2025 10:19:02 +1300 Subject: [PATCH] Adding rule for open source for linting --- markdownlint-custom-rules.js | 26 ++++++++++++++++++++++++++ package-lock.json | 15 +++++++++++++++ package.json | 2 +- 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 markdownlint-custom-rules.js diff --git a/markdownlint-custom-rules.js b/markdownlint-custom-rules.js new file mode 100644 index 0000000..693a864 --- /dev/null +++ b/markdownlint-custom-rules.js @@ -0,0 +1,26 @@ +"use strict"; + +module.exports = { + names: ["no-hyphenated-open-source"], + description: "Ensure 'open source' is not written as 'open-source'.", + tags: ["wording", "consistency"], + function: function noHyphenatedOpenSource(params, onError) { + params.lines.forEach((line, index) => { + const lineNumber = index + 1; + const match = line.match(/\b open-source \b/); // Find "open-source" + + if (match) { + onError({ + lineNumber: lineNumber, + detail: "Use 'open source' instead of 'open-source'.", + context: line.trim(), // Provide surrounding text + fixInfo: { + editColumn: match.index + 1, // Position in the line + deleteCount: match[0].length, + insertText: " open source ", + }, + }); + } + }); + }, +}; diff --git a/package-lock.json b/package-lock.json index 53bfcbe..e98a6cf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -7,6 +7,9 @@ "": { "name": "academic-map", "version": "1.0.0", + "dependencies": { + "markdownlint-rule-helpers": "^0.28.0" + }, "devDependencies": { "markdown-link-check": "^3.12.2", "markdownlint": "^0.36.1" @@ -664,6 +667,18 @@ "url": "https://github.com/sponsors/DavidAnson" } }, + "node_modules/markdownlint-rule-helpers": { + "version": "0.28.0", + "resolved": "https://registry.npmjs.org/markdownlint-rule-helpers/-/markdownlint-rule-helpers-0.28.0.tgz", + "integrity": "sha512-qBOQWESmc/yTNe6nVu3D7AU7pFg2e7T5svbQI+S7rocw4g4xZ3GHerKPl0Rw0cx4fnAViEdzoAcbrxeuXUCEAA==", + "license": "MIT", + "engines": { + "node": ">=18" + }, + "funding": { + "url": "https://github.com/sponsors/DavidAnson" + } + }, "node_modules/marked": { "version": "12.0.2", "resolved": "https://registry.npmjs.org/marked/-/marked-12.0.2.tgz", diff --git a/package.json b/package.json index 4ced300..18fe811 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "scripts": { "build": "jupyter-book build --all .", "publish": "./build.sh", - "lint": "markdownlint . -i _build/ -i node_modules", + "lint": "markdownlint . -i _build/ -i node_modules --rules markdownlint-custom-rules.js", "lint-fix": "markdownlint --fix . -i _build/ -i node_modules", "links": "markdown-link-check ./*.md -c mdlinkcheckconfig.json && markdown-link-check ./**/*.md -c mdlinkcheckconfig.json", "links-ci": "markdown-link-check -q ./*.md -c mdlinkcheckconfig.json && markdown-link-check ./**/*.md -q -c mdlinkcheckconfig.json",