|
| 1 | +# clang-format config for cforge itself. |
| 2 | +# Project-only — does not propagate to user projects that consume cforge. |
| 3 | +# Targets clang-format >= 18 (LLVM 18+). Anything older silently falls back |
| 4 | +# to defaults on unknown keys. |
| 5 | +# |
| 6 | +# Design goals (in order): |
| 7 | +# 1. Maximum readability — alignment ON wherever it doesn't fight reality. |
| 8 | +# 2. Matches the style the codebase already converged on: 2-space, attached |
| 9 | +# braces, right-aligned pointers, no namespace indent, C++17. |
| 10 | +# 3. Stable diffs — line breaks driven by structure, not by character count |
| 11 | +# shifting around. |
| 12 | +# |
| 13 | +# Apply with: cforge fmt |
| 14 | +# Verify with: cforge fmt --check |
| 15 | + |
| 16 | +--- |
| 17 | +Language: Cpp |
| 18 | +BasedOnStyle: LLVM |
| 19 | +Standard: c++17 |
| 20 | + |
| 21 | +# ── Layout ──────────────────────────────────────────────────────────────── |
| 22 | +ColumnLimit: 100 |
| 23 | +IndentWidth: 2 |
| 24 | +TabWidth: 2 |
| 25 | +UseTab: Never |
| 26 | +ContinuationIndentWidth: 4 |
| 27 | +ConstructorInitializerIndentWidth: 4 |
| 28 | +AccessModifierOffset: -2 |
| 29 | +NamespaceIndentation: None |
| 30 | +FixNamespaceComments: true |
| 31 | +ShortNamespaceLines: 0 |
| 32 | +IndentCaseLabels: true |
| 33 | +IndentExternBlock: NoIndent |
| 34 | +IndentPPDirectives: None # leave #include at col 0 even inside |
| 35 | + # #ifdef __cplusplus / extern "C" blocks |
| 36 | +LambdaBodyIndentation: Signature |
| 37 | +PPIndentWidth: -1 |
| 38 | + |
| 39 | +# ── Braces ──────────────────────────────────────────────────────────────── |
| 40 | +# Attached braces (Stroustrup with one-liners disabled). Matches existing code. |
| 41 | +BreakBeforeBraces: Attach |
| 42 | +Cpp11BracedListStyle: true |
| 43 | +InsertBraces: true # forces {} around single-statement ifs |
| 44 | +RemoveBracesLLVM: false # ...but never strips them |
| 45 | + |
| 46 | +# ── Short-form lines ────────────────────────────────────────────────────── |
| 47 | +# Single-line if/for/while hurt grep-ability and step-through debugging. |
| 48 | +# Only collapse the genuinely trivial: empty blocks and inline accessors. |
| 49 | +AllowShortBlocksOnASingleLine: Empty |
| 50 | +AllowShortCaseLabelsOnASingleLine: false |
| 51 | +AllowShortEnumsOnASingleLine: false |
| 52 | +AllowShortFunctionsOnASingleLine: InlineOnly |
| 53 | +AllowShortIfStatementsOnASingleLine: Never |
| 54 | +AllowShortLambdasOnASingleLine: Inline |
| 55 | +AllowShortLoopsOnASingleLine: false |
| 56 | +CompactNamespaces: false |
| 57 | + |
| 58 | +# ── Line breaking ───────────────────────────────────────────────────────── |
| 59 | +AllowAllArgumentsOnNextLine: true |
| 60 | +AllowAllParametersOfDeclarationOnNextLine: true |
| 61 | +AlwaysBreakAfterReturnType: None |
| 62 | +AlwaysBreakBeforeMultilineStrings: false |
| 63 | +AlwaysBreakTemplateDeclarations: Yes |
| 64 | +BinPackArguments: false # each arg its own line when wrapped |
| 65 | +BinPackParameters: false # each param its own line when wrapped |
| 66 | +BreakAfterAttributes: Leave |
| 67 | +BreakBeforeBinaryOperators: NonAssignment |
| 68 | +BreakBeforeConceptDeclarations: Always |
| 69 | +BreakBeforeTernaryOperators: true |
| 70 | +BreakConstructorInitializers: BeforeColon |
| 71 | +BreakInheritanceList: BeforeColon |
| 72 | +BreakStringLiterals: true |
| 73 | +ExperimentalAutoDetectBinPacking: false |
| 74 | +PackConstructorInitializers: NextLine |
| 75 | + |
| 76 | +# ── Alignment (this is where readability lives) ─────────────────────────── |
| 77 | +AlignAfterOpenBracket: Align |
| 78 | +AlignArrayOfStructures: Left |
| 79 | +AlignConsecutiveAssignments: |
| 80 | + Enabled: true |
| 81 | + AcrossEmptyLines: false |
| 82 | + AcrossComments: false |
| 83 | + AlignCompound: true |
| 84 | + PadOperators: true |
| 85 | +AlignConsecutiveBitFields: |
| 86 | + Enabled: true |
| 87 | + AcrossEmptyLines: false |
| 88 | + AcrossComments: false |
| 89 | +AlignConsecutiveDeclarations: |
| 90 | + Enabled: false # OFF: turning this on makes filesystem::path & co. |
| 91 | + # push other names off the right margin badly. |
| 92 | +AlignConsecutiveMacros: |
| 93 | + Enabled: true |
| 94 | + AcrossEmptyLines: false |
| 95 | + AcrossComments: false |
| 96 | +AlignEscapedNewlines: Left |
| 97 | +AlignOperands: AlignAfterOperator |
| 98 | +AlignTrailingComments: |
| 99 | + Kind: Always |
| 100 | + OverEmptyLines: 0 |
| 101 | +DerivePointerAlignment: false |
| 102 | +PointerAlignment: Right |
| 103 | +ReferenceAlignment: Pointer |
| 104 | +QualifierAlignment: Leave |
| 105 | + |
| 106 | +# ── Spacing ─────────────────────────────────────────────────────────────── |
| 107 | +SpaceAfterCStyleCast: false |
| 108 | +SpaceAfterLogicalNot: false |
| 109 | +SpaceAfterTemplateKeyword: true |
| 110 | +SpaceAroundPointerQualifiers: Default |
| 111 | +SpaceBeforeAssignmentOperators: true |
| 112 | +SpaceBeforeCaseColon: false |
| 113 | +SpaceBeforeCpp11BracedList: false |
| 114 | +SpaceBeforeCtorInitializerColon: true |
| 115 | +SpaceBeforeInheritanceColon: true |
| 116 | +SpaceBeforeParens: ControlStatements |
| 117 | +SpaceBeforeRangeBasedForLoopColon: true |
| 118 | +SpaceBeforeSquareBrackets: false |
| 119 | +SpaceInEmptyBlock: false |
| 120 | +SpaceInEmptyParentheses: false |
| 121 | +SpacesBeforeTrailingComments: 2 |
| 122 | +SpacesInAngles: Never |
| 123 | +SpacesInCStyleCastParentheses: false |
| 124 | +SpacesInConditionalStatement: false |
| 125 | +SpacesInContainerLiterals: false |
| 126 | +SpacesInLineCommentPrefix: |
| 127 | + Minimum: 1 |
| 128 | + Maximum: -1 |
| 129 | +SpacesInParentheses: false |
| 130 | +SpacesInSquareBrackets: false |
| 131 | +BitFieldColonSpacing: Both |
| 132 | + |
| 133 | +# ── Blank lines / vertical density ──────────────────────────────────────── |
| 134 | +KeepEmptyLinesAtTheStartOfBlocks: false |
| 135 | +MaxEmptyLinesToKeep: 1 |
| 136 | +SeparateDefinitionBlocks: Always |
| 137 | +EmptyLineAfterAccessModifier: Never |
| 138 | +EmptyLineBeforeAccessModifier: LogicalBlock |
| 139 | + |
| 140 | +# ── Comments / strings ──────────────────────────────────────────────────── |
| 141 | +ReflowComments: true |
| 142 | + |
| 143 | +# ── #include handling ───────────────────────────────────────────────────── |
| 144 | +# Group order: matching .hpp (Priority 0), then cforge public, then cforge |
| 145 | +# internal, then 3rd-party (fmt, toml++), then C++ std, then C std. Regroup |
| 146 | +# rewrites the blocks; SortIncludes keeps each block alphabetical. |
| 147 | +SortIncludes: CaseSensitive |
| 148 | +IncludeBlocks: Regroup |
| 149 | +IncludeCategories: |
| 150 | + - Regex: '^"cforge/[^"]+"' # public API headers |
| 151 | + Priority: 2 |
| 152 | + SortPriority: 2 |
| 153 | + - Regex: '^"core/[^"]+"' # internal headers |
| 154 | + Priority: 3 |
| 155 | + SortPriority: 3 |
| 156 | + - Regex: '^<(fmt|toml\+\+|tomlplusplus)/[^>]+>' |
| 157 | + Priority: 4 |
| 158 | + SortPriority: 4 |
| 159 | + - Regex: '^<[a-z_]+>' # C++ std (no extension) |
| 160 | + Priority: 5 |
| 161 | + SortPriority: 5 |
| 162 | + - Regex: '^<.*\.h>' # C std / system |
| 163 | + Priority: 6 |
| 164 | + SortPriority: 6 |
| 165 | + - Regex: '.*' |
| 166 | + Priority: 7 |
| 167 | + SortPriority: 7 |
| 168 | +IncludeIsMainRegex: '(_test|_bench)?$' |
| 169 | + |
| 170 | +# ── Other ───────────────────────────────────────────────────────────────── |
| 171 | +SortUsingDeclarations: true |
| 172 | +StatementMacros: |
| 173 | + - CF_SELECTANY # COMDAT-folding helper from test_runner |
| 174 | + - CF_MAYBE_UNUSED |
| 175 | + - TEST # cforge builtin test framework macro |
| 176 | + - BENCH # cforge builtin bench framework macro |
| 177 | +TypenameMacros: [] |
| 178 | +WhitespaceSensitiveMacros: |
| 179 | + - STRINGIZE |
| 180 | + - PP_STRINGIZE |
| 181 | + - BOOST_PP_STRINGIZE |
| 182 | + |
| 183 | +# ── Penalties (tune for stable, sensible wraps) ─────────────────────────── |
| 184 | +PenaltyBreakAssignment: 25 |
| 185 | +PenaltyBreakBeforeFirstCallParameter: 50 |
| 186 | +PenaltyBreakComment: 300 |
| 187 | +PenaltyBreakFirstLessLess: 120 |
| 188 | +PenaltyBreakOpenParenthesis: 0 |
| 189 | +PenaltyBreakString: 1000 |
| 190 | +PenaltyBreakTemplateDeclaration: 10 |
| 191 | +PenaltyExcessCharacter: 1000000 |
| 192 | +PenaltyIndentedWhitespace: 0 |
| 193 | +PenaltyReturnTypeOnItsOwnLine: 200 |
0 commit comments