diff --git a/apps/codestyle/codestyle.py b/apps/codestyle/codestyle.py index 50c5fe3dd..ac5af08a5 100644 --- a/apps/codestyle/codestyle.py +++ b/apps/codestyle/codestyle.py @@ -1,6 +1,7 @@ import io import os import sys +import re # Get the src directory of the project src_directory = os.path.join(os.getcwd(), 'src') @@ -11,6 +12,7 @@ results = { "Multiple blank lines check": "Passed", "Trailing whitespace check": "Passed", "GetCounter() check": "Passed", + "Misc codestyle check": "Passed", "GetTypeId() check": "Passed", "NpcFlagHelpers check": "Passed", "ItemFlagHelpers check": "Passed", @@ -29,6 +31,7 @@ def parsing_file(directory: str) -> None: multiple_blank_lines_check(file, file_path) trailing_whitespace_check(file, file_path) get_counter_check(file, file_path) + misc_codestyle_check(file, file_path) if file_name != 'Object.h': get_typeid_check(file, file_path) if file_name != 'Unit.h': @@ -184,7 +187,7 @@ def itemtemplateflag_helpers_check(file: io, file_path: str) -> None: for line_number, line in enumerate(file, start = 1): if 'Flags & ITEM_FLAG' in line: print( - f"Please use HasFlag(ItemFlag) instead of 'Flags & ITEM_FLAG_' {file_path} at line {line_number}") + f"Please use HasFlag(ItemFlag) instead of 'Flags & ITEM_FLAG_': {file_path} at line {line_number}") check_failed = True if 'Flags2 & ITEM_FLAG2' in line: print( @@ -199,5 +202,25 @@ def itemtemplateflag_helpers_check(file: io, file_path: str) -> None: error_handler = True results["ItemTemplateFlagHelpers check"] = "Failed" +# Codestyle patterns checking for various codestyle issues +def misc_codestyle_check(file: io, file_path: str) -> None: + global error_handler, results + file.seek(0) # Reset file pointer to the beginning + check_failed = False + # Parse all the file + for line_number, line in enumerate(file, start = 1): + if 'const auto&' in line: + print( + f"Please use 'auto const&' syntax instead of 'const auto&': {file_path} at line {line_number}") + check_failed = True + if re.search(r'\bconst\s+\w+\s*\*\b', line): + print( + f"Please use the syntax 'Class/ObjectType const*' instead of 'const Class/ObjectType*': {file_path} at line {line_number}") + check_failed = True + # Handle the script error and update the result output + if check_failed: + error_handler = True + results["Misc codestyle check"] = "Failed" + # Main function parsing_file(src_directory) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index c1c1e372e..97593309f 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -7739,7 +7739,7 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type) // remove FD and invisibility at all loots constexpr std::array toRemove = {SPELL_AURA_MOD_INVISIBILITY, SPELL_AURA_FEIGN_DEATH}; - for (const auto& aura : toRemove) + for (auto const& aura : toRemove) { RemoveAurasByType(aura); } diff --git a/src/server/game/Entities/Player/SocialMgr.cpp b/src/server/game/Entities/Player/SocialMgr.cpp index e66f52629..d5b5fdf59 100644 --- a/src/server/game/Entities/Player/SocialMgr.cpp +++ b/src/server/game/Entities/Player/SocialMgr.cpp @@ -29,7 +29,7 @@ PlayerSocial::PlayerSocial(): m_playerGUID() { } uint32 PlayerSocial::GetNumberOfSocialsWithFlag(SocialFlag flag) const { uint32 counter = 0; - for (const auto& itr : m_playerSocialMap) + for (auto const& itr : m_playerSocialMap) { if ((itr.second.Flags & flag) != 0) ++counter; @@ -178,7 +178,7 @@ void PlayerSocial::SendSocialList(Player* player, uint32 flags) bool PlayerSocial::_checkContact(ObjectGuid guid, SocialFlag flags) const { - const auto& itr = m_playerSocialMap.find(guid); + auto const& itr = m_playerSocialMap.find(guid); if (itr != m_playerSocialMap.end()) return (itr->second.Flags & flags) != 0; diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 9d2e77854..5d0fd1a0c 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -2657,7 +2657,7 @@ bool Unit::GetMeleeAttackPoint(Unit* attacker, Position& pos) double attackerSize = attacker->GetCollisionRadius(); - for (const auto& otherAttacker: attackers) + for (auto const& otherAttacker: attackers) { // if the otherAttacker is not valid, skip if (!otherAttacker || otherAttacker->GetGUID() == attacker->GetGUID() || diff --git a/src/server/game/Movement/Spline/Spline.cpp b/src/server/game/Movement/Spline/Spline.cpp index 601951a20..59086cc1a 100644 --- a/src/server/game/Movement/Spline/Spline.cpp +++ b/src/server/game/Movement/Spline/Spline.cpp @@ -71,7 +71,7 @@ namespace Movement 1.f, 0.f, 0.f, 0.f); /* classic view: - inline void C_Evaluate(const Vector3 *vertice, float t, const float (&matrix)[4][4], Vector3 &position) + inline void C_Evaluate(Vector3 const* vertice, float t, const float (&matrix)[4][4], Vector3 &position) { Vector3 tvec(t*t*t, t*t, t); int i = 0; diff --git a/src/server/game/Warden/Warden.h b/src/server/game/Warden/Warden.h index ba53a54ca..5b256993c 100644 --- a/src/server/game/Warden/Warden.h +++ b/src/server/game/Warden/Warden.h @@ -127,8 +127,8 @@ public: void DecryptData(uint8* buffer, uint32 length); void EncryptData(uint8* buffer, uint32 length); - static bool IsValidCheckSum(uint32 checksum, const uint8 *data, const uint16 length); - static uint32 BuildChecksum(const uint8 *data, uint32 length); + static bool IsValidCheckSum(uint32 checksum, uint8 const* data, const uint16 length); + static uint32 BuildChecksum(uint8 const* data, uint32 length); // If no check is passed, the default action from config is executed void ApplyPenalty(uint16 checkId, std::string const& reason); diff --git a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/blackrock_depths.cpp b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/blackrock_depths.cpp index 50f7d26fb..214b92355 100644 --- a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/blackrock_depths.cpp +++ b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/blackrock_depths.cpp @@ -303,7 +303,7 @@ public: bool doReset = false; if (resetTimer > 0) { - for (const auto& sum : summons) + for (auto const& sum : summons) { if (Creature* creature = ObjectAccessor::GetCreature(*me, sum)) { diff --git a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/instance_blackrock_depths.cpp b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/instance_blackrock_depths.cpp index 014531fa2..1e7dde565 100644 --- a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/instance_blackrock_depths.cpp +++ b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockDepths/instance_blackrock_depths.cpp @@ -471,7 +471,7 @@ public: SetData(TYPE_RING_OF_LAW, NOT_STARTED); break; case DONE: - for (const auto& itr : ArenaSpectators) + for (auto const& itr : ArenaSpectators) { if (Creature* spectator = instance->GetCreature(itr)) { diff --git a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/boss_solakar_flamewreath.cpp b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/boss_solakar_flamewreath.cpp index f820384c8..39cb7594e 100644 --- a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/boss_solakar_flamewreath.cpp +++ b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/boss_solakar_flamewreath.cpp @@ -83,7 +83,7 @@ public: } GetCreatureListWithEntryInGrid(nearbyWhelps, me, NPC_ROOKERY_WHELP, RANGE_WHELP_CALL_HELP); - for (const auto& whelp : nearbyWhelps) + for (auto const& whelp : nearbyWhelps) { if (!whelp->IsInCombat()) { @@ -106,7 +106,7 @@ public: minDist = 50; tempDist = 50; me->GetGameObjectListWithEntryInGrid(nearbyEggs, GO_ROOKERY_EGG, 40); - for (const auto& egg : nearbyEggs) + for (auto const& egg : nearbyEggs) { if (egg->isSpawned() && egg->getLootState() == GO_READY) { diff --git a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/instance_blackrock_spire.cpp b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/instance_blackrock_spire.cpp index fc06b6222..cff24c081 100644 --- a/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/instance_blackrock_spire.cpp +++ b/src/server/scripts/EasternKingdoms/BlackrockMountain/BlackrockSpire/instance_blackrock_spire.cpp @@ -401,14 +401,14 @@ public: pile->SetLootState(GO_READY); pile->Respawn(); } - for (const auto& circleGUID : go_urokOgreCirles) + for (auto const& circleGUID : go_urokOgreCirles) { if (GameObject* circle = instance->GetGameObject(circleGUID)) { circle->Delete(); } } - for (const auto& mobGUID : UrokMobs) + for (auto const& mobGUID : UrokMobs) { if (Creature* mob = instance->GetCreature(mobGUID)) { diff --git a/src/server/scripts/Kalimdor/DireMaul/instance_dire_maul.cpp b/src/server/scripts/Kalimdor/DireMaul/instance_dire_maul.cpp index fdf47189b..52d569572 100644 --- a/src/server/scripts/Kalimdor/DireMaul/instance_dire_maul.cpp +++ b/src/server/scripts/Kalimdor/DireMaul/instance_dire_maul.cpp @@ -120,7 +120,7 @@ public: immol->GetAI()->SetData(1, 1); immol->RemoveUnitFlag(UNIT_FLAG_NON_ATTACKABLE); } - for (const auto& guid : HighborneSummoners) + for (auto const& guid : HighborneSummoners) { if (Creature* summoner = instance->GetCreature(guid)) { diff --git a/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_cthun.cpp b/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_cthun.cpp index 0162d8cbb..ec8a985f2 100644 --- a/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_cthun.cpp +++ b/src/server/scripts/Kalimdor/TempleOfAhnQiraj/boss_cthun.cpp @@ -386,7 +386,7 @@ struct boss_cthun : public BossAI }, 500ms); //Spawn flesh tentacle - for (const auto& position : FleshTentaclePos) + for (auto const& position : FleshTentaclePos) me->SummonCreature(NPC_FLESH_TENTACLE, position, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 5000); ScheduleTasks(); @@ -501,7 +501,7 @@ struct boss_cthun : public BossAI me->RemoveAurasDueToSpell(SPELL_PURPLE_COLORATION); DoCastSelf(SPELL_CARAPACE_CTHUN, true); //Spawn flesh tentacle - for (const auto& position : FleshTentaclePos) + for (auto const& position : FleshTentaclePos) me->SummonCreature(NPC_FLESH_TENTACLE, position, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 5000); }); } diff --git a/src/server/scripts/Northrend/Naxxramas/boss_gluth.cpp b/src/server/scripts/Northrend/Naxxramas/boss_gluth.cpp index c3fd79e3a..cea3baccf 100644 --- a/src/server/scripts/Northrend/Naxxramas/boss_gluth.cpp +++ b/src/server/scripts/Northrend/Naxxramas/boss_gluth.cpp @@ -159,7 +159,7 @@ public: return false; Map::PlayerList const& pList = me->GetMap()->GetPlayers(); - for (const auto& itr : pList) + for (auto const& itr : pList) { Player* player = itr.GetSource(); if (!player || !player->IsAlive()) diff --git a/src/server/scripts/Northrend/Naxxramas/boss_gothik.cpp b/src/server/scripts/Northrend/Naxxramas/boss_gothik.cpp index d2ebea1ae..b5211f913 100644 --- a/src/server/scripts/Northrend/Naxxramas/boss_gothik.cpp +++ b/src/server/scripts/Northrend/Naxxramas/boss_gothik.cpp @@ -387,7 +387,7 @@ public: { bool checklife = false; bool checkdead = false; - for (const auto& i : PlayerList) + for (auto const& i : PlayerList) { Player* player = i.GetSource(); if (player->IsAlive() && diff --git a/src/server/scripts/Northrend/Naxxramas/boss_heigan.cpp b/src/server/scripts/Northrend/Naxxramas/boss_heigan.cpp index 6ed38b2c5..5dd6374b0 100644 --- a/src/server/scripts/Northrend/Naxxramas/boss_heigan.cpp +++ b/src/server/scripts/Northrend/Naxxramas/boss_heigan.cpp @@ -228,7 +228,7 @@ public: case EVENT_SAFETY_DANCE: { Map::PlayerList const& pList = me->GetMap()->GetPlayers(); - for (const auto& itr : pList) + for (auto const& itr : pList) { if (IsInRoom(itr.GetSource()) && !itr.GetSource()->IsAlive()) { diff --git a/src/server/scripts/Northrend/Naxxramas/boss_sapphiron.cpp b/src/server/scripts/Northrend/Naxxramas/boss_sapphiron.cpp index acad7283e..8ecc62f56 100644 --- a/src/server/scripts/Northrend/Naxxramas/boss_sapphiron.cpp +++ b/src/server/scripts/Northrend/Naxxramas/boss_sapphiron.cpp @@ -142,7 +142,7 @@ public: if (PlList.IsEmpty()) return; - for (const auto& i : PlList) + for (auto const& i : PlList) { if (Player* player = i.GetSource()) { @@ -400,7 +400,7 @@ public: case EVENT_HUNDRED_CLUB: { Map::PlayerList const& pList = me->GetMap()->GetPlayers(); - for (const auto& itr : pList) + for (auto const& itr : pList) { if (itr.GetSource()->GetResistance(SPELL_SCHOOL_FROST) > 100 && pInstance) { diff --git a/src/server/scripts/Spells/spell_hunter.cpp b/src/server/scripts/Spells/spell_hunter.cpp index 378604983..f4bfef0e9 100644 --- a/src/server/scripts/Spells/spell_hunter.cpp +++ b/src/server/scripts/Spells/spell_hunter.cpp @@ -671,7 +671,7 @@ class spell_hun_readiness : public SpellScript std::set> spellsToRemove; std::set categoriesToRemove; - for (const auto& [spellId, cooldown] : cooldowns) + for (auto const& [spellId, cooldown] : cooldowns) { SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId); if (spellInfo @@ -689,9 +689,9 @@ class spell_hun_readiness : public SpellScript } // we can't remove spell cooldowns while iterating. - for (const auto& [spellId, sendToClient] : spellsToRemove) + for (auto const& [spellId, sendToClient] : spellsToRemove) caster->RemoveSpellCooldown(spellId, sendToClient); - for (const auto& category : categoriesToRemove) + for (auto const& category : categoriesToRemove) caster->RemoveCategoryCooldown(category); } diff --git a/src/server/shared/Packets/ByteBuffer.h b/src/server/shared/Packets/ByteBuffer.h index 308b6d728..1b005826e 100644 --- a/src/server/shared/Packets/ByteBuffer.h +++ b/src/server/shared/Packets/ByteBuffer.h @@ -464,14 +464,14 @@ public: _storage.shrink_to_fit(); } - void append(const char *src, std::size_t cnt) + void append(char const* src, std::size_t cnt) { - return append((const uint8 *)src, cnt); + return append((uint8 const*)src, cnt); } template void append(const T* src, std::size_t cnt) { - return append((const uint8*)src, cnt * sizeof(T)); + return append((uint8 const*)src, cnt * sizeof(T)); } void append(uint8 const* src, std::size_t cnt); @@ -522,7 +522,7 @@ public: } void AppendPackedTime(time_t time); - void put(std::size_t pos, const uint8 *src, std::size_t cnt); + void put(std::size_t pos, uint8 const* src, std::size_t cnt); void print_storage() const; void textlike() const; void hexlike() const;