|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | | -set -e |
4 | | - |
| 3 | +echo |
| 4 | +echo "Checking For MaNGOS Coding Standards:" |
5 | 5 | echo "Starting Codestyling Script:" |
6 | 6 | echo |
7 | 7 |
|
8 | 8 | declare -A singleLineRegexChecks=( |
9 | 9 | ["[[:blank:]]$"]="Remove whitespace at the end of the lines above" |
10 | 10 | ["\t"]="Replace tabs with 4 spaces in the lines above" |
| 11 | + ["^[[: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" |
| 12 | + ["\{[[:blank:]]*\S"]="Opening brace must be on its own line (no code after '{')" |
| 13 | + ["\S[[:blank:]]*\}"]="Closing brace must be on its own line (no code before '}')" |
| 14 | + ["^[[:blank:]]*if\s*\(.*\)[[:blank:]]*(?!\{)"]="if statement must use braces" |
| 15 | + ["^[[:blank:]]*else[[:blank:]]*(?!if|\{)"]="else statement must use braces" |
| 16 | + ["\bif\("]="Missing space between 'if' and '('" |
11 | 17 | ) |
12 | 18 |
|
13 | | -for check in ${!singleLineRegexChecks[@]}; do |
14 | | - echo " Checking RegEx: '${check}'" |
15 | | - |
16 | | - if grep -P -r -I -n ${check} src; then |
17 | | - echo |
18 | | - echo "${singleLineRegexChecks[$check]}" |
19 | | - exit 1 |
20 | | - fi |
21 | | -done |
| 19 | +# Ignore directories |
| 20 | +grep_exclude_args=( |
| 21 | + --exclude-dir="Eluna" |
| 22 | + --exclude-dir="Extractor_Binaries" |
| 23 | + --exclude-dir="MangosStrings_LanguageHGenerator" |
| 24 | + --exclude-dir="restart-scripts" |
| 25 | +) |
| 26 | + |
| 27 | +# Accept multiple input paths |
| 28 | +input_paths=("$@") |
| 29 | +if [[ ${#input_paths[@]} -eq 0 ]]; then |
| 30 | + input_paths=("src") # fallback |
| 31 | +fi |
22 | 32 |
|
23 | | -# declare -A multiLineRegexChecks=( |
24 | | -# ["\n\n\n"]="Multiple blank lines detected, keep only one. Check the files above" |
25 | | -# ) |
| 33 | +hadError=0 |
| 34 | +declare -a triggeredDescriptions |
26 | 35 |
|
27 | | -# for check in ${!multiLineRegexChecks[@]}; do |
28 | | -# echo " Checking RegEx: '${check}'" |
| 36 | +for check in "${!singleLineRegexChecks[@]}"; do |
| 37 | + ruleDesc="${singleLineRegexChecks[$check]}" |
| 38 | + matches=$(grep -P -r -I -n "${grep_exclude_args[@]}" "${input_paths[@]}" -e "$check" 2>/dev/null) |
29 | 39 |
|
30 | | -# if grep -Pzo -r -I ${check} src; then |
31 | | -# echo |
32 | | -# echo |
33 | | -# echo "${multiLineRegexChecks[$check]}" |
34 | | -# exit 1 |
35 | | -# fi |
36 | | -# done |
| 40 | + if [[ -n "$matches" ]]; then |
| 41 | + echo |
| 42 | + echo "== Rule triggered: $ruleDesc ==" |
| 43 | + echo "$matches" |
| 44 | + triggeredDescriptions+=("$ruleDesc") |
| 45 | + hadError=1 |
| 46 | + fi |
| 47 | +done |
37 | 48 |
|
38 | 49 | echo |
39 | | -echo "Awesome! No issues..." |
| 50 | +echo "------------------------------------------" |
| 51 | +echo "Summary of Triggered Rules:" |
| 52 | +echo "------------------------------------------" |
| 53 | + |
| 54 | +if [[ ${#triggeredDescriptions[@]} -eq 0 ]]; then |
| 55 | + echo "No style violations found." |
| 56 | +else |
| 57 | + for rule in "${triggeredDescriptions[@]}"; do |
| 58 | + echo "$rule" |
| 59 | + done |
| 60 | +fi |
| 61 | + |
| 62 | +exit $hadError |
0 commit comments