Skip to content

Instantly share code, notes, and snippets.

@dimohamdy
Created January 8, 2021 01:07
Show Gist options
  • Save dimohamdy/b32b31958e5b11452afb6e70828a1c15 to your computer and use it in GitHub Desktop.
Save dimohamdy/b32b31958e5b11452afb6e70828a1c15 to your computer and use it in GitHub Desktop.
Swiftlint changes only
# Run SwiftLint
#https://github.com/realm/SwiftLint/issues/413#issuecomment-184077062
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} autocorrect --path "${filename}"
${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."
@dimohamdy
Copy link
Author

swiftlint autocorrect for only chaned files

@dimohamdy
Copy link
Author

dimohamdy commented Jan 23, 2021

Run this command
open -e ~/.zshrc
Then add this to file
alias swiftlintme='~/swiftlintchanges.command'
Then run this command in terminal to reload
source ~/.zshrc

@dimohamdy
Copy link
Author

May you need to change to .zshrc, .profile, .bashrc, .bash_profile

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment