mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2025-11-29 17:38:24 +08:00
feat(CI/Codestyle): check for curly brackets before/after if/else statements (#20977)
* feat(CI/Codestyle): check for braces after if/else statements * right need to edit a cpp file to trigger cpp check * Revert "right need to edit a cpp file to trigger cpp check" This reverts commit 2e34d8c52f35216549107a3476e79e79ea2ae077. * fix codestyle in cpp * Update oculus.cpp * Update codestyle.py * Update codestyle.py * Update codestyle.py * Update codestyle.py
This commit is contained in:
@@ -21,6 +21,11 @@ results = {
|
|||||||
|
|
||||||
# Main function to parse all the files of the project
|
# Main function to parse all the files of the project
|
||||||
def parsing_file(directory: str) -> None:
|
def parsing_file(directory: str) -> None:
|
||||||
|
print("Starting AzerothCore CPP Codestyle check...")
|
||||||
|
print(" ")
|
||||||
|
print("Please read the C++ Code Standards for AzerothCore:")
|
||||||
|
print("https://www.azerothcore.org/wiki/cpp-code-standards")
|
||||||
|
print(" ")
|
||||||
for root, _, files in os.walk(directory):
|
for root, _, files in os.walk(directory):
|
||||||
for file in files:
|
for file in files:
|
||||||
if not file.endswith('.ico'): # Skip .ico files that cannot be read
|
if not file.endswith('.ico'): # Skip .ico files that cannot be read
|
||||||
@@ -138,23 +143,23 @@ def npcflags_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 'GetUInt32Value(UNIT_NPC_FLAGS)' in line:
|
if 'GetUInt32Value(UNIT_NPC_FLAGS)' in line:
|
||||||
print(
|
print(
|
||||||
f"Please use GetNpcFlags() instead GetUInt32Value(UNIT_NPC_FLAGS): {file_path} at line {line_number}")
|
f"Please use GetNpcFlags() instead of GetUInt32Value(UNIT_NPC_FLAGS): {file_path} at line {line_number}")
|
||||||
check_failed = True
|
check_failed = True
|
||||||
if 'HasFlag(UNIT_NPC_FLAGS,' in line:
|
if 'HasFlag(UNIT_NPC_FLAGS,' in line:
|
||||||
print(
|
print(
|
||||||
f"Please use HasNpcFlag() instead HasFlag(UNIT_NPC_FLAGS, ...): {file_path} at line {line_number}")
|
f"Please use HasNpcFlag() instead of HasFlag(UNIT_NPC_FLAGS, ...): {file_path} at line {line_number}")
|
||||||
check_failed = True
|
check_failed = True
|
||||||
if 'SetUInt32Value(UNIT_NPC_FLAGS,' in line:
|
if 'SetUInt32Value(UNIT_NPC_FLAGS,' in line:
|
||||||
print(
|
print(
|
||||||
f"Please use ReplaceAllNpcFlags() instead SetUInt32Value(UNIT_NPC_FLAGS, ...): {file_path} at line {line_number}")
|
f"Please use ReplaceAllNpcFlags() instead of SetUInt32Value(UNIT_NPC_FLAGS, ...): {file_path} at line {line_number}")
|
||||||
check_failed = True
|
check_failed = True
|
||||||
if 'SetFlag(UNIT_NPC_FLAGS,' in line:
|
if 'SetFlag(UNIT_NPC_FLAGS,' in line:
|
||||||
print(
|
print(
|
||||||
f"Please use SetNpcFlag() instead SetFlag(UNIT_NPC_FLAGS, ...): {file_path} at line {line_number}")
|
f"Please use SetNpcFlag() instead of SetFlag(UNIT_NPC_FLAGS, ...): {file_path} at line {line_number}")
|
||||||
check_failed = True
|
check_failed = True
|
||||||
if 'RemoveFlag(UNIT_NPC_FLAGS,' in line:
|
if 'RemoveFlag(UNIT_NPC_FLAGS,' in line:
|
||||||
print(
|
print(
|
||||||
f"Please use RemoveNpcFlag() instead RemoveFlag(UNIT_NPC_FLAGS, ...): {file_path} at line {line_number}")
|
f"Please use RemoveNpcFlag() instead of RemoveFlag(UNIT_NPC_FLAGS, ...): {file_path} at line {line_number}")
|
||||||
check_failed = True
|
check_failed = True
|
||||||
# Handle the script error and update the result output
|
# Handle the script error and update the result output
|
||||||
if check_failed:
|
if check_failed:
|
||||||
@@ -214,19 +219,26 @@ def misc_codestyle_check(file: io, file_path: str) -> None:
|
|||||||
global error_handler, results
|
global error_handler, results
|
||||||
file.seek(0) # Reset file pointer to the beginning
|
file.seek(0) # Reset file pointer to the beginning
|
||||||
check_failed = False
|
check_failed = False
|
||||||
|
|
||||||
|
# used to check for "if/else (...) {" "} else" ignores "if/else (...) {...}" "#define ... if/else (...) {"
|
||||||
|
ifelse_curlyregex = r"^[^#define].*\s+(if|else)(\s*\(.*\))?\s*{[^}]*$|}\s*else(\s*{[^}]*$)"
|
||||||
# Parse all the file
|
# Parse all the file
|
||||||
for line_number, line in enumerate(file, start = 1):
|
for line_number, line in enumerate(file, start = 1):
|
||||||
if 'const auto&' in line:
|
if 'const auto&' in line:
|
||||||
print(
|
print(
|
||||||
f"Please use 'auto const&' syntax instead of 'const auto&': {file_path} at line {line_number}")
|
f"Please use the 'auto const&' syntax instead of 'const auto&': {file_path} at line {line_number}")
|
||||||
check_failed = True
|
check_failed = True
|
||||||
if re.search(r'\bconst\s+\w+\s*\*\b', line):
|
if re.search(r'\bconst\s+\w+\s*\*\b', line):
|
||||||
print(
|
print(
|
||||||
f"Please use the syntax 'Class/ObjectType const*' instead of 'const Class/ObjectType*': {file_path} at line {line_number}")
|
f"Please use the 'Class/ObjectType const*' syntax instead of 'const Class/ObjectType*': {file_path} at line {line_number}")
|
||||||
check_failed = True
|
check_failed = True
|
||||||
if [match for match in [' if(', ' if ( '] if match in line]:
|
if [match for match in [' if(', ' if ( '] if match in line]:
|
||||||
print(
|
print(
|
||||||
f"AC have as standard: if (XXXX). Please check spaces in your condition': {file_path} at line {line_number}")
|
f"Please use the 'if (XXXX)' syntax instead of 'if(XXXX)': {file_path} at line {line_number}")
|
||||||
|
check_failed = True
|
||||||
|
if re.match(ifelse_curlyregex, line):
|
||||||
|
print(
|
||||||
|
f"Curly brackets are not allowed to be leading or trailing if/else statements. Place it on a new line: {file_path} at line {line_number}")
|
||||||
check_failed = True
|
check_failed = True
|
||||||
# Handle the script error and update the result output
|
# Handle the script error and update the result output
|
||||||
if check_failed:
|
if check_failed:
|
||||||
|
|||||||
@@ -775,9 +775,8 @@ void BattlegroundQueue::BattlegroundQueueUpdate(uint32 diff, BattlegroundTypeId
|
|||||||
|
|
||||||
sScriptMgr->OnQueueUpdate(this, diff, bgTypeId, bracket_id, arenaType, isRated, arenaRating);
|
sScriptMgr->OnQueueUpdate(this, diff, bgTypeId, bracket_id, arenaType, isRated, arenaRating);
|
||||||
|
|
||||||
if (!sScriptMgr->OnQueueUpdateValidity(this, diff, bgTypeId, bracket_id, arenaType, isRated, arenaRating)) {
|
if (!sScriptMgr->OnQueueUpdateValidity(this, diff, bgTypeId, bracket_id, arenaType, isRated, arenaRating))
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
m_SelectionPools[TEAM_ALLIANCE].Init();
|
m_SelectionPools[TEAM_ALLIANCE].Init();
|
||||||
m_SelectionPools[TEAM_HORDE].Init();
|
m_SelectionPools[TEAM_HORDE].Init();
|
||||||
|
|||||||
@@ -932,7 +932,8 @@ void WorldSession::ComputeNewClockDelta()
|
|||||||
uint32 sampleSizeAfterFiltering = 0;
|
uint32 sampleSizeAfterFiltering = 0;
|
||||||
for (auto& pair : _timeSyncClockDeltaQueue.content())
|
for (auto& pair : _timeSyncClockDeltaQueue.content())
|
||||||
{
|
{
|
||||||
if (pair.second <= latencyMedian + latencyStandardDeviation) {
|
if (pair.second <= latencyMedian + latencyStandardDeviation)
|
||||||
|
{
|
||||||
clockDeltasAfterFiltering.push_back(pair.first);
|
clockDeltasAfterFiltering.push_back(pair.first);
|
||||||
sampleSizeAfterFiltering++;
|
sampleSizeAfterFiltering++;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,8 @@ public:
|
|||||||
resetPosition = true;
|
resetPosition = true;
|
||||||
moved = true;
|
moved = true;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
moved = false;
|
moved = false;
|
||||||
resetPosition = false;
|
resetPosition = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -147,7 +147,8 @@ void OPvPCapturePointNA::SpawnNPCsForTeam(HalaaNPCS teamNPC)
|
|||||||
{
|
{
|
||||||
ObjectGuid::LowType spawnId = teamNPC[i];
|
ObjectGuid::LowType spawnId = teamNPC[i];
|
||||||
const CreatureData* data = sObjectMgr->GetCreatureData(spawnId);
|
const CreatureData* data = sObjectMgr->GetCreatureData(spawnId);
|
||||||
if (data) {
|
if (data)
|
||||||
|
{
|
||||||
UpdateCreatureHalaa(spawnId, _pvp->GetMap(), data->posX, data->posY);
|
UpdateCreatureHalaa(spawnId, _pvp->GetMap(), data->posX, data->posY);
|
||||||
_creatures[i] = spawnId;
|
_creatures[i] = spawnId;
|
||||||
_creatureTypes[_creatures[i]] = i;
|
_creatureTypes[_creatures[i]] = i;
|
||||||
@@ -650,12 +651,14 @@ bool OPvPCapturePointNA::Update(uint32 diff)
|
|||||||
}
|
}
|
||||||
else m_GuardCheckTimer -= diff;
|
else m_GuardCheckTimer -= diff;
|
||||||
|
|
||||||
if (m_capturable) {
|
if (m_capturable)
|
||||||
|
{
|
||||||
if (m_RespawnTimer < diff)
|
if (m_RespawnTimer < diff)
|
||||||
{
|
{
|
||||||
// if the guards have been killed, then the challenger has one hour to take over halaa.
|
// if the guards have been killed, then the challenger has one hour to take over halaa.
|
||||||
// in case they fail to do it, the guards are respawned, and they have to start again.
|
// in case they fail to do it, the guards are respawned, and they have to start again.
|
||||||
if (GetControllingFaction() == TEAM_ALLIANCE) {
|
if (GetControllingFaction() == TEAM_ALLIANCE)
|
||||||
|
{
|
||||||
_state = OBJECTIVESTATE_ALLIANCE;
|
_state = OBJECTIVESTATE_ALLIANCE;
|
||||||
_value = _maxValue;
|
_value = _maxValue;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user