.clang-format: リポジトリ実態に合わせてリファイン - #75
Merged
Merged
Conversation
CLion 生成のままだった設定を ccbench の実コードスタイルに合わせて更新。 - IndentWidth を 4 から 2 へ (実コードは全面的に 2-space indent。 4 のままだと全ファイルが大量 reformat 対象になっていた) - TabWidth / AccessModifierOffset / ContinuationIndentWidth を 2-space ベースに整合 - Standard: c++20 を明示 (本リポは C++20) - DerivePointerAlignment: false を明示し PointerAlignment: Left を固定 - SortIncludes: false を明示 (include 順は一部 load-bearing なため別途対応) - 非デフォルト/曖昧なオプションを整理しコメントを付与 clang-format 14 想定。clang-format --dump-config でパース可能なことを確認。 このリポの clang-format 自体への準拠は #63 で CI 化を検討中。
This was referenced May 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概要
リポジトリ直下の
.clang-formatは CLion が生成したままで、ccbench の実コードスタイルと乖離していた。実態に合わせてリファインし、現代的でメンテしやすい設定に更新する。背景: 設定が実態と合っていなかった
cc/include/common/の C++ ソースは 全面的に 2-space indent だが、旧.clang-formatはIndentWidth: 4だった。このため設定どおりに format すると全ファイルが大量に書き換わる状態になっていた (leading-space ヒストグラムでも 2 の倍数が圧倒的多数)。変更したオプションと理由
IndentWidth4→2TabWidth4→2ContinuationIndentWidth8→4AccessModifierOffset-4→-2public:/private:はメンバから 1 段外。実測で -2 が diff 最小AllowShortIfStatementsOnASingleLineAlways→WithoutElseelse付きは展開する方が実態に近い (実測で diff 減)Standardc++20DerivePointerAlignmentfalsePointerAlignment: Leftをファイル間で固定SortIncludesfalseinclude/common.hhを先頭に置く protocol .cc など)。並べ替えは別途対応clang-format 14 (devcontainer /
ubuntu:24.04同梱バージョン) で有効なオプションのみ使用。clang-format --dump-configがエラーなくパースできることを確認済み。方針: 「設定ファイルの質を上げる」ことが目的であり、「コードを大量 reformat させる」ことではない。今回の変更はむしろ設定を実態に寄せることで reformat 量を 大幅に削減 する。
before/after の計測
対象:
find cc include common -type f \( -name '*.cc' -o -name '*.hh' -o -name '*.cpp' \)(242 ファイル)dry-run 違反ファイル数
違反ファイル数は増えていない (むしろ微減)。
format 時の総変更行数 (設定が実態にどれだけ合っているかの指標)
IndentWidthの修正だけで reformat 量が半分以下になり、設定が実態に大きく近づいたことを示す。test plan
clang-format --dump-configがエラーなくパースできるclang-format --dry-run --Werrorをcc/ include/ common/全ソース (242 ファイル) に対して実行し、違反ファイル数を計測 (before 222 → after 215、増加なし)IndentWidth/AccessModifierOffset/ContinuationIndentWidth/AllowShortIfStatementsOnASingleLineの候補値を実測比較し、diff 最小の組み合わせを採用関連