forked from vectordotdev/vector
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck-style.sh
More file actions
executable file
·90 lines (80 loc) · 1.95 KB
/
check-style.sh
File metadata and controls
executable file
·90 lines (80 loc) · 1.95 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
#!/usr/bin/env bash
set -euo pipefail
# check-style.sh
#
# SUMMARY
#
# Checks that all text files have correct line endings and no trailing spaces.
if [ "${1:-}" == "--fix" ]; then
MODE="fix"
else
MODE="check"
fi
ised() {
local PAT="$1"
local FILE="$2"
# In-place `sed` that uses the form of `sed -i` which works
# on both GNU and macOS.
sed -i.bak "$PAT" "$FILE"
rm "$FILE.bak"
}
EXIT_CODE=0
for FILE in $(git ls-files); do
# Ignore binary files and generated files.
case "$FILE" in
*png) continue;;
*svg) continue;;
*gif) continue;;
*ico) continue;;
*sig) continue;;
*html) continue;;
tests/data*) continue;;
lib/codecs/tests/data*) continue;;
lib/vector-core/tests/data*) continue;;
distribution/kubernetes/*/*.yaml) continue;;
tests/helm-snapshots/*/snapshot.yaml) continue;;
lib/remap-tests/tests/*.vrl) continue;;
lib/datadog/grok/patterns/*.pattern) continue;;
esac
# Skip all directories (usually this only happens when we have symlinks).
if [[ -d "$FILE" ]]; then
continue
fi
# check that the file contains trailing newline
if [ -n "$(tail -c1 "$FILE" | tr -d $'\n')" ]; then
case "$MODE" in
check)
echo "File \"$FILE\" doesn't end with a newline"
EXIT_CODE=1
;;
fix)
echo >> "$FILE"
;;
esac
fi
# check that the file uses LF line breaks
if grep $'\r$' "$FILE" > /dev/null; then
case "$MODE" in
check)
echo "File \"$FILE\" contains CRLF line breaks instead of LF line breaks"
EXIT_CODE=1
;;
fix)
ised 's/\r$//' "$FILE"
;;
esac
fi
# check that the lines don't contain trailing spaces
if grep ' $' "$FILE" > /dev/null; then
case "$MODE" in
check)
echo "File \"$FILE\" contains trailing spaces in some of the lines"
EXIT_CODE=1
;;
fix)
ised 's/ *$//' "$FILE"
;;
esac
fi
done
exit "$EXIT_CODE"