Skip to content

docs: Add code standard guidelines for #include#1229

Open
NoxMax wants to merge 2 commits into
azerothcore:masterfrom
NoxMax:master
Open

docs: Add code standard guidelines for #include#1229
NoxMax wants to merge 2 commits into
azerothcore:masterfrom
NoxMax:master

Conversation

@NoxMax

@NoxMax NoxMax commented Jul 14, 2026

Copy link
Copy Markdown

Description

The codebase is (mostly) consistent in the way includes are formatted. Now there are formal guidelines. Most critically highlighting that headers need to self-contained, but also what order includes should be added in for ease of readability.

Related Issue

Closes

Thank you for contributing to the AzerothCore wiki.

Remember that the wiki is currently available in English and Spanish.

Summary by CodeRabbit

  • Documentation
    • Clarified C++ code standards for whitespace and within-bracket spacing.
    • Added guidance that each header is self-contained (compilable without prior includes).
    • Documented a strict #include block order: own header first, then project headers alphabetically, then library headers alphabetically (with an example).

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@NoxMax, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 34 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d7054b52-de9f-4ab4-bb3c-9bff30ccc4ea

📥 Commits

Reviewing files that changed from the base of the PR and between faaf59c and c4c979c.

📒 Files selected for processing (1)
  • docs/cpp-code-standards.md
📝 Walkthrough

Walkthrough

The C++ code standards document refines bracket-spacing guidance and adds an Includes section covering self-contained headers, required include ordering, an example include block, and case-sensitive alphabetical sorting.

Changes

C++ Standards Documentation

Layer / File(s) Summary
Whitespace and include guidance
docs/cpp-code-standards.md
Refines the bracket-spacing rule and documents self-contained headers, include-block ordering, an ItemEnchantmentMgr.cpp example, and case-sensitive alphabetical ordering.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding C++ code standard guidelines for #include directives.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@docs/cpp-code-standards.md`:
- Line 56: Update the bracket-spacing rule in the C++ standards documentation to
explicitly cover parentheses, square brackets, and braces, rather than using the
ambiguous term “bracket.” Keep the existing guidance about avoiding unnecessary
spaces within these delimiters.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 7e9f551a-e439-418c-93bb-23668f5bf441

📥 Commits

Reviewing files that changed from the base of the PR and between ad1574e and 71aff8a.

📒 Files selected for processing (1)
  • docs/cpp-code-standards.md

Trailing whitespace is not allowed.

You should also not have unneeded spaces within a bracket.
You should also not have unneeded spaces within a bracket.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Clarify which delimiters this rule covers.

“Bracket” is ambiguous here, while the examples only demonstrate parentheses. Specify parentheses, square brackets, and braces to make the rule unambiguous.

Proposed wording
-You should also not have unneeded spaces within a bracket.
+You should also avoid unneeded spaces inside parentheses, square brackets, and braces.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
You should also not have unneeded spaces within a bracket.
You should also avoid unneeded spaces inside parentheses, square brackets, and braces.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/cpp-code-standards.md` at line 56, Update the bracket-spacing rule in
the C++ standards documentation to explicitly cover parentheses, square
brackets, and braces, rather than using the ambiguous term “bracket.” Keep the
existing guidance about avoiding unnecessary spaces within these delimiters.

Comment on lines +347 to +348
#include "DBCStores.h" // then project headers, alphabetically
#include "DatabaseEnv.h"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should be the other way around

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

With ASCII sorting? It is essentially sorting "D B C Stores" then "Database Env". D will come before Database.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We have, to my knowledge, always enforced alphabetical sorting

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It is always alphabetical, but question is whether its case sensitive alphabetical (ASCII) or insensitive. ASCII sort will place DBCStores sort first. Insensitive will treat it both the same as "dbcstores" and "databaseenv", which would place DatabaseEnv first. Other codebase examples similar to what's in ItemEnchantmentMgr.cpp
ConditionMgr.cpp:

#include "ScriptMgr.h"
#include "ScriptedCreature.h"

GroupHandler.cpp:

#include "LFGMgr.h"
#include "Language.h"

Beyond my general observation, I asked Claude to do an actual analysis of sort orders. It did find examples where sorting is case insensitive. GridTerrainLoader.cpp:

#include "Map.h"
#include "MMapMgr.h"

But the vast majority of examples it found (127 vs 5) favoured case sensitive sorting.

Comment on lines +346 to +356
#include "ItemEnchantmentMgr.h" // The file's own header, first
#include "DBCStores.h" // then project headers, alphabetically
#include "DatabaseEnv.h"
#include "Log.h"
#include "ObjectMgr.h"
#include "QueryResult.h"
#include "Timer.h"
#include "Util.h"
#include <cmath> // then library headers, alphabetically
#include <functional>
#include <vector>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should be project -> lib -> standard C headers

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

That would be the Google convention, but I tried to formalize the order based on what AC already uses, which is mostly LLVM. Every single case I found in the codebase, libraries were always in the bottom. Though if you and the other staff think the Google style is what AC should adopt and everything should be eventually changed to match, then yeah sure we can adopt that.

Personally I prefer Google, but I deferred to what's already there.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

isnt the google style lib/standard C at the top?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yeah it is. But without exception all the examples I found in AC place libraries at the bottom. Google also breaks the include block into sections https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes but AC uses a single block.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

perhaps I get it mixed and c standard should be before lib. probably doesnt matter

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

It's no more than a style choice. AC uses LLVM mostly with libs in the bottom, and its the other way around from Google. Ultimately though, yeah it's mostly about style consistency.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

then I dont care :P

Added guidelines for header file includes and ordering.
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