Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ steps:

echo "--- :rust: Ensuring Code Conforms to rustfmt"
make fmt-check-rust

echo "--- :json: Ensuring JSON Test Fixtures are Pretty-Printed"
make fmt-check-json
- label: ":rust: Build Docs"
command: |
echo "--- :rust: Building Documentation"
Expand Down
10 changes: 9 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ stop-server:
@# Help: Stop the running server.
docker-compose down

lint: lint-rust lint-swift
lint: lint-rust lint-swift fmt-check-json
@# Help: Run the linter for all languages.

lint-rust:
Expand All @@ -264,6 +264,14 @@ lint-swift:

lintfix-swift: fmt-swift

fmt-json:
@# Help: Format all JSON test fixtures with 2-space indent.
@./scripts/check-json-formatting.sh --fix

fmt-check-json:
@# Help: Check that all JSON test fixtures are pretty-printed.
@./scripts/check-json-formatting.sh

fmt-rust:
$(rust_docker_run) /bin/bash -c "rustup component add rustfmt && cargo fmt"

Expand Down
46 changes: 46 additions & 0 deletions scripts/check-json-formatting.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/bash
#
# Check that JSON test fixtures are pretty-printed (2-space indent via jq).
# Usage:
# ./scripts/check-json-formatting.sh # check mode (exit 1 on failure)
# ./scripts/check-json-formatting.sh --fix # rewrite files in place

set -euo pipefail

fix=false
if [[ "${1:-}" == "--fix" ]]; then
fix=true
fi

failed=false

while IFS= read -r -d '' file; do
# Strip BOM if present — jq handles it, but we want consistent output
contents=$(sed '1s/^\xef\xbb\xbf//' "$file")

formatted=$(echo "$contents" | jq .) || {
echo "Invalid JSON: $file"
failed=true
continue
}

actual=$(cat "$file")
if [[ "$actual" != "$formatted" ]]; then
if $fix; then
echo "$formatted" > "$file"
echo "Fixed: $file"
else
echo "Not properly formatted: $file"
failed=true
fi
fi
done < <(find wp_api/tests test-data -name '*.json' -print0 | sort -z)

if $failed; then
echo
echo "Some JSON files are not properly formatted."
echo "Run 'make fmt-json' to fix them."
exit 1
elif ! $fix; then
echo "All JSON test fixtures are properly formatted."
fi
2 changes: 1 addition & 1 deletion test-data/api-details/test-case-01.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
{
"name": "Site with BOM",
"description": "Site with BOM",
"url": "https://example.com",
Expand Down
Loading