Created
July 23, 2023 11:59
-
-
Save dimohamdy/f638dac39d05b324d5ed36b03f75e2ba to your computer and use it in GitHub Desktop.
Lint changed files 🤖
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
# Run SwiftLint | |
#https://github.com/realm/SwiftLint/issues/413#issuecomment-184077062 | |
START_DATE=$(date +"%s") | |
SWIFTLINT="${PODS_ROOT}/SwiftLint/swiftlint" | |
# Run SwiftLint for given filename | |
run_swiftlint() { | |
local filename="${SRCROOT}/../${1}" | |
if [[ "${filename##*.}" == "swift" ]]; then | |
echo "⛔️ ${filename}" | |
${SWIFTLINT} --fix "${filename}" | |
fi | |
} | |
# Check if SwiftLint is installed | |
if which "$SWIFTLINT" > /dev/null; then | |
echo "SwiftLint version: $(${SWIFTLINT} 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 "${SWIFTLINT} 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