Skip to content

Commit 734fd30

Browse files
authored
Format-check the documentation examples in CI (#5386)
* Reformat parser_callback_t example with astyle 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> * Format-check the documentation examples in CI 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> --------- Signed-off-by: Niels Lohmann <mail@nlohmann.me>
1 parent 36187ca commit 734fd30

4 files changed

Lines changed: 15 additions & 6 deletions

File tree

.github/workflows/check_amalgamation.yml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,18 @@ jobs:
6767
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=none --quiet \
6868
$INCLUDE_DIR/json.hpp $INCLUDE_DIR/json_fwd.hpp
6969
70+
# fail loudly if a directory is renamed or removed: find would only warn
71+
# about the missing path and silently drop its files from the check
72+
SOURCE_DIRS="docs/mkdocs/docs/examples include tests"
73+
for DIR in $SOURCE_DIRS; do
74+
if [ ! -d "$DIR" ]; then
75+
echo "::error::source directory '$DIR' does not exist"
76+
exit 1
77+
fi
78+
done
79+
7080
${{ github.workspace }}/venv/bin/astyle --project=tools/astyle/.astylerc --suffix=none --quiet \
71-
$(find docs/examples include tests -type f \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' \) -not -path 'tests/thirdparty/*' -not -path 'tests/abi/include/nlohmann/*' | sort)
81+
$(find $SOURCE_DIRS -type f \( -name '*.hpp' -o -name '*.cpp' -o -name '*.cu' \) -not -path 'tests/thirdparty/*' -not -path 'tests/abi/include/nlohmann/*' | sort)
7282
7383
- name: Build patch and check for differences
7484
id: diff

.github/workflows/publish_documentation.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ on:
77
- develop
88
paths:
99
- docs/mkdocs/**
10-
- docs/examples/**
1110
workflow_dispatch:
1211

1312
# we don't want to have concurrent jobs, and we don't want to cancel running jobs to avoid broken publications

cmake/ci.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ file(GLOB_RECURSE INDENT_FILES
294294
${PROJECT_SOURCE_DIR}/tests/src/*.cpp
295295
${PROJECT_SOURCE_DIR}/tests/src/*.hpp
296296
${PROJECT_SOURCE_DIR}/tests/benchmarks/src/benchmarks.cpp
297-
${PROJECT_SOURCE_DIR}/docs/examples/*.cpp
297+
${PROJECT_SOURCE_DIR}/docs/mkdocs/docs/examples/*.cpp
298298
)
299299

300300
set(include_dir ${PROJECT_SOURCE_DIR}/single_include/nlohmann)

docs/mkdocs/docs/examples/parser_callback_t.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ int main()
99
auto text = R"({"IDs": [116, 943], "Width": 800})";
1010

1111
// discard the array when the parser reads its opening bracket
12-
json j_array_start = json::parse(text, [](int /*depth*/, json::parse_event_t event, json & /*parsed*/)
12+
json j_array_start = json::parse(text, [](int /*depth*/, json::parse_event_t event, json& /*parsed*/)
1313
{
1414
return event != json::parse_event_t::array_start;
1515
});
1616

1717
// discard the same array when the parser reads its closing bracket
18-
json j_array_end = json::parse(text, [](int /*depth*/, json::parse_event_t event, json & /*parsed*/)
18+
json j_array_end = json::parse(text, [](int /*depth*/, json::parse_event_t event, json& /*parsed*/)
1919
{
2020
return event != json::parse_event_t::array_end;
2121
});
@@ -33,7 +33,7 @@ int main()
3333
});
3434

3535
// discard the top-level object
36-
json j_root = json::parse(text, [](int /*depth*/, json::parse_event_t event, json & /*parsed*/)
36+
json j_root = json::parse(text, [](int /*depth*/, json::parse_event_t event, json& /*parsed*/)
3737
{
3838
return event != json::parse_event_t::object_end;
3939
});

0 commit comments

Comments
 (0)