chore(Apps/Codestyle): add new codestyle checks for pointers and range loops (#19841)

* chore(Apps/Codestyle): add new codestyle checks for pointers and range loops

* revert a typo
This commit is contained in:
Grimdhex 2024-09-03 18:02:38 +02:00 committed by GitHub
parent c929b95172
commit 221dbd3fdb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
18 changed files with 52 additions and 29 deletions

View file

@ -1,6 +1,7 @@
import io import io
import os import os
import sys import sys
import re
# Get the src directory of the project # Get the src directory of the project
src_directory = os.path.join(os.getcwd(), 'src') src_directory = os.path.join(os.getcwd(), 'src')
@ -11,6 +12,7 @@ results = {
"Multiple blank lines check": "Passed", "Multiple blank lines check": "Passed",
"Trailing whitespace check": "Passed", "Trailing whitespace check": "Passed",
"GetCounter() check": "Passed", "GetCounter() check": "Passed",
"Misc codestyle check": "Passed",
"GetTypeId() check": "Passed", "GetTypeId() check": "Passed",
"NpcFlagHelpers check": "Passed", "NpcFlagHelpers check": "Passed",
"ItemFlagHelpers check": "Passed", "ItemFlagHelpers check": "Passed",
@ -29,6 +31,7 @@ def parsing_file(directory: str) -> None:
multiple_blank_lines_check(file, file_path) multiple_blank_lines_check(file, file_path)
trailing_whitespace_check(file, file_path) trailing_whitespace_check(file, file_path)
get_counter_check(file, file_path) get_counter_check(file, file_path)
misc_codestyle_check(file, file_path)
if file_name != 'Object.h': if file_name != 'Object.h':
get_typeid_check(file, file_path) get_typeid_check(file, file_path)
if file_name != 'Unit.h': 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): for line_number, line in enumerate(file, start = 1):
if 'Flags & ITEM_FLAG' in line: if 'Flags & ITEM_FLAG' in line:
print( 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 check_failed = True
if 'Flags2 & ITEM_FLAG2' in line: if 'Flags2 & ITEM_FLAG2' in line:
print( print(
@ -199,5 +202,25 @@ def itemtemplateflag_helpers_check(file: io, file_path: str) -> None:
error_handler = True error_handler = True
results["ItemTemplateFlagHelpers check"] = "Failed" 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 # Main function
parsing_file(src_directory) parsing_file(src_directory)

View file

@ -7739,7 +7739,7 @@ void Player::SendLoot(ObjectGuid guid, LootType loot_type)
// remove FD and invisibility at all loots // remove FD and invisibility at all loots
constexpr std::array<AuraType, 2> toRemove = {SPELL_AURA_MOD_INVISIBILITY, SPELL_AURA_FEIGN_DEATH}; constexpr std::array<AuraType, 2> toRemove = {SPELL_AURA_MOD_INVISIBILITY, SPELL_AURA_FEIGN_DEATH};
for (const auto& aura : toRemove) for (auto const& aura : toRemove)
{ {
RemoveAurasByType(aura); RemoveAurasByType(aura);
} }

View file

@ -29,7 +29,7 @@ PlayerSocial::PlayerSocial(): m_playerGUID() { }
uint32 PlayerSocial::GetNumberOfSocialsWithFlag(SocialFlag flag) const uint32 PlayerSocial::GetNumberOfSocialsWithFlag(SocialFlag flag) const
{ {
uint32 counter = 0; uint32 counter = 0;
for (const auto& itr : m_playerSocialMap) for (auto const& itr : m_playerSocialMap)
{ {
if ((itr.second.Flags & flag) != 0) if ((itr.second.Flags & flag) != 0)
++counter; ++counter;
@ -178,7 +178,7 @@ void PlayerSocial::SendSocialList(Player* player, uint32 flags)
bool PlayerSocial::_checkContact(ObjectGuid guid, SocialFlag flags) const 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()) if (itr != m_playerSocialMap.end())
return (itr->second.Flags & flags) != 0; return (itr->second.Flags & flags) != 0;

View file

@ -2657,7 +2657,7 @@ bool Unit::GetMeleeAttackPoint(Unit* attacker, Position& pos)
double attackerSize = attacker->GetCollisionRadius(); double attackerSize = attacker->GetCollisionRadius();
for (const auto& otherAttacker: attackers) for (auto const& otherAttacker: attackers)
{ {
// if the otherAttacker is not valid, skip // if the otherAttacker is not valid, skip
if (!otherAttacker || otherAttacker->GetGUID() == attacker->GetGUID() || if (!otherAttacker || otherAttacker->GetGUID() == attacker->GetGUID() ||

View file

@ -71,7 +71,7 @@ namespace Movement
1.f, 0.f, 0.f, 0.f); 1.f, 0.f, 0.f, 0.f);
/* classic view: /* 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); Vector3 tvec(t*t*t, t*t, t);
int i = 0; int i = 0;

View file

@ -127,8 +127,8 @@ public:
void DecryptData(uint8* buffer, uint32 length); void DecryptData(uint8* buffer, uint32 length);
void EncryptData(uint8* buffer, uint32 length); void EncryptData(uint8* buffer, uint32 length);
static bool IsValidCheckSum(uint32 checksum, const uint8 *data, const uint16 length); static bool IsValidCheckSum(uint32 checksum, uint8 const* data, const uint16 length);
static uint32 BuildChecksum(const uint8 *data, uint32 length); static uint32 BuildChecksum(uint8 const* data, uint32 length);
// If no check is passed, the default action from config is executed // If no check is passed, the default action from config is executed
void ApplyPenalty(uint16 checkId, std::string const& reason); void ApplyPenalty(uint16 checkId, std::string const& reason);

View file

@ -303,7 +303,7 @@ public:
bool doReset = false; bool doReset = false;
if (resetTimer > 0) if (resetTimer > 0)
{ {
for (const auto& sum : summons) for (auto const& sum : summons)
{ {
if (Creature* creature = ObjectAccessor::GetCreature(*me, sum)) if (Creature* creature = ObjectAccessor::GetCreature(*me, sum))
{ {

View file

@ -471,7 +471,7 @@ public:
SetData(TYPE_RING_OF_LAW, NOT_STARTED); SetData(TYPE_RING_OF_LAW, NOT_STARTED);
break; break;
case DONE: case DONE:
for (const auto& itr : ArenaSpectators) for (auto const& itr : ArenaSpectators)
{ {
if (Creature* spectator = instance->GetCreature(itr)) if (Creature* spectator = instance->GetCreature(itr))
{ {

View file

@ -83,7 +83,7 @@ public:
} }
GetCreatureListWithEntryInGrid(nearbyWhelps, me, NPC_ROOKERY_WHELP, RANGE_WHELP_CALL_HELP); GetCreatureListWithEntryInGrid(nearbyWhelps, me, NPC_ROOKERY_WHELP, RANGE_WHELP_CALL_HELP);
for (const auto& whelp : nearbyWhelps) for (auto const& whelp : nearbyWhelps)
{ {
if (!whelp->IsInCombat()) if (!whelp->IsInCombat())
{ {
@ -106,7 +106,7 @@ public:
minDist = 50; minDist = 50;
tempDist = 50; tempDist = 50;
me->GetGameObjectListWithEntryInGrid(nearbyEggs, GO_ROOKERY_EGG, 40); me->GetGameObjectListWithEntryInGrid(nearbyEggs, GO_ROOKERY_EGG, 40);
for (const auto& egg : nearbyEggs) for (auto const& egg : nearbyEggs)
{ {
if (egg->isSpawned() && egg->getLootState() == GO_READY) if (egg->isSpawned() && egg->getLootState() == GO_READY)
{ {

View file

@ -401,14 +401,14 @@ public:
pile->SetLootState(GO_READY); pile->SetLootState(GO_READY);
pile->Respawn(); pile->Respawn();
} }
for (const auto& circleGUID : go_urokOgreCirles) for (auto const& circleGUID : go_urokOgreCirles)
{ {
if (GameObject* circle = instance->GetGameObject(circleGUID)) if (GameObject* circle = instance->GetGameObject(circleGUID))
{ {
circle->Delete(); circle->Delete();
} }
} }
for (const auto& mobGUID : UrokMobs) for (auto const& mobGUID : UrokMobs)
{ {
if (Creature* mob = instance->GetCreature(mobGUID)) if (Creature* mob = instance->GetCreature(mobGUID))
{ {

View file

@ -120,7 +120,7 @@ public:
immol->GetAI()->SetData(1, 1); immol->GetAI()->SetData(1, 1);
immol->RemoveUnitFlag(UNIT_FLAG_NON_ATTACKABLE); immol->RemoveUnitFlag(UNIT_FLAG_NON_ATTACKABLE);
} }
for (const auto& guid : HighborneSummoners) for (auto const& guid : HighborneSummoners)
{ {
if (Creature* summoner = instance->GetCreature(guid)) if (Creature* summoner = instance->GetCreature(guid))
{ {

View file

@ -386,7 +386,7 @@ struct boss_cthun : public BossAI
}, 500ms); }, 500ms);
//Spawn flesh tentacle //Spawn flesh tentacle
for (const auto& position : FleshTentaclePos) for (auto const& position : FleshTentaclePos)
me->SummonCreature(NPC_FLESH_TENTACLE, position, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 5000); me->SummonCreature(NPC_FLESH_TENTACLE, position, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 5000);
ScheduleTasks(); ScheduleTasks();
@ -501,7 +501,7 @@ struct boss_cthun : public BossAI
me->RemoveAurasDueToSpell(SPELL_PURPLE_COLORATION); me->RemoveAurasDueToSpell(SPELL_PURPLE_COLORATION);
DoCastSelf(SPELL_CARAPACE_CTHUN, true); DoCastSelf(SPELL_CARAPACE_CTHUN, true);
//Spawn flesh tentacle //Spawn flesh tentacle
for (const auto& position : FleshTentaclePos) for (auto const& position : FleshTentaclePos)
me->SummonCreature(NPC_FLESH_TENTACLE, position, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 5000); me->SummonCreature(NPC_FLESH_TENTACLE, position, TEMPSUMMON_CORPSE_TIMED_DESPAWN, 5000);
}); });
} }

View file

@ -159,7 +159,7 @@ public:
return false; return false;
Map::PlayerList const& pList = me->GetMap()->GetPlayers(); Map::PlayerList const& pList = me->GetMap()->GetPlayers();
for (const auto& itr : pList) for (auto const& itr : pList)
{ {
Player* player = itr.GetSource(); Player* player = itr.GetSource();
if (!player || !player->IsAlive()) if (!player || !player->IsAlive())

View file

@ -387,7 +387,7 @@ public:
{ {
bool checklife = false; bool checklife = false;
bool checkdead = false; bool checkdead = false;
for (const auto& i : PlayerList) for (auto const& i : PlayerList)
{ {
Player* player = i.GetSource(); Player* player = i.GetSource();
if (player->IsAlive() && if (player->IsAlive() &&

View file

@ -228,7 +228,7 @@ public:
case EVENT_SAFETY_DANCE: case EVENT_SAFETY_DANCE:
{ {
Map::PlayerList const& pList = me->GetMap()->GetPlayers(); Map::PlayerList const& pList = me->GetMap()->GetPlayers();
for (const auto& itr : pList) for (auto const& itr : pList)
{ {
if (IsInRoom(itr.GetSource()) && !itr.GetSource()->IsAlive()) if (IsInRoom(itr.GetSource()) && !itr.GetSource()->IsAlive())
{ {

View file

@ -142,7 +142,7 @@ public:
if (PlList.IsEmpty()) if (PlList.IsEmpty())
return; return;
for (const auto& i : PlList) for (auto const& i : PlList)
{ {
if (Player* player = i.GetSource()) if (Player* player = i.GetSource())
{ {
@ -400,7 +400,7 @@ public:
case EVENT_HUNDRED_CLUB: case EVENT_HUNDRED_CLUB:
{ {
Map::PlayerList const& pList = me->GetMap()->GetPlayers(); 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) if (itr.GetSource()->GetResistance(SPELL_SCHOOL_FROST) > 100 && pInstance)
{ {

View file

@ -671,7 +671,7 @@ class spell_hun_readiness : public SpellScript
std::set<std::pair<uint32, bool>> spellsToRemove; std::set<std::pair<uint32, bool>> spellsToRemove;
std::set<uint32> categoriesToRemove; std::set<uint32> categoriesToRemove;
for (const auto& [spellId, cooldown] : cooldowns) for (auto const& [spellId, cooldown] : cooldowns)
{ {
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId); SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
if (spellInfo if (spellInfo
@ -689,9 +689,9 @@ class spell_hun_readiness : public SpellScript
} }
// we can't remove spell cooldowns while iterating. // we can't remove spell cooldowns while iterating.
for (const auto& [spellId, sendToClient] : spellsToRemove) for (auto const& [spellId, sendToClient] : spellsToRemove)
caster->RemoveSpellCooldown(spellId, sendToClient); caster->RemoveSpellCooldown(spellId, sendToClient);
for (const auto& category : categoriesToRemove) for (auto const& category : categoriesToRemove)
caster->RemoveCategoryCooldown(category); caster->RemoveCategoryCooldown(category);
} }

View file

@ -464,14 +464,14 @@ public:
_storage.shrink_to_fit(); _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<class T> void append(const T* src, std::size_t cnt) template<class T> 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); void append(uint8 const* src, std::size_t cnt);
@ -522,7 +522,7 @@ public:
} }
void AppendPackedTime(time_t time); 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 print_storage() const;
void textlike() const; void textlike() const;
void hexlike() const; void hexlike() const;