-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclang-check.sh
More file actions
executable file
·52 lines (47 loc) · 1.17 KB
/
clang-check.sh
File metadata and controls
executable file
·52 lines (47 loc) · 1.17 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
#!/bin/bash
set -euo pipefail
# Supported extensions
supported_ext=("c" "h" "cpp" "hpp")
# Check if a file is supported
is_supported_file() {
local file="$1"
local ext="${file##*.}"
for e in "${supported_ext[@]}"; do
[[ "$ext" == "$e" ]] && return 0
done
return 1
}
# Run clang-format in dry-run mode on a single file
format_file() {
local file="$1"
if is_supported_file "$file"; then
echo "Check Formatting $file"
clang-format --dry-run --Werror "$file"
else
echo "Skipping unsupported file: $file"
fi
}
# Run clang-format on a glob pattern recursively
format_pattern() {
local pattern="$1"
# Find files matching the pattern
find . -type f -iname "$pattern" ! -path "./.git/*" -print0 | while IFS= read -r -d '' file; do
format_file "$file"
done
}
# Main
if [ "$#" -eq 0 ]; then
# Default: format all supported files
for ext in "${supported_ext[@]}"; do
format_pattern "*.$ext"
done
else
for arg in "$@"; do
if [ -f "$arg" ]; then
format_file "$arg"
else
# Treat as a pattern
format_pattern "$arg"
fi
done
fi