Skip to content

Instantly share code, notes, and snippets.

@dimohamdy
Created July 23, 2023 11:59
Show Gist options
  • Save dimohamdy/f638dac39d05b324d5ed36b03f75e2ba to your computer and use it in GitHub Desktop.
Save dimohamdy/f638dac39d05b324d5ed36b03f75e2ba to your computer and use it in GitHub Desktop.
Lint changed files 🤖
# 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