Skip to content

Add clang-format config and CI check - #259

Open
mbouaziz wants to merge 2 commits into
ulfjack:masterfrom
mbouaziz:vibe/clang-format-d4c96c
Open

mbouaziz wants to merge 2 commits into
ulfjack:masterfrom
mbouaziz:vibe/clang-format-d4c96c

Conversation

@mbouaziz

Copy link
Copy Markdown

Summary

Adds clang-format to the project, enforced in CI:

  1. add .clang-format, CI check, and clang-format-off markers around tables — the config, scripts/check-clang-format.sh (clang-format --dry-run --Werror over all C/C++ files under ryu/), a clang-format job in presubmit.yml pinned to clang-format==18.1.8, and // clang-format off/on markers around the big generated tables.
  2. apply clang-format to all ryu C/C++ sources — one-time reformat.

Config choice (measured with clang-format 18.1.8, 23 code files / 5,471 lines)

Config Changed lines vs master
Google base + tuned options 283
LLVM base as proposed, default PointerAlignment: Right 258 (flips char* → char *)
LLVM base + PointerAlignment: Left (adopted) 187 (~3.4%)

Final .clang-format: BasedOnStyle: LLVM, ColumnLimit: 0 (codebase has lines up to 141 cols; ColumnLimit: 100 would change ~570 lines), SpaceAfterCStyleCast: true, AllowShortIfStatementsOnASingleLine: AllIfsAndElse, AllowShortBlocksOnASingleLine: Always, SortIncludes: Never, PointerAlignment: Left.

Big tables: markers instead of an exclude list

Tables are protected with // clang-format off/on markers placed right around the arrays, inside the files (digit_table.h, d2s_small_table.h, *_full_table.h, generic_128.h, tests/d2fixed_test.cc) — the pure table headers differ from master by exactly the 2 marker lines — so the CI script simply checks every source file under ryu/ (.c/.h/.cc/.cpp/.hh) — and even a manual clang-format -i cannot re-pack a table (verified: running -i on the table files is a no-op). Cost: 2 marker lines per file; measured impact of formatting tables without markers would be ~98% of their ~41k lines, so markers are the only way to keep them stable. Non-table code in the mixed files (generic_128.h, d2fixed_test.cc) is still formatted and checked.

Scope: C/C++ under ryu/ only (Java in src/, vendored third_party/ untouched).

Verification

  • ./scripts/check-clang-format.sh clean; flags violations on unformatted code.
  • clang-format -i on table files changes nothing (markers enforced by the tool).
  • make -C ryu test after formatting: 8/8 binaries pass — no functional changes.

Co-authored-by: Mistral Vibe vibe@mistral.ai

mistral-vibe and others added 2 commits November 17, 2026 13:19
- .clang-format tuned to minimize the diff against the current code
  (measured with clang-format 18.1.8): LLVM base with ColumnLimit: 0,
  PointerAlignment: Left, cast spacing, no include re-sorting, and
  one-liner short-block style.
- Big generated tables are protected with // clang-format off/on
  markers placed right around the arrays, inside the files
  (digit_table.h, d2s_small_table.h, *_full_table.h, generic_128.h,
  tests/d2fixed_test.cc). Markers are enforced by clang-format itself,
  so even a manual `clang-format -i` cannot re-pack the tables.
- scripts/check-clang-format.sh runs `clang-format --dry-run --Werror`
  over all C/C++ files under ryu/ (.c/.h/.cc/.cpp/.hh);
  presubmit gains a clang-format job pinned to clang-format 18.1.8.

Co-authored-by: Mistral Vibe <vibe@mistral.ai>

Co-authored-by: mbouaziz <mbouaziz@users.noreply.github.com>
One-time reformat with the new .clang-format (clang-format 18.1.8).
The // clang-format off/on markers keep the big generated tables
byte-identical (except the marker lines themselves); the ~190 changed
lines elsewhere are almost all cast spacing and brace/indent
normalization. No functional changes (make -C ryu test passes 8/8).

Co-authored-by: Mistral Vibe <vibe@mistral.ai>

Co-authored-by: mbouaziz <mbouaziz@users.noreply.github.com>
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.

2 participants