From f4ffc33887394519b08e7961eccdcd5474a6a9e0 Mon Sep 17 00:00:00 2001 From: Meltie2013 Date: Fri, 25 Jul 2025 04:07:43 +0000 Subject: [PATCH 01/12] [Part 1] Updating all workflow files - Updated workflow for code styling - Updated linux build file For the code styling, I have added 6 new checks that will check code for a few things. Refer to the PR description area for more details. Note: Making sure Linux is using the same version of OpenSSL as the Windows workflow build. So we are consistent with that package if problems happen. On the workflow side, default version is 3.0.2 from what I been seeing thus far. --- .github/workflows/core_build.yml | 25 +++++++++-- apps/ci/ci-codestyle.sh | 75 ++++++++++++++++++++++---------- apps/ci/ci-compile.sh | 10 ++--- apps/ci/ci-compiler-update.sh | 7 --- apps/ci/ci-submodule-update.sh | 7 --- 5 files changed, 78 insertions(+), 46 deletions(-) delete mode 100644 apps/ci/ci-compiler-update.sh delete mode 100644 apps/ci/ci-submodule-update.sh diff --git a/.github/workflows/core_build.yml b/.github/workflows/core_build.yml index 4a079dd2f..d2ffcb50f 100644 --- a/.github/workflows/core_build.yml +++ b/.github/workflows/core_build.yml @@ -7,6 +7,9 @@ on: jobs: build: + strategy: + fail-fast: false + runs-on: ubuntu-latest steps: @@ -20,11 +23,27 @@ jobs: - name: Install Required Packages run: sudo apt-get install -y git make cmake clang libssl-dev libbz2-dev build-essential default-libmysqlclient-dev libace-dev libreadline-dev - - name: Update Compilers - run: source ./apps/ci/ci-compiler-update.sh + - name: Install OpenSSL 3.5.1 Package Manually + run: | + wget https://www.openssl.org/source/openssl-3.5.1.tar.gz + tar -xvf openssl-3.5.1.tar.gz + cd openssl-3.5.1 + ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl + make -j$(nproc) + sudo make install + + - name: Set OpenSSL 3.5.1 Environment Variables + run: | + echo "OPENSSL_ROOT_DIR=/usr/local/openssl" >> $GITHUB_ENV + echo "OPENSSL_INCLUDE_DIR=/usr/local/openssl/include" >> $GITHUB_ENV + echo "OPENSSL_LIBRARIES=/usr/local/openssl/lib" >> $GITHUB_ENV + echo "/usr/local/openssl/lib" | sudo tee /etc/ld.so.conf.d/openssl-3.5.conf + sudo ldconfig - name: Check for Submodule Updates - run: source ./apps/ci/ci-submodule-update.sh + run: | + git submodule init + git submodule update - name: Build Mangos Project run: source ./apps/ci/ci-compile.sh diff --git a/apps/ci/ci-codestyle.sh b/apps/ci/ci-codestyle.sh index ca9deab3a..65d6dd24a 100644 --- a/apps/ci/ci-codestyle.sh +++ b/apps/ci/ci-codestyle.sh @@ -1,39 +1,66 @@ #!/bin/bash -set -e - +echo +echo "Checking For MaNGOS Coding Standards:" echo "Starting Codestyling Script:" echo declare -A singleLineRegexChecks=( ["[[:blank:]]$"]="Remove whitespace at the end of the lines above" ["\t"]="Replace tabs with 4 spaces in the lines above" + ["^[[:blank:]]*(?:[a-zA-Z_][a-zA-Z_0-9]*[[:blank:]]+)*[a-zA-Z_][a-zA-Z_0-9]*[[:blank:]]*\([^)]*\)[[:blank:]]*\{[[:blank:]]*$"]="Move opening brace to a new line after function definition" + ["\{[[:blank:]]*\S"]="Opening brace must be on its own line (no code after '{')" + ["\S[[:blank:]]*\}"]="Closing brace must be on its own line (no code before '}')" + ["^[[:blank:]]*if\s*\(.*\)[[:blank:]]*(?!\{)"]="if statement must use braces" + ["^[[:blank:]]*else[[:blank:]]*(?!if|\{)"]="else statement must use braces" + ["\bif\("]="Missing space between 'if' and '('" ) -for check in ${!singleLineRegexChecks[@]}; do - echo " Checking RegEx: '${check}'" - - if grep -P -r -I -n ${check} src; then - echo - echo "${singleLineRegexChecks[$check]}" - exit 1 +# Ignore directories +grep_exclude_args=( + --exclude-dir="Eluna" + --exclude-dir="tools" +) + +# Accept multiple input paths +input_paths=("$@") +if [[ ${#input_paths[@]} -eq 0 ]]; then + input_paths=("src") # fallback +fi + +# Track errors and triggered rules +hadError=0 +declare -A results +declare -a triggeredDescriptions + +# Perform checks +for check in "${!singleLineRegexChecks[@]}"; do + matches=$(grep -P -r -I -n "${grep_exclude_args[@]}" "${input_paths[@]}" -e "$check" 2>/dev/null) + if [[ -n "$matches" ]]; then + results["$check"]="$matches" + triggeredDescriptions+=("${singleLineRegexChecks[$check]}") + hadError=1 fi done -# declare -A multiLineRegexChecks=( -# ["\n\n\n"]="Multiple blank lines detected, keep only one. Check the files above" -# ) - -# for check in ${!multiLineRegexChecks[@]}; do -# echo " Checking RegEx: '${check}'" +# Display results +if [[ $hadError -eq 1 ]]; then + echo + for check in "${!results[@]}"; do + echo "== Rule: ${singleLineRegexChecks[$check]} ==" + echo "${results[$check]}" + echo + done -# if grep -Pzo -r -I ${check} src; then -# echo -# echo -# echo "${multiLineRegexChecks[$check]}" -# exit 1 -# fi -# done + echo "------------------------------------------" + echo "Summary of Triggered Rules:" + for rule in "${triggeredDescriptions[@]}"; do + echo "- $rule" + done + echo "------------------------------------------" -echo -echo "Awesome! No issues..." + exit 1 +else + echo "All checks passed. No issues found." + exit 0 +fi diff --git a/apps/ci/ci-compile.sh b/apps/ci/ci-compile.sh index a8669e58c..7fe5b1b01 100644 --- a/apps/ci/ci-compile.sh +++ b/apps/ci/ci-compile.sh @@ -3,14 +3,14 @@ set -e # Check for & make directories -time test -d _build || mkdir _build -time test -d _install || mkdir _install +test -d _build || mkdir _build +test -d _install || mkdir _install # Move to build folder -time cd _build +cd _build # Run CMake Configurations -time cmake .. -DCMAKE_INSTALL_PREFIX=../_install -DBUILD_TOOLS:BOOL=1 -DBUILD_MANGOSD:BOOL=1 -DBUILD_REALMD:BOOL=1 -DSOAP:BOOL=1 -DSCRIPT_LIB_ELUNA:BOOL=1 -DSCRIPT_LIB_SD3:BOOL=1 -DPLAYERBOTS:BOOL=1 -DUSE_STORMLIB:BOOL=1 +cmake .. -DCMAKE_INSTALL_PREFIX=../_install -DCMAKE_C_COMPILER=/usr/bin/clang -DCMAKE_CXX_COMPILER=/usr/bin/clang++ -DBUILD_TOOLS:BOOL=1 -DBUILD_MANGOSD:BOOL=1 -DBUILD_REALMD:BOOL=1 -DSOAP:BOOL=1 -DSCRIPT_LIB_ELUNA:BOOL=1 -DSCRIPT_LIB_SD3:BOOL=1 -DPLAYERBOTS:BOOL=1 -DUSE_STORMLIB:BOOL=1 # Compile the Project -time make -j 6 +make -j$(nproc) diff --git a/apps/ci/ci-compiler-update.sh b/apps/ci/ci-compiler-update.sh deleted file mode 100644 index f281f376b..000000000 --- a/apps/ci/ci-compiler-update.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -set -e - -# Update to Clang Compilers -time sudo update-alternatives --install /usr/bin/cc cc /usr/bin/clang 100 -time sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/clang 100 diff --git a/apps/ci/ci-submodule-update.sh b/apps/ci/ci-submodule-update.sh deleted file mode 100644 index 4ebb10efe..000000000 --- a/apps/ci/ci-submodule-update.sh +++ /dev/null @@ -1,7 +0,0 @@ -#!/bin/bash - -set -e - -# Check for Submodule Updates -git submodule init -git submodule update From 3aad0d6bcd8b2b352622d0ae52bedd5c5f40ebe0 Mon Sep 17 00:00:00 2001 From: Meltie2013 Date: Fri, 25 Jul 2025 04:47:09 +0000 Subject: [PATCH 02/12] I think I need some sleep, Placed the code in the wrong spot. --- .github/workflows/core_codestyle.yml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/.github/workflows/core_codestyle.yml b/.github/workflows/core_codestyle.yml index 3f9a73e0c..ec0a1893d 100644 --- a/.github/workflows/core_codestyle.yml +++ b/.github/workflows/core_codestyle.yml @@ -11,9 +11,19 @@ jobs: fail-fast: false runs-on: ubuntu-latest + name: Check Codestyling steps: - uses: actions/checkout@v2 + - name: Ensure grep supports -P + run: | + grep -P 'test' <<< 'test' || echo "::warning ::grep -P not supported" + + - name: Install GNU grep (for full -P support) + run: | + sudo apt-get update + sudo apt-get install -y grep + - name: Check Codestyling run: source ./apps/ci/ci-codestyle.sh From 873d12a7fad0c50be885d60af54fd616a458ab6b Mon Sep 17 00:00:00 2001 From: Meltie2013 Date: Fri, 25 Jul 2025 04:57:18 +0000 Subject: [PATCH 03/12] Let's see if the code styling check works as it should or breaks again. --- apps/ci/ci-codestyle.sh | 42 +++++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/apps/ci/ci-codestyle.sh b/apps/ci/ci-codestyle.sh index 65d6dd24a..d96d4a25b 100644 --- a/apps/ci/ci-codestyle.sh +++ b/apps/ci/ci-codestyle.sh @@ -19,7 +19,9 @@ declare -A singleLineRegexChecks=( # Ignore directories grep_exclude_args=( --exclude-dir="Eluna" - --exclude-dir="tools" + --exclude-dir="Extractor_Binaries" + --exclude-dir="MangosStrings_LanguageHGenerator" + --exclude-dir="restart-scripts" ) # Accept multiple input paths @@ -28,39 +30,33 @@ if [[ ${#input_paths[@]} -eq 0 ]]; then input_paths=("src") # fallback fi -# Track errors and triggered rules hadError=0 -declare -A results declare -a triggeredDescriptions -# Perform checks for check in "${!singleLineRegexChecks[@]}"; do + ruleDesc="${singleLineRegexChecks[$check]}" matches=$(grep -P -r -I -n "${grep_exclude_args[@]}" "${input_paths[@]}" -e "$check" 2>/dev/null) + if [[ -n "$matches" ]]; then - results["$check"]="$matches" - triggeredDescriptions+=("${singleLineRegexChecks[$check]}") + echo + echo "== Rule triggered: $ruleDesc ==" + echo "$matches" + triggeredDescriptions+=("$ruleDesc") hadError=1 fi done -# Display results -if [[ $hadError -eq 1 ]]; then - echo - for check in "${!results[@]}"; do - echo "== Rule: ${singleLineRegexChecks[$check]} ==" - echo "${results[$check]}" - echo - done +echo +echo "------------------------------------------" +echo "Summary of Triggered Rules:" +echo "------------------------------------------" - echo "------------------------------------------" - echo "Summary of Triggered Rules:" +if [[ ${#triggeredDescriptions[@]} -eq 0 ]]; then + echo "No style violations found." +else for rule in "${triggeredDescriptions[@]}"; do - echo "- $rule" + echo "$rule" done - echo "------------------------------------------" - - exit 1 -else - echo "All checks passed. No issues found." - exit 0 fi + +exit $hadError From dcec82bc0448a0a0199aa8fe968ce81f641d94df Mon Sep 17 00:00:00 2001 From: Meltie2013 Date: Fri, 25 Jul 2025 05:24:12 +0000 Subject: [PATCH 04/12] Fixed the problem and now it works as it should. --- .github/workflows/core_codestyle.yml | 11 +---------- apps/ci/ci-codestyle.sh | 1 + 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/core_codestyle.yml b/.github/workflows/core_codestyle.yml index ec0a1893d..85bffb1b2 100644 --- a/.github/workflows/core_codestyle.yml +++ b/.github/workflows/core_codestyle.yml @@ -16,14 +16,5 @@ jobs: steps: - uses: actions/checkout@v2 - - name: Ensure grep supports -P - run: | - grep -P 'test' <<< 'test' || echo "::warning ::grep -P not supported" - - - name: Install GNU grep (for full -P support) - run: | - sudo apt-get update - sudo apt-get install -y grep - - name: Check Codestyling - run: source ./apps/ci/ci-codestyle.sh + run: bash ./apps/ci/ci-codestyle.sh diff --git a/apps/ci/ci-codestyle.sh b/apps/ci/ci-codestyle.sh index d96d4a25b..8eaa35707 100644 --- a/apps/ci/ci-codestyle.sh +++ b/apps/ci/ci-codestyle.sh @@ -22,6 +22,7 @@ grep_exclude_args=( --exclude-dir="Extractor_Binaries" --exclude-dir="MangosStrings_LanguageHGenerator" --exclude-dir="restart-scripts" + --exclude="CMakeLists.txt" ) # Accept multiple input paths From 269023594daaefa9133ffe7f73669a66911baae8 Mon Sep 17 00:00:00 2001 From: Meltie2013 Date: Fri, 25 Jul 2025 08:53:57 +0000 Subject: [PATCH 05/12] Some more changes to reduce code overview and false positives. - Working on some exception patterns that will output but will be marked with 0 instead of 1. Still a working progress. - Added general comments to the filters based on what they do. --- apps/ci/ci-codestyle.sh | 48 ++++++++++++++++++++++++++++++----------- 1 file changed, 35 insertions(+), 13 deletions(-) diff --git a/apps/ci/ci-codestyle.sh b/apps/ci/ci-codestyle.sh index 8eaa35707..0eae0a453 100644 --- a/apps/ci/ci-codestyle.sh +++ b/apps/ci/ci-codestyle.sh @@ -6,14 +6,25 @@ echo "Starting Codestyling Script:" echo declare -A singleLineRegexChecks=( - ["[[:blank:]]$"]="Remove whitespace at the end of the lines above" - ["\t"]="Replace tabs with 4 spaces in the lines above" - ["^[[:blank:]]*(?:[a-zA-Z_][a-zA-Z_0-9]*[[:blank:]]+)*[a-zA-Z_][a-zA-Z_0-9]*[[:blank:]]*\([^)]*\)[[:blank:]]*\{[[:blank:]]*$"]="Move opening brace to a new line after function definition" - ["\{[[:blank:]]*\S"]="Opening brace must be on its own line (no code after '{')" - ["\S[[:blank:]]*\}"]="Closing brace must be on its own line (no code before '}')" - ["^[[:blank:]]*if\s*\(.*\)[[:blank:]]*(?!\{)"]="if statement must use braces" - ["^[[:blank:]]*else[[:blank:]]*(?!if|\{)"]="else statement must use braces" - ["\bif\("]="Missing space between 'if' and '('" + # Exception patterns (ignore initializer-style brace lines) + ["^[[:blank:]]*\\{\\s*\".*?\"\\s*,\\s*\\w+\\s*,\\s*(true|false)\\s*,\\s*&[a-zA-Z_][\\w:]*::[a-zA-Z_]\\w*\\s*,\\s*\".*?\"\\s*,\\s*(NULL|nullptr)\\s*\\},?[[:blank:]]*$"]="Well-formed initializer list line (valid) #ignore" + + # General whitespace/style rules + ["[[:blank:]]$"]="Remove whitespace at the end of the lines" + ["\t"]="Replace tabs with 4 spaces in the lines" + + # Control statements and braces + ["^[[:blank:]]*(if|else if|else|for|while|switch)[[:blank:]]*\(.*\)[[:blank:]]*\{[[:blank:]]*\S"]="Opening brace must be on its own line after control statement" + ["^[[:blank:]]*[\w:<>\*&~]+[[:blank:]]+\w+::?\w*\(.*\)[[:blank:]]*(const)?[[:blank:]]*\{[[:blank:]]*\S"]="Function opening brace must be on its own line (no code after '{')" + ["^\s*\S.*\}[[:blank:]]*\S.*$"]="Closing brace must be on its own line (no code before or after '}' on the line)" + + # Brace usage enforcement + ["^[[:blank:]]*if[[:blank:]]*\(.*\)[[:blank:]]*$"]="if statement must use braces" + ["^[[:blank:]]*else[[:blank:]]*$"]="else statement must use braces" + + # Spacing rules + ["\\b(if|for|while|switch|else\\s+if)\\("]="Missing space between keyword and '('" + ["\\)(\\{)"]="Missing space before '{'" ) # Ignore directories @@ -36,14 +47,25 @@ declare -a triggeredDescriptions for check in "${!singleLineRegexChecks[@]}"; do ruleDesc="${singleLineRegexChecks[$check]}" + + # If it's a fully ignorable rule, skip early + if [[ "$ruleDesc" == *"#ignore"* ]]; then + continue + fi + matches=$(grep -P -r -I -n "${grep_exclude_args[@]}" "${input_paths[@]}" -e "$check" 2>/dev/null) if [[ -n "$matches" ]]; then - echo - echo "== Rule triggered: $ruleDesc ==" - echo "$matches" - triggeredDescriptions+=("$ruleDesc") - hadError=1 + # Efficiently filter initializer list matches + filteredMatches=$(printf "%s\n" "$matches" | grep -Pv '^[[:blank:]]*\{\s*".*?"\s*,\s*\w+\s*,\s*(true|false)\s*,\s*&[a-zA-Z_][\w:]*::[a-zA-Z_]\w*\s*,\s*".*?"\s*,\s*(NULL|nullptr)\s*\},?[[:blank:]]*$') + + if [[ -n "$filteredMatches" ]]; then + echo + echo "== Rule triggered: ${ruleDesc%%#*} ==" + echo "$filteredMatches" + triggeredDescriptions+=("${ruleDesc%%#*}") + hadError=1 + fi fi done From 2f9876ec3e2cebf45194d45f2f53ac92620a3c72 Mon Sep 17 00:00:00 2001 From: Meltie2013 Date: Sat, 26 Jul 2025 05:33:35 +0000 Subject: [PATCH 06/12] Update whitespace remover - Added in some code to replace tab spaces with 4 spaces per tab Requested by @billy1arm --- apps/whitespace_remover/whitespace_remover.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/apps/whitespace_remover/whitespace_remover.sh b/apps/whitespace_remover/whitespace_remover.sh index fe3aeea6a..f6cea6fb3 100755 --- a/apps/whitespace_remover/whitespace_remover.sh +++ b/apps/whitespace_remover/whitespace_remover.sh @@ -1,6 +1,14 @@ # Required files -find -name '*.cpp' -print0 | xargs -r0 sed -e 's/[[:blank:]]\+$//' -i -find -name '*.h' -print0 | xargs -r0 sed -e 's/[[:blank:]]\+$//' -i + +# Find all .cpp files and process them: +# - Remove trailing whitespace at the end of lines (spaces or tabs) +# - Replace every tab character with 4 spaces +find -name '*.cpp' -print0 | xargs -r0 sed -e 's/[[:blank:]]\+$//' -e 's/\t/ /g' -i + +# Find all .h files and process them the same way: +# - Remove trailing whitespace at the end of lines (spaces or tabs) +# - Replace every tab character with 4 spaces +find -name '*.h' -print0 | xargs -r0 sed -e 's/[[:blank:]]\+$//' -e 's/\t/ /g' -i # Optional files - uncomment lines below to add them. #find -name '*.txt' -print0 | xargs -r0 sed -e 's/[[:blank:]]\+$//' -i From 92f6485f56f7a4ee0b190ad3e39567d04cdbda19 Mon Sep 17 00:00:00 2001 From: Meltie2013 Date: Sat, 26 Jul 2025 05:47:24 +0000 Subject: [PATCH 07/12] [Change] Build workflow update - Adding some paths ignore on some areas of the project, so only changes to the project source code will trigger a build and not areas like the ReadMe.md or apps folder. --- .github/workflows/core_build.yml | 10 ++++++++-- .github/workflows/core_windows_build.yml | 10 ++++++++-- .github/workflows/docker_build.yml | 10 ++++++++-- 3 files changed, 24 insertions(+), 6 deletions(-) diff --git a/.github/workflows/core_build.yml b/.github/workflows/core_build.yml index d2ffcb50f..4a4d1ffcd 100644 --- a/.github/workflows/core_build.yml +++ b/.github/workflows/core_build.yml @@ -1,9 +1,15 @@ name: Linux Build on: push: - branches: [ master ] + paths-ignore: + - 'README.md' + - 'apps/**' + branches: [ master ] pull_request: - branches: [ master ] + paths-ignore: + - 'README.md' + - 'apps/**' + branches: [ master ] jobs: build: diff --git a/.github/workflows/core_windows_build.yml b/.github/workflows/core_windows_build.yml index 50af0d32e..40a70a2f6 100644 --- a/.github/workflows/core_windows_build.yml +++ b/.github/workflows/core_windows_build.yml @@ -1,9 +1,15 @@ name: Windows Build on: push: - branches: [ master ] + paths-ignore: + - 'README.md' + - 'apps/**' + branches: [ master ] pull_request: - branches: [ master ] + paths-ignore: + - 'README.md' + - 'apps/**' + branches: [ master ] jobs: build: diff --git a/.github/workflows/docker_build.yml b/.github/workflows/docker_build.yml index d505640c3..978668086 100644 --- a/.github/workflows/docker_build.yml +++ b/.github/workflows/docker_build.yml @@ -1,9 +1,15 @@ name: Docker Build on: push: - branches: [ master ] + paths-ignore: + - 'README.md' + - 'apps/**' + branches: [ master ] pull_request: - branches: [ master ] + paths-ignore: + - 'README.md' + - 'apps/**' + branches: [ master ] jobs: build: From 9935db16720c9429ee28baf9012d214b82c3c94d Mon Sep 17 00:00:00 2001 From: Meltie2013 Date: Sun, 27 Jul 2025 09:25:45 +0000 Subject: [PATCH 08/12] [New] Added a script to fix spacing in statements --- apps/styling_tools/fix_statement_spacing.sh | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 apps/styling_tools/fix_statement_spacing.sh diff --git a/apps/styling_tools/fix_statement_spacing.sh b/apps/styling_tools/fix_statement_spacing.sh new file mode 100644 index 000000000..65e50db76 --- /dev/null +++ b/apps/styling_tools/fix_statement_spacing.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# +# Fix Statement Spacing for getMaNGOS +# Script written by Meltie2013 (https://github.com/Meltie2013) +# +# Copyright: 2025 +# Website: https://getmangos.eu/ +# +# Script Type: Bash +# +# Co-authors Area: +# +# Note from the author: Anyone is free to use this script but is asked to keep the original author name and GitHub url in the header. +# You can add co-authors to the header when the script is updated or changed for your project needs. Removing the original author +# from the header, will result in a DMCA (take-down). +# +# This script is viewed under the GPL-2.0 license and shall not be changed unless authorized by the original author. +# + +# Fixes missing space between control statement keywords and '(' + +# List of statement keywords to fix +keywords="if|else[[:blank:]]+if|for|while|switch" + +for file in $(find . -type f \( -name "*.cpp" -o -name "*.h" \)); do + temp_file="${file}.tmp" + cp "$file" "$temp_file" + + changed=false + + for kw in if 'else[[:blank:]]+if' for while switch; do + # Fix keyword immediately followed by '(' with no space + sed -E "s/\b($kw)\(/\1 (/g" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file" + if ! diff -q "$file" "$temp_file" >/dev/null; then + changed=true + fi + done + + if $changed; then + mv "$temp_file" "$file" + echo "Fixed spacing in: $file" + else + rm "$temp_file" + fi +done From 0d85436716b6e2bb92488b2e5e2ed0c18d6e70c5 Mon Sep 17 00:00:00 2001 From: Meltie2013 Date: Sun, 27 Jul 2025 09:33:28 +0000 Subject: [PATCH 09/12] Fix issue in script reported by Codacy --- apps/styling_tools/fix_statement_spacing.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/styling_tools/fix_statement_spacing.sh b/apps/styling_tools/fix_statement_spacing.sh index 65e50db76..650d92536 100644 --- a/apps/styling_tools/fix_statement_spacing.sh +++ b/apps/styling_tools/fix_statement_spacing.sh @@ -29,7 +29,8 @@ for file in $(find . -type f \( -name "*.cpp" -o -name "*.h" \)); do changed=false - for kw in if 'else[[:blank:]]+if' for while switch; do + IFS='|' read -ra KW_ARR <<< "$keywords" + for kw in "${KW_ARR[@]}"; do # Fix keyword immediately followed by '(' with no space sed -E "s/\b($kw)\(/\1 (/g" "$temp_file" > "$temp_file.tmp" && mv "$temp_file.tmp" "$temp_file" if ! diff -q "$file" "$temp_file" >/dev/null; then From a179d2714d63cbfc7d385ad36557f9acd42b9b65 Mon Sep 17 00:00:00 2001 From: Meltie2013 Date: Sun, 27 Jul 2025 19:38:34 +0000 Subject: [PATCH 10/12] [RC] Code Style Check Script - This script needs review based on the rules used in the script. Aggressive Level: Moderate-to-Strict --- apps/ci/ci-codestyle.sh | 155 ++++++++++++++++++++++++++++++++++------ 1 file changed, 134 insertions(+), 21 deletions(-) diff --git a/apps/ci/ci-codestyle.sh b/apps/ci/ci-codestyle.sh index 0eae0a453..dc6a985a8 100644 --- a/apps/ci/ci-codestyle.sh +++ b/apps/ci/ci-codestyle.sh @@ -1,70 +1,145 @@ #!/bin/bash +# +# Advanced Code Styling Check for getMaNGOS +# Script written by Meltie2013 (https://github.com/Meltie2013) +# +# Copyright: 2025 +# Website: https://getmangos.eu/ +# +# Script Type: Bash +# +# Co-authors Area: +# +# Note from the author: Anyone is free to use this script but is asked to keep the original author name and GitHub url in the header. +# You can add co-authors to the header when the script is updated or changed for your project needs. Removing the original author +# from the header, will result in a DMCA (take-down). +# +# This script is viewed under the GPL-2.0 license and shall not be changed unless authorized by the original author. +# + +LOG_IGNORED_RULES=false # Set to true to print exception rule matches + echo echo "Checking For MaNGOS Coding Standards:" echo "Starting Codestyling Script:" -echo declare -A singleLineRegexChecks=( - # Exception patterns (ignore initializer-style brace lines) - ["^[[:blank:]]*\\{\\s*\".*?\"\\s*,\\s*\\w+\\s*,\\s*(true|false)\\s*,\\s*&[a-zA-Z_][\\w:]*::[a-zA-Z_]\\w*\\s*,\\s*\".*?\"\\s*,\\s*(NULL|nullptr)\\s*\\},?[[:blank:]]*$"]="Well-formed initializer list line (valid) #ignore" - # General whitespace/style rules ["[[:blank:]]$"]="Remove whitespace at the end of the lines" ["\t"]="Replace tabs with 4 spaces in the lines" + # Exception patterns (ignored, but still shown in summary) + ["^[[:blank:]]*\\{\\s*\".*?\"\\s*,\\s*\\w+\\s*,\\s*(true|false)\\s*,\\s*&[a-zA-Z_][\\w:]*::[a-zA-Z_]\\w*\\s*,\\s*\".*?\"\\s*,\\s*(NULL|nullptr)\\s*\\},?[[:blank:]]*$"]="Well-formed initializer list line (styling is valid) #ignore" + ["^[[:blank:]]*\\{[[:blank:]]*\"(SOAP-ENV|SOAP-ENC|xsi|xsd|ns1)\"[[:blank:]]*,[[:blank:]]*\"(http://[^\"]+|urn:[^\"]+)\"(?:[[:blank:]]*,[[:blank:]]*\"(http://[^\"]+|urn:[^\"]+)\")?[[:blank:]]*\\}[[:blank:]]*,?[[:blank:]]*(//.*)?$"]="Namespace initializer list line (styling is valid) #ignore" + ["^[[:blank:]]*[^[:blank:]]+[[:blank:]]*<<(.*\"[^\"]*[{}][^\"]*\".*)+[[:blank:]]*;?[[:blank:]]*$"]="Streamed brace output (styling is valid) #ignore" + + # Control TODO/FIXME rules + ["//[[:blank:]]*(TODO|FIXME)[[:blank:]]*(?!:)"]="TODO/FIXME must include description" + + # Virtual destructor enforcement + ["\\b(?:virtual[[:space:]]+)?~[[:alnum:]_]+[[:space:]]*\\([[:space:]]*\\)[[:space:]]*\\{[[:space:]]*\\}[[:space:]]*;?"]="Prefer '= default' for destructors instead of empty braces" + # Control statements and braces - ["^[[:blank:]]*(if|else if|else|for|while|switch)[[:blank:]]*\(.*\)[[:blank:]]*\{[[:blank:]]*\S"]="Opening brace must be on its own line after control statement" + ["^[[:blank:]]*(if|else if|else|do|for|while|switch|try|catch|class|struct|namespace|case)[[:blank:]]*(\(.*\))?[[:blank:]]*\{[[:blank:]]*\S"]="Opening brace must be on its own line after statement" ["^[[:blank:]]*[\w:<>\*&~]+[[:blank:]]+\w+::?\w*\(.*\)[[:blank:]]*(const)?[[:blank:]]*\{[[:blank:]]*\S"]="Function opening brace must be on its own line (no code after '{')" ["^\s*\S.*\}[[:blank:]]*\S.*$"]="Closing brace must be on its own line (no code before or after '}' on the line)" # Brace usage enforcement - ["^[[:blank:]]*if[[:blank:]]*\(.*\)[[:blank:]]*$"]="if statement must use braces" - ["^[[:blank:]]*else[[:blank:]]*$"]="else statement must use braces" + ["^[[:blank:]]*enum[[:blank:]]+(\\w+[[:blank:]]*)?\\{[[:blank:]]*[^}]*\\}[[:blank:]]*;"]="Enum opening brace must be on its own line and enum body properly formatted" # Spacing rules ["\\b(if|for|while|switch|else\\s+if)\\("]="Missing space between keyword and '('" - ["\\)(\\{)"]="Missing space before '{'" + + # Bad coding practice enforcement + ["^[[:blank:]]*using[[:blank:]]+namespace[[:blank:]]+std[[:blank:]]*;"]="Avoid using namespace std (prefer explicit qualifiers)" + ["^[[:blank:]]*namespace[[:blank:]]*\\{"]="Anonymous namespace brace must be on its own line" ) -# Ignore directories +# Directories and files to exclude grep_exclude_args=( + # Exclude Folders --exclude-dir="Eluna" --exclude-dir="Extractor_Binaries" --exclude-dir="MangosStrings_LanguageHGenerator" --exclude-dir="restart-scripts" + + # Exclude Files --exclude="CMakeLists.txt" + --exclude="realmd.conf.dist.in" + --exclude="mangosd.conf.dist.in" + --exclude=".dockerignore" + --exclude=".gitattributes" + --exclude=".gitignore" + --exclude=".gitmodules" ) -# Accept multiple input paths input_paths=("$@") if [[ ${#input_paths[@]} -eq 0 ]]; then - input_paths=("src") # fallback + input_paths=("src") fi hadError=0 declare -a triggeredDescriptions +declare -a ignoredLines=() # To store all lines matched by #ignore rules +# First pass: collect ignored lines (to exclude later from other rules) for check in "${!singleLineRegexChecks[@]}"; do ruleDesc="${singleLineRegexChecks[$check]}" + if [[ "$ruleDesc" == *"#ignore"* ]]; then + # Keep original description with #ignore intact + origRuleDesc="$ruleDesc" + # Create print-friendly description without #ignore + printRuleDesc="${ruleDesc%%#*}" + + matches=$(grep -P -r -I -n "${grep_exclude_args[@]}" "${input_paths[@]}" -e "$check" 2>/dev/null) + if [[ -n "$matches" ]]; then + ignoredLines+=("$matches") + triggeredDescriptions+=("$origRuleDesc") # Store original with #ignore for summary categorization + + if $LOG_IGNORED_RULES; then + echo + echo "== Exception Rule matched: $printRuleDesc ==" + echo "$matches" + fi + fi + fi +done + +# Flatten ignoredLines to a single pattern (line numbers + paths) for exclusion +ignoredPattern=$(printf "%s\n" "${ignoredLines[@]}" | cut -d: -f1,2 | sort -u | tr '\n' '|' | sed 's/|$//') - # If it's a fully ignorable rule, skip early +# Second pass: check non-ignored rules, excluding ignored lines from output +for check in "${!singleLineRegexChecks[@]}"; do + ruleDesc="${singleLineRegexChecks[$check]}" if [[ "$ruleDesc" == *"#ignore"* ]]; then + # Already handled in first pass, skip here continue fi matches=$(grep -P -r -I -n "${grep_exclude_args[@]}" "${input_paths[@]}" -e "$check" 2>/dev/null) + # Filter out any ignored lines from matches if [[ -n "$matches" ]]; then - # Efficiently filter initializer list matches - filteredMatches=$(printf "%s\n" "$matches" | grep -Pv '^[[:blank:]]*\{\s*".*?"\s*,\s*\w+\s*,\s*(true|false)\s*,\s*&[a-zA-Z_][\w:]*::[a-zA-Z_]\w*\s*,\s*".*?"\s*,\s*(NULL|nullptr)\s*\},?[[:blank:]]*$') + # Remove lines already caught by ignored rules + filteredMatches=$(printf "%s\n" "$matches" | grep -v -E "^($ignoredPattern):") if [[ -n "$filteredMatches" ]]; then - echo - echo "== Rule triggered: ${ruleDesc%%#*} ==" - echo "$filteredMatches" - triggeredDescriptions+=("${ruleDesc%%#*}") - hadError=1 + # Skip lines with streamed or quoted braces + filteredMatches=$(printf "%s\n" "$filteredMatches" | while IFS= read -r line; do + # Extract just the code part from line (after filename:linenumber:) + codePart=$(echo "$line" | cut -d: -f3-) + + echo "$line" + done) + + if [[ -n "$filteredMatches" ]]; then + echo + echo "== Rule triggered: $ruleDesc ==" + echo "$filteredMatches" + triggeredDescriptions+=("$ruleDesc") + hadError=1 + fi fi fi done @@ -77,9 +152,47 @@ echo "------------------------------------------" if [[ ${#triggeredDescriptions[@]} -eq 0 ]]; then echo "No style violations found." else - for rule in "${triggeredDescriptions[@]}"; do - echo "$rule" + declare -A seen=() + exceptions=() + violations=() + + for desc in "${triggeredDescriptions[@]}"; do + # Remove leading/trailing whitespace and outer quotes if present + clean_desc="$(echo "$desc" | sed -E 's/^[[:space:]]+|[[:space:]]+$//g' | sed -E 's/^"(.*)"$/\1/')" + + # Deduplicate + [[ -n "${seen[$clean_desc]}" ]] && continue + seen["$clean_desc"]=1 + + # Check if the line ends with #ignore (with or without trailing space) + if [[ "$desc" =~ [[:space:]]*#ignore$ ]]; then + # Remove #ignore for printing + exceptions+=("$(echo "$clean_desc" | sed -E 's/[[:space:]]*#ignore$//')") + else + violations+=("$clean_desc") + fi done + + echo "Exception Rules (Informational Only):" + echo "----" + if [[ ${#exceptions[@]} -eq 0 ]]; then + echo "(none)" + else + for e in "${exceptions[@]}"; do + echo "$e" + done + fi + + echo "------------------------------------------" + echo "Violations:" + echo "----" + if [[ ${#violations[@]} -eq 0 ]]; then + echo "(none)" + else + for v in "${violations[@]}"; do + echo "$v" + done + fi fi exit $hadError From 11c14e087aca9f7e629722e842fc77bf9d8b1312 Mon Sep 17 00:00:00 2001 From: Meltie2013 Date: Sun, 27 Jul 2025 22:12:15 +0000 Subject: [PATCH 11/12] [Update] Fix Statement Spacing - This script should be only touching the src folder and the contents within it. --- apps/styling_tools/fix_statement_spacing.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/styling_tools/fix_statement_spacing.sh b/apps/styling_tools/fix_statement_spacing.sh index 650d92536..6e466b87b 100644 --- a/apps/styling_tools/fix_statement_spacing.sh +++ b/apps/styling_tools/fix_statement_spacing.sh @@ -23,7 +23,7 @@ # List of statement keywords to fix keywords="if|else[[:blank:]]+if|for|while|switch" -for file in $(find . -type f \( -name "*.cpp" -o -name "*.h" \)); do +for file in $(find ./src -type f \( -name "*.cpp" -o -name "*.h" \)); do temp_file="${file}.tmp" cp "$file" "$temp_file" From 1833f21704e8e3df0776876bcecc67655558e6e4 Mon Sep 17 00:00:00 2001 From: Meltie2013 Date: Sun, 27 Jul 2025 22:17:28 +0000 Subject: [PATCH 12/12] Fix Codacy warning --- apps/ci/ci-codestyle.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/apps/ci/ci-codestyle.sh b/apps/ci/ci-codestyle.sh index dc6a985a8..aec6f280f 100644 --- a/apps/ci/ci-codestyle.sh +++ b/apps/ci/ci-codestyle.sh @@ -127,9 +127,6 @@ for check in "${!singleLineRegexChecks[@]}"; do if [[ -n "$filteredMatches" ]]; then # Skip lines with streamed or quoted braces filteredMatches=$(printf "%s\n" "$filteredMatches" | while IFS= read -r line; do - # Extract just the code part from line (after filename:linenumber:) - codePart=$(echo "$line" | cut -d: -f3-) - echo "$line" done)