I found this shell script
# Run SwiftLint
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."
Over here https://github.com/realm/SwiftLint/issues/413#issuecomment-184077062
Which worked pretty well till I updated my computer to the new M1 chip.
According to this blog https://www.anotheriosdevblog.com/installing-swiftlint-on-a-m1/ We should change the location of the path. I suspect it has something to do with the location SwiftLint is installed:
However I'm not to familiar with home-brew or shell script to get it working.
Home-brew location has changed on the new Macs.
changing
SWIFT_LINT=/usr/local/bin/swiftlint
to
SWIFT_LINT=/opt/homebrew/bin/swiftlint
Fixed the issue