-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_swiftlint.sh
executable file
·33 lines (24 loc) · 1.08 KB
/
run_swiftlint.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
# Run SwiftLint
set -o xtrace
START_DATE=$(date +"%s")
SWIFT_LINT=/usr/local/bin/swiftlint
if [[ -e "${SWIFT_LINT}" ]]; then
echo "SwiftLint version: $(${SWIFT_LINT} version)"
# Run for both staged and unstaged files
SWIFT_GIT_DIFF="$(git diff --name-only | grep '\.swift' | tr '\n' ' ' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
SWIFT_CACHED_DIFF="$(git diff --cached --name-only | grep '\.swift' | tr '\n' ' ' | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
ALL_SWIFT_DIFF="$(echo "${SWIFT_GIT_DIFF} ${SWIFT_CACHED_DIFF}" | sed -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')"
echo ${ALL_SWIFT_DIFF}
if [[ $ALL_SWIFT_DIFF != "" ]]; then
${SWIFT_LINT} autocorrect --format ${ALL_SWIFT_DIFF}
${SWIFT_LINT} lint ${ALL_SWIFT_DIFF}
fi
else
echo "SwifLint is not installed."
echo "Expected location is '${SWIFT_LINT}'"
echo "Please install it. eg. 'brew install swiftlint'"
exit 1
fi
END_DATE=$(date +"%s")
DIFF=$(($END_DATE - $START_DATE))
echo "SwiftLint took $(($DIFF / 60)) minutes and $(($DIFF % 60)) seconds to complete."