Skip to content

ci: catch broken markdown links#403

Open
x-n2o wants to merge 3 commits into
ml-explore:mainfrom
x-n2o:markdown-link-check
Open

ci: catch broken markdown links#403
x-n2o wants to merge 3 commits into
ml-explore:mainfrom
x-n2o:markdown-link-check

Conversation

@x-n2o

@x-n2o x-n2o commented May 10, 2026

Copy link
Copy Markdown

Proposed changes

Adds a markdown link check to the existing pre-commit workflow so repository-local links are validated locally and in pull request CI. Per review feedback, this now uses a small local script (tools/check_links.py) instead of a third-party dependency — the same checker proposed in ml-explore/mlx-swift-examples#479; the two copies are kept in sync.

  • pre-commit passes the tracked markdown files to the script; links with a URL scheme or host are skipped — matching the previous offline lychee behavior without the extra dependency. The script also supports a manual whole-tree scan: python3 tools/check_links.py .
  • The earlier .lycheeignore is replaced by a .check-links-ignore blocklist (fnmatch globs, repo-root relative). Patterns skip both scanned files and link targets, covering the review feedback:
    • Third-party sources we don't build docs for are not scanned at all: Source/Cmlx/fmt/*, Source/Cmlx/json/*, Source/Cmlx/metal-cpp/* (this also silences false positives like C++ lambdas [=](auto out) in fmt's docs being parsed as markdown links).
    • DocC cross-doc-package links (mlx, mlxnn, mlxoptimizers) are not flagged — they resolve in the built documentation, not as repository files.
  • Links inside fenced code blocks are ignored, so the linkage example in MAINTENANCE.md is not flagged.

Unlike the examples repo (#479), no genuinely missing in-repo .md targets turned up: running the checker with an empty .check-links-ignore flags exactly the 7 links covered above — the fmt lambda and the six DocC cross-package links — all verified false positives, so there is nothing to track in issues here.

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING document
  • I have run pre-commit run --all-files to format my code / installed pre-commit prior to committing changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have updated the necessary documentation (if needed)

Local run:

❯ pre-commit run --all
swift-format.............................................................Passed
check markdown links.....................................................Passed
cmake-format.............................................................Passed

False-positive audit — with an empty .check-links-ignore, the whole-tree scan flags only the known false positives, no real missing files:

❯ python3 tools/check_links.py .

Source/Cmlx/fmt/doc/api.md:
  line 173: [=](auto out) -> NOT FOUND

Source/MLX/Documentation.docc/MLX.md:
  line 69: [MLXNN](mlxnn) -> NOT FOUND
  line 70: [MLXOptimizers](mlxoptimizers) -> NOT FOUND

Source/MLXNN/Documentation.docc/MLXNN.md:
  line 46: [MLX](mlx) -> NOT FOUND
  line 47: [MLXOptimizers](mlxoptimizers) -> NOT FOUND

Source/MLXOptimizers/Documentation.docc/MLXOptimizers.md:
  line 34: [MLX](mlx) -> NOT FOUND
  line 35: [MLXNN](mlxnn) -> NOT FOUND

Total: 7 broken link(s) in 4 file(s)

@x-n2o x-n2o marked this pull request as ready for review May 10, 2026 22:16
Copilot AI review requested due to automatic review settings May 10, 2026 22:16

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds an offline broken-Markdown-link check to the existing pre-commit-driven lint workflow (both locally and in CI) by introducing the lychee pre-commit hook, and updates the lint step wording to reflect the broader checks.

Changes:

  • Add lychee as a pre-commit hook (offline) to detect broken links in Markdown files.
  • Update the CI lint step name/message to mention Markdown link checks.
  • Add an acknowledgment entry for the contributor who introduced the link checks.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
ACKNOWLEDGMENTS.md Adds contributor acknowledgment for the new Markdown link checks.
.pre-commit-config.yaml Introduces the lychee hook configured for offline Markdown link checking.
.github/workflows/pull_request.yml Renames the lint step and updates the failure message to include Markdown link checks.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .pre-commit-config.yaml Outdated
Comment thread .github/workflows/pull_request.yml
@davidkoski

Copy link
Copy Markdown
Collaborator

This looks interesting, but:

This is a third party and we don't build docs for this -- we shouldn't be checking this.

[Source/Cmlx/fmt/doc/index.md]:
 [ERROR] file:///Users/ledio/src/mlx-swift/Source/Cmlx/fmt/doc/api#compile-api (at 60:12) | File not found. Check if file exists and path is correct
 [ERROR] file:///Users/ledio/src/mlx-swift/Source/Cmlx/fmt/doc/api#compile-time-checks (at 27:10) | File not found. Check if file exists and path is correct
 [ERROR] file:///Users/ledio/src/mlx-swift/Source/Cmlx/fmt/doc/api#format (at 23:52) | File not found. Check if file exists and path is correct
 [ERROR] file:///Users/ledio/src/mlx-swift/Source/Cmlx/fmt/doc/api#udt (at 46:10) | File not found. Check if file exists and path is correct

These links do resolve -- they are cross doc package links, see: https://swiftpackageindex.com/ml-explore/mlx-swift/main/documentation/mlx

[Source/MLX/Documentation.docc/MLX.md]:
 [ERROR] file:///Users/ledio/src/mlx-swift/Source/MLX/Documentation.docc/mlxnn (at 69:3) | File not found. Check if file exists and path is correct
 [ERROR] file:///Users/ledio/src/mlx-swift/Source/MLX/Documentation.docc/mlxoptimizers (at 70:3) | File not found. Check if file exists and path is correct

[Source/MLXNN/Documentation.docc/MLXNN.md]:
 [ERROR] file:///Users/ledio/src/mlx-swift/Source/MLXNN/Documentation.docc/mlx (at 46:3) | File not found. Check if file exists and path is correct
 [ERROR] file:///Users/ledio/src/mlx-swift/Source/MLXNN/Documentation.docc/mlxoptimizers (at 47:3) | File not found. Check if file exists and path is correct

[Source/MLXOptimizers/Documentation.docc/MLXOptimizers.md]:
 [ERROR] file:///Users/ledio/src/mlx-swift/Source/MLXOptimizers/Documentation.docc/mlx (at 34:3) | File not found. Check if file exists and path is correct
 [ERROR] file:///Users/ledio/src/mlx-swift/Source/MLXOptimizers/Documentation.docc/mlxnn (at 35:3) | File not found. Check if file exists and path is correct

@x-n2o

x-n2o commented May 11, 2026

Copy link
Copy Markdown
Author

Ah, I suppose this would require a gating mechanism or a mutli-repo checkout (overengineering?). I found .lycheeignore. I'll add the third-parties that resolve on swiftpackageindex.com/ml-explore.

@x-n2o x-n2o force-pushed the markdown-link-check branch from fe623f6 to a6fce24 Compare May 11, 2026 15:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants