forked from splitwise/super_diff
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlint-changed-files.sh
executable file
·64 lines (53 loc) · 1.37 KB
/
lint-changed-files.sh
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
#!/bin/bash
get-files-to-lint() {
local flag="$1"
local current_branch_name="$(git branch --show-current)"
if [[ "$current_branch_name" == "main" ]]; then
git diff origin/main...HEAD --name-only --diff-filter=d
else
git diff main...HEAD --name-only --diff-filter=d
fi
if [[ $flag == "--include-uncommitted" ]]; then
git diff --name-only --diff-filter=d
fi
}
main() {
local prettier_flag
local include_uncommitted_flag
while [[ -n "$1" ]]; do
case "$1" in
--check | --write)
prettier_flag="$1"
shift
;;
--include-uncommitted)
include_uncommitted_flag="$1"
shift
;;
*)
echo "ERROR: Unknown option $1."
exit 1
;;
esac
done
local files_to_lint="$(get-files-to-lint "$include_uncommitted_flag")"
if [[ -z "$prettier_flag" ]]; then
echo "ERROR: Missing --check or --write."
exit 1
fi
echo "*** Checking for lint violations in changed files ***************"
echo
if [[ -n "$files_to_lint" ]]; then
echo "Files to check:"
echo "$files_to_lint" | while IFS=$'\n' read -r line; do
echo "- $line"
done
echo
echo "$files_to_lint" | while IFS=$'\n' read -r line; do
printf '%s\0' "$line"
done | xargs -0 yarn prettier "$prettier_flag" --ignore-unknown
else
echo "No files to lint this time."
fi
}
main "$@"