5 # Assumption: file names don't contain `:` (for the `cut` invocation).
6 # Safe to assume, as such a character in a filename would cause trouble on Windows, a platform we support
8 # any regression turn this non-zero
11 # exclusions (these are just grep extended regular expressions to match against paths relative to the root of the repository)
12 exclusions_nonutf8
='(.*(7z|gif|ic(ns|o)|png|qm|zip))'
13 exclusions_bom
='src/base/unicodestrings.h'
14 exclusions_tw
='(*.ts)|src/webui/www/private/scripts/lib/*'
15 exclusions_trailing_newline
='configure'
16 exclusions_no_lf
='(*.ts)|(.*svg)|compile_commands.json|src/webui/www/private/scripts/lib/*'
18 echo -e "\n*** Detect files not encoded in UTF-8 ***\n"
20 find .
-path .
/build
-prune -false -o -path .
/.git
-prune -false -o -type f
-exec file --mime {} \
; |
sort \
21 |
grep -v -e "charset=us-ascii" -e "charset=utf-8" | cut
-d ":" -f 1 \
22 |
grep -E -v -e "${exclusions_nonutf8}" \
23 |
tee >(echo -e "--> Files not encoded in UTF-8: found" "$(wc -l < /dev/stdin)" "regression(s)\n") \
24 |
xargs -I my_input
-0 bash
-c 'echo "my_input"; test "$(echo -n "my_input" | wc -l)" -eq 0'
25 regressions
=$
((regressions
+$?
))
27 echo -e "\n*** Detect files encoded in UTF-8 with BOM ***\n"
29 grep --exclude-dir={.git
,build
} -rIl $
'\xEF\xBB\xBF' |
sort \
30 |
grep -E -v -e "${exclusions_bom}" \
31 |
tee >(echo -e "--> Files encoded in UTF-8 with BOM: found" "$(wc -l < /dev/stdin)" "regression(s)\n") \
32 |
xargs -I my_input
-0 bash
-c 'echo "my_input"; test "$(echo -n "my_input" | wc -l)" -eq 0'
33 regressions
=$
((regressions
+$?
))
35 echo -e "\n*** Detect usage of CR byte ***\n"
37 grep --exclude-dir={.git
,build
} -rIlU $
'\x0D' |
sort \
38 |
tee >(echo -e "--> Usage of CR byte: found" "$(wc -l < /dev/stdin)" "regression(s)\n") \
39 |
xargs -I my_input
-0 bash
-c 'echo "my_input"; test "$(echo -n "my_input" | wc -l)" -eq 0'
40 regressions
=$
((regressions
+$?
))
42 echo -e "\n*** Detect trailing whitespace in lines ***\n"
44 grep --exclude-dir={.git
,build
} -rIl "[[:blank:]]$" |
sort \
45 |
grep -E -v -e "${exclusions_tw}" \
46 |
tee >(echo -e "--> Trailing whitespace in lines: found" "$(wc -l < /dev/stdin)" "regression(s)\n") \
47 |
xargs -I my_input
-0 bash
-c 'echo "my_input"; test "$(echo -n "my_input" | wc -l)" -eq 0';
48 regressions
=$
((regressions
+$?
))
50 echo -e "\n*** Detect too many trailing newlines ***\n"
52 find .
-path .
/build
-prune -false -o -path .
/.git
-prune -false -o -type f
-exec file --mime {} \
; |
sort \
53 |
grep -e "charset=us-ascii" -e "charset=utf-8" | cut
-d ":" -f 1 \
54 |
grep -E -v -e "${exclusions_trailing_newline}" \
55 |
xargs -L1 -I my_input bash
-c 'test "$(tail -q -c2 "my_input" | hexdump -C | grep "0a 0a")" && echo "my_input"' \
56 |
tee >(echo -e "--> Too many trailing newlines: found" "$(wc -l < /dev/stdin)" "regression(s)\n") \
57 |
xargs -I my_input
-0 bash
-c 'echo "my_input"; test "$(echo -n "my_input" | wc -l)" -eq 0'
58 regressions
=$
((regressions
+$?
))
60 echo -e "\n*** Detect no trailing newline ***\n"
62 find .
-path .
/build
-prune -false -o -path .
/.git
-prune -false -o -type f
-exec file --mime {} \
; |
sort \
63 |
grep -e "charset=us-ascii" -e "charset=utf-8" | cut
-d ":" -f 1 \
64 |
grep -E -v -e "${exclusions_no_lf}" \
65 |
xargs -L1 -I my_input bash
-c 'test "$(tail -q -c1 "my_input" | hexdump -C | grep "0a")" || echo "my_input"' \
66 |
tee >(echo -e "--> No trailing newline: found" "$(wc -l < /dev/stdin)" "regression(s)\n") \
67 |
xargs -I my_input
-0 bash
-c 'echo "my_input"; test "$(echo -n "my_input" | wc -l)" -eq 0'
68 regressions
=$
((regressions
+$?
))
70 echo -e "\n*** Detect translation closing tag in new line ***\n"
72 grep --exclude-dir={.git
,build
} -nri "^</translation>" |
sort \
74 |
tee >(echo -e "--> Translation closing tag in new line: found" "$(wc -l < /dev/stdin)" "regression(s)\n") \
75 |
xargs -I my_input
-0 bash
-c 'echo "my_input"; test "$(echo -n "my_input" | wc -l)" -eq 0'
76 regressions
=$
((regressions
+$?
))
78 if [ "$regressions" -ne 0 ]; then
80 echo "\nFile health regressions found. Please fix them (or add them as exclusions)."
82 echo "All OK, no file health regressions found."