-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathpre-commit
More file actions
executable file
·38 lines (34 loc) · 1.15 KB
/
pre-commit
File metadata and controls
executable file
·38 lines (34 loc) · 1.15 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
#!/bin/bash
git diff --diff-filter=d --staged --name-only | grep -e '\.swift$' | while read line; do
if [[ $line == *"/Generated"* ]]; then
echo "IGNORING GENERATED FILE: " "$line";
else
mint run swiftformat swiftformat "${line}";
git add "$line";
fi
done
LINT=$(which mint)
if [[ -e "${LINT}" ]]; then
# Export files in SCRIPT_INPUT_FILE_$count to lint against later
count=0
while IFS= read -r file_path; do
export SCRIPT_INPUT_FILE_$count="$file_path"
count=$((count + 1))
done < <(git diff --name-only --cached --diff-filter=d | grep ".swift$")
export SCRIPT_INPUT_FILE_COUNT=$count
if [ "$count" -eq 0 ]; then
echo "No files to lint!"
exit 0
fi
echo "Found $count lintable files! Linting now.."
mint run swiftlint --use-script-input-files --strict --config .swiftlint.yml
RESULT=$? # swiftline exit value is number of errors
if [ $RESULT -eq 0 ]; then
echo "🎉 Well done. No violation."
fi
exit $RESULT
else
echo "⚠️ WARNING: SwiftLint not found"
echo "⚠️ You might want to edit .git/hooks/pre-commit to locate your swiftlint"
exit 0
fi