Skip to content

Format-check the documentation examples in CI - #5386

Merged
nlohmann merged 2 commits into
developfrom
claude/loving-chaum-14587d
Aug 20, 2026
Merged

Format-check the documentation examples in CI#5386
nlohmann merged 2 commits into
developfrom
claude/loving-chaum-14587d

Conversation

@nlohmann

@nlohmann nlohmann commented Aug 20, 2026

Copy link
Copy Markdown
Owner

The documentation examples have never been format-checked by CI. Both format checks pointed at docs/examples, a path that does not exist — the examples live in docs/mkdocs/docs/examples. In each case the missing path failed silently rather than erroring:

Location Failure mode
.github/workflows/check_amalgamation.yml find printed an error for the missing path and exited nonzero, but its status was swallowed by command substitution. astyle simply received a shorter file list and the step exited 0.
cmake/ci.cmake file(GLOB_RECURSE ...) over a missing directory silently yields nothing, so the ci_test_amalgamation target (still active via .github/workflows/ubuntu.yml) skipped the examples too.
.github/workflows/publish_documentation.yml Dead docs/examples/** path filter.

Both checks now resolve 231 example files, up from 0.

For publish_documentation.yml the filter was removed rather than repointed: docs/mkdocs/** is already listed and covers docs/mkdocs/docs/examples, so repointing would have been redundant.

Formatting fix

With the check repaired, make amalgamate reformats exactly one file that had drifted behind it: docs/mkdocs/docs/examples/parser_callback_t.cpp, where three lambda parameters read json & /*parsed*/ instead of json& /*parsed*/ (--align-reference=type).

To confirm nothing else had drifted in the meantime, astyle was run over the full 384-file post-fix list — no further changes — and no verbatim copies of the old spelling remain elsewhere in the docs.

Failing loudly on a future rename

A rename silently shrinking the file list is the root cause here, not the stale path itself. The workflow now checks each source directory exists before the find and fails with a GitHub error annotation if one does not:

::error::source directory 'docs/examples' does not exist

Verified in both directions: it passes on the current paths, and fails with exactly that message when fed the old one.

Guarding find's own exit status instead would not have been enough here without also adding set -o pipefail — this workflow uses the default bash -e {0} shell and the file list is piped through sort, so the pipeline reports sort's status, not find's.

Notes for reviewers

  • Commit order is deliberate. The formatting fix lands first so that each commit is green under its own CI configuration. Reversed, the intermediate commit would enable a check that fails on a file it had only just started looking at.
  • No local/CI gap for contributors. Since the check gets stricter, make pretty was compared against the new CI file list: it covers all 384 files plus the two amalgamated headers, which CI formats in the preceding astyle call. make amalgamate therefore remains a faithful local pre-check.

API impact

No breaking changes. This touches CI configuration and comment whitespace in one documentation example. No changes to any header, to single_include/, or to the public API. The amalgamated headers are unchanged by this PR.


  • The changes are described in detail, both the what and why.
  • If applicable, an existing issue is referenced. — n/a, no existing issue.
  • The Code coverage remained at 100%. A test case for every new line of code. — n/a, no library code changed.
  • If applicable, the documentation is updated. — example reformatted; rendered output is unchanged.
  • The source code is amalgamated by running make amalgamate.

This pull request was prepared by Claude Code.

The file uses "json & /*parsed*/" in three lambda parameter lists, which
astyle rewrites to "json& /*parsed*/" per --align-reference=type. The
drift went unnoticed because CI never format-checked the documentation
examples; "make pretty" does cover them.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
The examples live in docs/mkdocs/docs/examples, but both format checks
still referenced the long-gone docs/examples path:

- check_amalgamation.yml passed it to find, which printed an error for
  the missing path and carried on, so astyle only ever saw include and
  tests. The step still exited 0.
- ci.cmake globbed it into INDENT_FILES, and a GLOB_RECURSE over a
  missing directory silently yields nothing, so the ci_test_amalgamation
  target skipped the examples too.

Either way the 231 example files have never been format-checked. Point
both at the real path, and guard the workflow with an explicit directory
check so a future rename fails the job instead of quietly shrinking the
file list again.

Also drop the dead docs/examples/** path filter from
publish_documentation.yml; docs/mkdocs/** already covers the examples.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
@nlohmann nlohmann added this to the Release 3.13.0 milestone Aug 20, 2026
@nlohmann
nlohmann merged commit 734fd30 into develop Aug 20, 2026
157 of 158 checks passed
@nlohmann
nlohmann deleted the claude/loving-chaum-14587d branch August 20, 2026 10:32
nlohmann added a commit that referenced this pull request Aug 21, 2026
#5386 reformatted this example on develop and extended the CI format check to
cover docs/mkdocs/docs/examples, which this branch predates. astyle rewrites
"json & /*parsed*/" to "json& /*parsed*/" per --align-reference=type; the result
is byte-identical to develop's copy.

Signed-off-by: Niels Lohmann <mail@nlohmann.me>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant