-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added swiftformat to precommit script and docs
- Loading branch information
Showing
2 changed files
with
36 additions
and
27 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,37 @@ | ||
#!/bin/bash | ||
|
||
if ! command -v swiftlint 2>&1 >/dev/null | ||
then | ||
|
||
echo "install swiftlint \(v0.0.57\) for pre-commit linting." | ||
exit 0 | ||
fi | ||
|
||
if [ "$(swiftlint --version)" != "0.57.1" ] | ||
then | ||
echo "swiftlint installed with incorrect version (`swiftlint --version`). Please use version 0.57.1 for pre-commit linting." | ||
exit 0 | ||
fi | ||
OIFS="$IFS" | ||
IFS=$'\n' | ||
FILE_LIST=($(git diff --cached --name-only | grep "\.swift$")) | ||
IFS="$OIFS" | ||
|
||
if [ -z "${FILE_LIST}" ]; then | ||
exit 0 | ||
fi | ||
# if [ -z "${FILE_LIST}" ]; then | ||
# exit 0 | ||
# fi | ||
|
||
if [ -e $(command -v swiftlint 2>&1 >/dev/null) ] && [ "$(swiftlint --version)" == "0.57.1" ] | ||
then | ||
swiftlint lint --config .swiftlint.yml --strict "${FILE_LIST[@]}" | ||
RESULT=$? | ||
if [ $RESULT -ne 0 ]; then | ||
echo -e "Swiftlint failed!\n Fix issues above or run:\n\tswiftlint lint --fix $(printf "\"%s\" " "${FILE_LIST[@]}")" | ||
echo "Skip linting with '--no-verify'." | ||
exit 1 | ||
fi | ||
echo "Swiftlint passed!" | ||
else | ||
echo "Install SwiftLint at version 0.57.1 to enable pre-commit linting." | ||
fi | ||
|
||
swiftlint lint --config .swiftlint.yml --strict "${FILE_LIST[@]}" | ||
RESULT=$? | ||
if [ $RESULT -ne 0 ]; then | ||
echo -e "Swiftlint failed!\n Fix issues above or run:\n\tswiftlint lint --fix $(printf "\"%s\" " "${FILE_LIST[@]}")" | ||
echo "Skip linting with '--no-verify'." | ||
exit 1 | ||
fi | ||
echo "Swiftlint passed!" | ||
exit 1 | ||
if [ -e $(command -v swiftformat 2>&1 > /dev/null) ]; then | ||
swiftformat --lint "${FILE_LIST[@]}" | ||
RESULT=$? | ||
if [ $RESULT -ne 0 ]; then | ||
echo -e "Swiftformat linting failed.\n Fix the issues above or run:\n\tswiftformat $(printf "\"%s\" " "${FILE_LIST[@]}")" | ||
echo "Skip linting with '--no-verify'." | ||
exit 1 | ||
fi | ||
echo "SwiftFormat passed!" | ||
else | ||
echo "Install swiftformat to enable pre-commit format linting." | ||
fi |