Created
March 20, 2018 11:08
-
-
Save nzatsepilov/5cff25f1d897a4243095dd1cf5a1f995 to your computer and use it in GitHub Desktop.
Swiftlint script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
START_DATE=$(date +"%s") | |
SWIFT_LINT=/usr/local/bin/swiftlint | |
# Run SwiftLint for given filename | |
run_swiftlint() { | |
local filename="${1}" | |
if [[ "${filename##*.}" == "swift" ]]; then | |
${SWIFT_LINT} lint --path "${filename}" | |
fi | |
} | |
if [[ -e "${SWIFT_LINT}" ]]; then | |
echo "SwiftLint version: $(${SWIFT_LINT} version)" | |
# Run for both staged and unstaged files | |
git diff --name-only | while read filename; do run_swiftlint "${filename}"; done | |
git diff --cached --name-only | while read filename; do run_swiftlint "${filename}"; done | |
else | |
echo "${SWIFT_LINT} is not installed." | |
exit 0 | |
fi | |
END_DATE=$(date +"%s") | |
DIFF=$(($END_DATE - $START_DATE)) | |
echo "SwiftLint took $(($DIFF / 60)) minutes and $(($DIFF % 60)) seconds to complete." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment