Skip to content

style: Convert leading spaces to tabs in Core and Dependencies#2561

Open
bobtista wants to merge 7 commits intoTheSuperHackers:mainfrom
bobtista:bobtista/feat/access-spec-indent-core
Open

style: Convert leading spaces to tabs in Core and Dependencies#2561
bobtista wants to merge 7 commits intoTheSuperHackers:mainfrom
bobtista:bobtista/feat/access-spec-indent-core

Conversation

@bobtista
Copy link
Copy Markdown

@bobtista bobtista commented Apr 9, 2026

Summary

  • Convert leading spaces/mixed whitespace to tabs, including access specifier indentation
  • All changes are whitespace-only (git diff -w is empty)
  • Uses tree-sitter-cpp for accurate C++ parsing with macro preprocessing

Access specifiers (public:/private:/protected:) are placed at the class
brace level, matching the existing codebase convention.

Script

The formatting script is included in the PR for reference but is not intended
to be merged — it shows how the changes were generated.

See scripts/cpp/convert_leading_spaces_to_tabs.py for details.

Part 1 of 4 — Core/ and Dependencies/ (499 files).
See also: #2562, #2563, #2564.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Apr 9, 2026

Greptile Summary

This PR performs a whitespace-only conversion of leading spaces to tabs across 499 C/C++ files in Core/ and Dependencies/, using a tree-sitter-based Python script for accurate AST-driven indentation. git diff -w is confirmed empty, so no logical changes are introduced.

Two minor issues were found:

  • Braceless else body under-indentation: In Network.cpp (6 cases) and ConnectionManager.cpp (5 cases), return 0.0; inside a braceless else clause was placed at the same tab level as the else keyword instead of one level deeper, creating a visually misleading layout.
  • Script inclusion vs. PR description: The conversion script is a new committed file despite the PR description stating it is not intended to be merged.

Confidence Score: 5/5

Safe to merge — all changes are whitespace-only with no functional impact; the two findings are minor style regressions.

git diff -w is empty (confirmed), so no logic is altered. The braceless else under-indentation is a cosmetic issue already present in mixed-whitespace form before this PR. The script inclusion is a documentation/policy question that does not affect build or runtime. All remaining findings are P2.

Core/GameEngine/Source/GameNetwork/Network.cpp and ConnectionManager.cpp for the braceless else indentation; scripts/cpp/convert_leading_spaces_to_tabs.py for the merge-intent question.

Important Files Changed

Filename Overview
scripts/cpp/convert_leading_spaces_to_tabs.py New utility script using tree-sitter to convert spaces→tabs; PR description says it should not be merged but the file is included in the diff.
Core/GameEngine/Source/GameNetwork/Network.cpp Whitespace-only conversion; braceless else bodies (6 instances) were under-indented — return 0.0; left at depth 1 instead of depth 2.
Core/GameEngine/Source/GameNetwork/ConnectionManager.cpp Whitespace-only conversion; 5 braceless else return 0.0; bodies share the same under-indentation regression as Network.cpp.
Core/GameEngine/Source/Common/System/AsciiString.cpp Whitespace-only conversion; mixed-whitespace va_start/va_end lines correctly normalized to 1 tab.
Core/GameEngine/Include/Common/AudioEventInfo.h Whitespace-only conversion; 2-space indented member declarations correctly converted to 1-tab indentation.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Read source file\ncp1252 encoding] --> B[Preprocess macros\nfor tree-sitter]
    B --> C[Parse with\ntree-sitter C++]
    C --> D{Too many\nparse errors?}
    D -->|yes| E[Skip file]
    D -->|no| F[For each line]
    F --> G{In block\ncomment?}
    G -->|yes| H[Keep as-is]
    G -->|no| I{Has leading\nspaces?}
    I -->|no| H
    I -->|yes| J[Find AST node\nat line start]
    J --> K{Continuation\nline or ERROR?}
    K -->|yes| H
    K -->|no| L[Compute indent\ndepth via AST walk]
    L --> M{Sanity check:\ndepth=0 but 4+ spaces?}
    M -->|fail| H
    M -->|pass| N[Replace leading ws\nwith N tabs]
    N --> O[Write converted file]
Loading
Prompt To Fix All With AI
This is a comment left during a code review.
Path: Core/GameEngine/Source/GameNetwork/Network.cpp
Line: 831

Comment:
**Braceless `else` body under-indented**

The `return 0.0;` inside a braceless `else` clause was converted to depth 1 (one tab) but should be at depth 2 (two tabs), matching the indentation of the `if`-branch body above it. This pattern appears 6 times in this file and 5 more times in `ConnectionManager.cpp`. The resulting layout is visually ambiguous — the `return 0.0` line sits at the same column as `else`, making it look like it's outside the `else` branch.

```suggestion
		return 0.0;
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: scripts/cpp/convert_leading_spaces_to_tabs.py
Line: 1

Comment:
**Script included in PR despite PR description saying it shouldn't be merged**

The PR description states: *"The formatting script is included in the PR for reference but is not intended to be merged."* However, `scripts/cpp/convert_leading_spaces_to_tabs.py` is a new file in this diff and will be committed to the repository. If the intent is to keep it out of the codebase, it should be removed from this branch. If the intent is to keep it as a reference utility in `scripts/`, the PR description should be updated to reflect that.

How can I resolve this? If you propose a fix, please make it concise.

Reviews (3): Last reviewed commit: "style: Fix indentation regressions flagg..." | Re-trigger Greptile

Copy link
Copy Markdown

@xezon xezon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By what rules are these whitespaces edited? How can it be reviewed?

//using the IMC_SETCOMPOSITIONWINDOW message.
//
//I'm not sure what to do here.
m_result = 1;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not look right.

return SEISMIC_STATUS_ACTIVE;
}
else
return SEISMIC_STATUS_ZERO_ENERGY;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This not good


// sanity
if( wallPiece == nullptr )
if( wallPiece == nullptr )
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 indent too much.

@bobtista
Copy link
Copy Markdown
Author

By what rules are these whitespaces edited? How can it be reviewed?

Leading whitespace is regenerated from the C++ AST, not counted from spaces. For more details on how it's done, check scripts/cpp/convert_leading_spaces_to_tabs.py it will:

  • Parse the file with tree-sitter-cpp
  • For any line whose leading whitespace contains a space, locate the AST node at the first non-whitespace column.
  • Walk up the AST counting "scope-creating" ancestors: compound_statement, field_declaration_list, declaration_list (namespace body), enumerator_list, initializer_list, case_statement. Add one level for the braceless body/consequence/alternative of if/while/for/do/else. A compound_statement directly under a case_statement does not add a level (the case already provides it).
  • Replace the leading whitespace with exactly that many tab characters.

It skips a bunch of things eg block comments, and things that are addressed in later PRs to make review easier. To review it, I'd make sure you like the approach in the script, then spot check the results.

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