-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint
executable file
·52 lines (44 loc) · 1.75 KB
/
lint
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
#!/bin/bash
set -e
bad_allocs=$(egrep -iR "(malloc\(|calloc\(|realloc\(| free\()" --exclude "alloc.h" --exclude "file.h" --exclude-dir "./html" | tee)
if [[ "$bad_allocs" ]]; then
printf "\r\e[KInvalid allocation: Use malloc_, calloc_, realloc_, or free_:\n$bad_allocs\n" >&2
exit 1
fi
bad_files=$(egrep -iR "(fopen\(|fclose\()" --exclude "file.h" --exclude-dir "./html" | tee)
if [[ "$bad_files" ]]; then
printf "\r\e[KInvalid file: Use fopen_ or fclose_:\n$bad_files\n" >&2
exit 1
fi
find . -name "*.c" -type f -not -path "./tests/.test.c" -print0 | while read -d $'\0' file; do
filename=$(basename "$file")
name="${filename%.*}"
found=$(grep "bin/$name" "$file" | tee)
if [[ ! "$found" ]]; then
printf "\r\e[KInvalid binary name: $file\n" >&2
exit 1
fi
done
find ./src -name "*.h" -type f -print0 | while read -d $'\0' file; do
filename=$(basename "$file")
name="${filename%.*}"
upper=$(echo "$name" | tr '[:lower:]' '[:upper:]')
found_guard=$(grep "CSYNTH_${upper}_H" "$file" | tee)
if [[ ! "$found_guard" ]]; then
printf "\r\e[KInvalid include guard: $file\n" >&2
exit 1
fi
folder=$(dirname "$file")
parent=$(basename "$folder")
ignores=("notes.h" "envelopes.h" "time.h" "biquad.h" "times.h" "func_tools.h")
if [[ "${parent}s" != "$name" ]] && [[ ! " ${ignores[*]} " =~ " ${filename} " ]]; then
found_prefix=$(grep "^[^ {}#/]" "$file" | grep -v "\([ *]${name}_\|[ *]${upper}_\|typedef\|struct\)" | tee)
if [[ "$found_prefix" ]]; then
printf "\r\e[KInvalid declaration: $file\n$found_prefix\n" >&2
exit 1
fi
fi
done
clang-tidy ./src/func/all.h
find . -name '*.h' | xargs clang-tidy
find . -name '*.c' | xargs clang-tidy