-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclazy.sh
More file actions
executable file
·116 lines (90 loc) · 3.23 KB
/
clazy.sh
File metadata and controls
executable file
·116 lines (90 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#!/bin/bash
set -x
options=()
extra_args=()
extra_args_before=()
files=()
for pair in $EXTRA_ARG; do
extra_args+=( "--extra-arg=$pair" )
done
for pair in $EXTRA_ARG_BEFORE; do
extra_args_before+=( "--extra-arg-before=$pair" )
done
if [ "$ONLY_QT" == "true" ]; then
options+=( "--only-qt" )
fi
if [ "$QT4_COMPAT" == "true" ]; then
options+=( "--qt4-compat" )
fi
if [ "$SUPPORTED_CHECKS_JSON" == "true" ]; then
options+=( "--supported-checks-json" )
fi
if [ "$VISIT_IMPLICIT_CODE" == "true" ]; then
options+=( "--visit-implicit-code" )
fi
pattern='^(.*?):([0-9]+):([0-9]+): (.+): (.+) \[(.*)\]$'
if [[ -n "$ONLY_DIFF" ]]; then
for file in $(git diff --name-only HEAD^1 HEAD); do
file_extension="${file##*.}"
if echo "$EXTENSIONS" | grep -q "$file_extension"; then
files+=("$(realpath "$file")")
fi
done
else
IFS=',' read -r -a extensions <<< "$EXTENSIONS"
for ext in "${extensions[@]}"; do
while IFS= read -r -d '' file; do
files+=($(realpath "$file"))
done < <(find . -name "*.$ext" -print0)
done
fi
export CLAZY_CHECKS="$CHECKS"
output=$(set -e; clazy-standalone -p="$DATABASE" \
--header-filter="$HEADER_FILTER" --ignore-dirs="$IGNORE_DIRS" \
"${options[@]}" "${extra_args[@]}" "${extra_args_before[@]}" "${files[@]}" 2>&1)
warnings_file=$(mktemp)
errors_file=$(mktemp)
trap 'rm -f "$warnings_file" "$errors_file"' EXIT
echo 0 > "$warnings_file"
echo 0 > "$errors_file"
declare -A warnings_seen
root_path=$(realpath -s "$ROOT_DIR")
echo "$output" | grep -E "$pattern" | while IFS= read -r line; do
if [[ $line =~ $pattern ]]; then
absolute_path="${BASH_REMATCH[1]}"
line_number="${BASH_REMATCH[2]}"
column_number="${BASH_REMATCH[3]}"
warning_type="${BASH_REMATCH[4]}"
warning_message="${BASH_REMATCH[5]}"
warning_code="${BASH_REMATCH[6]}"
warning_key="${absolute_path}:${line_number}:${column_number}:${warning_code}"
hash=$(echo -n "$warning_key" | md5sum | cut -d' ' -f1)
if [[ -n "${warnings_seen[$hash]:-}" ]]; then
continue
fi
warnings_seen["$warning_key"]=1
if [[ "$IGNORE_EXTERNAL_FILES" == "true" && "$absolute_path" != "$root_path"* ]]; then
continue
fi
if [[ "$IGNORE_HEADER_DEPS" == "true" ]] && [[ ! "${files[@]}" =~ "$absolute_path" ]]; then
continue
fi
if [[ "$warning_type" == "warning" ]]; then
echo "::warning file=$absolute_path,line=$line_number,col=$column_number::$warning_message [$warning_code]"
current_warnings=$(<"$warnings_file")
((current_warnings++))
echo "$current_warnings" > "$warnings_file"
fi
if [[ "$warning_type" == "error" ]]; then
echo "::error file=$absolute_path,line=$line_number,col=$column_number::$warning_message [$warning_code]"
current_errors=$(<"$errors_file")
((current_errors++))
echo "$current_errors" > "$errors_file"
fi
fi
done
warnings_count=$(<"$warnings_file")
errors_count=$(<"$errors_file")
echo "::set-output name=errors-count::$errors_count"
echo "::set-output name=warnings-count::$warnings_count"
rm -f "$warnings_file" "$errors_file"