Skip to content

Commit 5109d36

Browse files
authored
Link checker and documentation updates (#264)
* Link checker and documentation updates * check links script
1 parent 92b6b40 commit 5109d36

File tree

5 files changed

+423
-19
lines changed

5 files changed

+423
-19
lines changed

.github/markdown-link-check.jsonc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@
77
}
88
}
99
],
10+
"ignorePatterns": [
11+
{ "pattern": "^#" },
12+
{ "pattern": "https://www\\.st\\.com/en/development-tools/hardware-debugger-and-programmer-tools-for-stm32/products\\.html" }
13+
]
1014
}

DEVELOPMENT.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,30 @@ Tool dependencies are recorded in `package.json`:
8686
````
8787
8888
The `<version>` must match the tools release version tag.
89+
90+
## Updating documentation
91+
92+
Contributors who make changes to the documentation are encouraged to validate their updates using the
93+
Markdown linter to ensure consistency and adherence to the project's formatting standards.
94+
95+
Run the following command from the project root:
96+
97+
```bash
98+
yarn lint:md
99+
````
100+
101+
This command checks Markdown files against the linting rules defined in the
102+
[markdownlint.jsonc](./.github/markdownlint.jsonc) configuration file.
103+
104+
Any formatting issues or deviations from the defined standards will be reported in the console. Addressing these helps
105+
maintain high-quality, readable, and standardized documentation across the project.
106+
107+
Additionally, if your changes involve updating or adding links within the documentation, you can verify the validity
108+
of all links by running:
109+
110+
```bash
111+
yarn check:links
112+
````
113+
114+
This will check each link to ensure it is reachable (i.e., returns a 200 OK status). Identifying and correcting broken
115+
links contributes to a better reader experience and ensures long-term reliability of the documentation.

package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,8 @@
221221
"test": "jest",
222222
"package": "vsce package --yarn",
223223
"tpip:report": "ts-node scripts/tpip-reporter --header docs/tpip-header.md docs/third-party-licenses.json TPIP.md",
224-
"lint:md": "markdownlint **/*.md -c ./.github/markdownlint.jsonc -i ./node_modules ./dist ./coverage ./tools"
224+
"lint:md": "markdownlint **/*.md -c ./.github/markdownlint.jsonc -i ./node_modules ./dist ./coverage ./tools",
225+
"check:links": "ts-node scripts/check-links.ts -i ./node_modules/** -i ./.github/** -c ./.github/markdown-link-check.jsonc"
225226
},
226227
"vsce": {
227228
"yarn": true,
@@ -243,8 +244,10 @@
243244
"@yarnpkg/lockfile": "^1.1.0",
244245
"eslint": "^9.26.0",
245246
"extract-zip": "^2.0.1",
247+
"globby": "^13.2.2",
246248
"jest": "^29.7.0",
247249
"markdownlint-cli": "^0.45.0",
250+
"markdown-link-check": "^3.13.7",
248251
"node-fetch": "^3.3.2",
249252
"octokit": "^4.1.3",
250253
"tempfile": "^5.0.0",

scripts/check-links.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!npx ts-node
2+
3+
/**
4+
* Copyright 2025 Arm Limited
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
import { execFile } from "child_process";
20+
import { promisify } from "util";
21+
import { resolve } from "path";
22+
import yargs from "yargs";
23+
import { hideBin } from "yargs/helpers";
24+
25+
const execFileAsync = promisify(execFile);
26+
27+
async function main() {
28+
const argv = yargs(hideBin(process.argv))
29+
.option("config", {
30+
alias: "c",
31+
type: "string",
32+
description: "Path to markdown-link-check config file"
33+
})
34+
.option("ignore", {
35+
alias: "i",
36+
type: "array",
37+
description: "Directories to ignore",
38+
default: ["node_modules/**"],
39+
})
40+
.help()
41+
.alias("help", "h")
42+
.parseSync();
43+
44+
const { globby } = await import("globby");
45+
const ignorePatterns = (argv.ignore as string[]).map((pattern) => `!${pattern}`);
46+
const configPath = resolve(argv.config as string);
47+
const mdFiles = await globby(["**/*.md", ...ignorePatterns]);
48+
49+
if (mdFiles.length === 0) {
50+
console.log("No markdown files found.");
51+
return;
52+
}
53+
54+
console.log(`Checking ${mdFiles.length} markdown file(s)...`);
55+
for (const file of mdFiles) {
56+
try {
57+
const { stdout } = await execFileAsync(
58+
"npx", ["markdown-link-check", "-v", "-c", configPath, file], { shell: true }
59+
);
60+
console.log(stdout);
61+
} catch (err: any) {
62+
console.error(`Error in file: ${file}`);
63+
console.error(err.stdout || err.message);
64+
process.exitCode = 1;
65+
}
66+
}
67+
}
68+
69+
main().catch((error) => {
70+
console.error(error);
71+
process.exit(1);
72+
});

0 commit comments

Comments
 (0)