style: apply automated formatting baseline with clang-format#2638
style: apply automated formatting baseline with clang-format#2638DevGeniusCode wants to merge 6 commits into
Conversation
|
| Filename | Overview |
|---|---|
| .clang-format | New clang-format baseline config; Standard: c++20 (not yet changed to c++03 as promised) causes /* */ insertion into template declarations; missing AlignConsecutiveDeclarations conflicts with team style rule. |
| Core/GameEngine/Source/Common/System/GameMemory.cpp | Automated whitespace/brace reformatting; /* */ injected into UsedNPeakMap typedef; IndentPPDirectives: BeforeHash causes #ifdef directives to indent while their enclosed code stays at column 0. |
| Core/GameEngine/Include/Common/AsciiString.h | Formatting-only changes; column-aligned struct member declarations (m_refCount, m_numCharsAllocated) are un-aligned by the formatter. |
| Core/GameEngine/Include/Common/GameCommon.h | Formatting-only changes; CPP_11(: Int) macro invocations gain a space before the colon (CPP_11( : Int)); code inside #if blocks is de-indented to column 0. |
| Generals/Code/GameEngine/Include/Common/Player.h | Formatting-only changes; /* */ injected into PlayerRelationMapType typedef template closing brackets. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A["Source Files\n369 .cpp/.h"] --> B["clang-format\nwith .clang-format config"]
B --> C{"Standard: c++20\nstill active"}
C -->|"template closing brackets\n> > found"| D["Insert /* */ separator\nbetween > and >"]
C -->|"normal formatting"| E["Apply Allman braces\nLeft pointer alignment\nTab indentation"]
D --> F["Typedef declarations\ne.g. std::map< /* */>\nClass inheritance lists"]
E --> G["AlignConsecutiveDeclarations\nnot set → removes column alignment"]
E --> H["IndentPPDirectives: BeforeHash\n→ #ifdef indented, code at col 0"]
F --> I["Formatted output\nwith embedded /* */ comments"]
G --> I
H --> I
Prompt To Fix All With AI
Fix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
.clang-format:63-64
**`/* */` injected into hundreds of template type declarations**
Because `Standard: c++20` is still active, the formatter merges `> >` into `>>` in template closing brackets — then inserts a `/* */` empty comment as a separator to keep the code compiling (e.g., `std::map<const char*, UsedNPeak, std::less<const char*> /* */> UsedNPeakMap`). This appears in 30+ typedef declarations, member variable types, and class inheritance lists throughout the codebase. While C++-valid, it permanently embeds empty comments into semantic code, contradicting the PR's stated "do no harm" goal. This is a direct consequence of `Standard: c++20` not yet having been changed to `c++03` as acknowledged in the previous review thread.
### Issue 2 of 2
.clang-format:38-39
The formatter is removing column-aligned struct member declarations that the team's style guide explicitly requires to be aligned. Without `AlignConsecutiveDeclarations`, every future formatter run will strip any manual alignment added by developers (e.g., `m_refCount` / `m_numCharsAllocated` in `AsciiStringData`), creating a permanent conflict between the formatter and the team's alignment rule.
```suggestion
AlignTrailingComments: false
SpacesBeforeTrailingComments: 4
AlignConsecutiveDeclarations: Consecutive
```
Reviews (5): Last reviewed commit: "style: format multi-line macros with una..." | Re-trigger Greptile
a9d279e to
9ddb58a
Compare
|
There are still a few formatting improvements I haven’t addressed in this pass, such as consecutive assignment alignment. Current (Before): AudioAffect_Music = 0x01,
AudioAffect_Sound = 0x02,
AudioAffect_Sound3D = 0x04,
AudioAffect_All = (Music | Sound | Sound3D),Target (After): AudioAffect_Music = 0x01,
AudioAffect_Sound = 0x02,
AudioAffect_Sound3D = 0x04,
AudioAffect_All = (Music | Sound | Sound3D),If there is interest, I can implement it |
Core\GameEngine)Core\GameEngine)
This is good. |
Core\GameEngine)|
Updated |
This comment was marked as resolved.
This comment was marked as resolved.
xezon
left a comment
There was a problem hiding this comment.
Looks very promising again. I like the minimal formatting on this first pass. Just a few more things to polish.
| if you define MEMORYPOOL_INTENSE_VERIFY, we do intensive verifications after | ||
| nearly every memory operation. this is OFF by default, since it slows down | ||
| things a lot, but is worth turning on for really obscure memory corruption issues. | ||
| */ |
There was a problem hiding this comment.
The block macros are indented with 2 spaces instead of tabs. In the github page they will show with different indent width.
| */ | ||
| * Closes the current file if it is open. | ||
| * Must call LocalFile::close() for each successful LocalFile::open() call. | ||
| */ |
There was a problem hiding this comment.
Also strange that here the block comment has only 1 leading space.
14366de to
e19a3a9
Compare
|
Updated |
Prerequisites: Please Merge First
This PR is the final step of the formatting baseline. It depends on two preliminary structural PRs that must be merged first to ensure a clean, 100% automated formatting pass without breaking VC6 compilation:
>>merging in C++98.Objective
This PR introduces a minimalist, non-destructive
.clang-formatbaseline. To make this easy to review and discuss, I have scoped the formatting only to the.\Core\GameEnginedirectory.The "Do No Harm" Approach
The primary goal of this configuration is to avoid the "destructive" behavior of standard formatters.
ColumnLimit: 0: Automatic line wrapping is completely disabled. Clang-format will respect our manual line breaks and will not pack or split arguments unexpectedly.What is being formatted?
To establish a consistent baseline, the formatter enforces a few core rules:
Why this change was made -now-:
clang-formatfundamentally requires a brace style to function; it cannot simply "ignore" braces even on a pure whitespace pass. Since running the tool was inevitably going to touch braces and affect line counts anyway, I decided to "go all in" and establish a fully consistent style across the board, rather than trying to fight the tool to maintain an inconsistent legacy mix.void* ptr).AlignTrailingComments: false) with a fixed 5-space offset. This prevents "diff pollution" (the ripple effect where adding one long function name forces all surrounding comments to shift).\) are left-aligned (AlignEscapedNewlines: DontAlign) with a single space. This eliminates the "mixed whitespace" anti-pattern and ensures macros render perfectly straight in GitHub and all IDEs, regardless of the user's tab width setting.Legacy / VC6 Compatibility
A lot of effort went into making sure this doesn't break our legacy support:
Standard: c++20to correctly parse modern syntax while maintaining VC6 compatibility structurally.AttributeMacrosandMacros) to safely parse ourCPP_11enum macros without breaking the formatting tree.AllowShortBlocksOnASingleLine: Alwaysso macros and empty stubs aren't vertically bloated.Future Phases (Minimizing the Initial Diff)
Please note that several settings in this baseline (such as
SortIncludes: false,AllowShortFunctionsOnASingleLine: All, andAllowShortBlocksOnASingleLine: Always) are intentionally included purely to minimize the initial diff and avoid overwhelming changes.