Debian Codegraph @

dev/tools/check-eof-newline.sh

raw symbols ◀ ▶ SCIP
1 Debian patch touch this file
•1 #!/usr/bin/bashscip-shell filesystem . . `/usr/bin/bash`.
2
3 # Usage: check-eof-newline.sh [--fix] FILES...
4 # Detect missing end of file newlines for FILES.
5 # Files are skipped if untracked by git and depending on gitattributes.
6 # With --fix, automatically append a newline.
7 # Exit status:
8 # Without --fix: 1 if any file had a missing newline, 0 otherwise.
9 # With --fix: 1 if any non writable file had a missing newline, 0 otherwise.
10
11 FIX=
12 if [scip-shell system . . `[`. "$1" = --fix ];
13 then
14 FIX=1
15 shift
16 fi
17
18 REDBOLD="\033[31m"
19 YELLOW="\033[33m"
20 RESET="\033[0m"
21
22 function colorprintscip-shell shell shell-project 0.0.0 colorprint().
23 {
24 if [scip-shell system . . `[`. "$COQ_CI_COLOR" ]; then
25 printfscip-shell system . . printf. "$1%s$RESET\n" "$2"
26 else
27 printfscip-shell system . . printf. '%s\n' "$2"
28 fi
29 }
30
31 CODE=0
32 for f in "$@"; do
33 if gitscip-shell system . . git. ls-files --error-unmatch "$f" >/dev/nullscip-shell filesystem . . `/dev/null`. 2>&1 && \
34 git check-attr whitespace -- "$f" | grepscip-shell system . . grep. -q -v -e 'unset$' -e 'unspecified$' && \
35 [ -n "$(tailscip-shell system . . tail. -c 1 "$f")" ]
36 then
37 if [scip-shell system . . `[`. -n "$FIX" ];
38 then
39 if [scip-shell system . . `[`. -w "$f" ];
40 then
41 echoscip-shell system . . echo. >> "$f"
42 colorprintscip-shell shell shell-project 0.0.0 colorprint(). "$YELLOW" "Newline appended to file $f!"
43 else
44 colorprintscip-shell shell shell-project 0.0.0 colorprint(). "$REDBOLD" "File $f is missing a newline and not writable!"
45 CODE=1
46 fi
47 else
48 colorprintscip-shell shell shell-project 0.0.0 colorprint(). "$REDBOLD" "No newline at end of file $f!"
49 CODE=1
50 fi
51 fi
52 done
53
54 exit "$CODE"