-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] Githook pre-commit SwiftLint μ μ©(#12)
- Loading branch information
Showing
1 changed file
with
53 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
#!/bin/sh | ||
LINT=$(which swiftlint) | ||
|
||
if [[ -e "${LINT}" ]]; then | ||
echo "π SwiftLint μμ..." | ||
echo "π lint μ μ© κ²½λ‘: $(pwd)" | ||
count=0 | ||
for file_path in $(git ls-files -m --exclude-from=.gitignore | grep ".swift$"); do | ||
export SCRIPT_INPUT_FILE_$count=$file_path | ||
count=$((count + 1)) | ||
done | ||
else | ||
echo "SwiftLintκ° μ‘΄μ¬νμ§ μμ΅λλ€, 곡μλ¬Έμλ₯Ό νμΈν΄μ£ΌμΈμ. π https://github.com/realm/SwiftLint" | ||
exit 1 | ||
fi | ||
|
||
##### Check for modified files in unstaged/Staged area ##### | ||
for file_path in $(git diff --name-only --cached | grep ".swift$"); do | ||
export SCRIPT_INPUT_FILE_$count=$file_path | ||
count=$((count + 1)) | ||
done | ||
|
||
export SCRIPT_INPUT_FILE_COUNT=$count | ||
|
||
echo "${SCRIPT_INPUT_FILE_COUNT}" | ||
|
||
# lint rule μ μ νμΌ | ||
RESULT=$($LINT lint --quiet --use-script-input-files --config .precommit.yml) | ||
|
||
if [ "$RESULT" == '' ]; then | ||
printf "β¨ SwiftLint μ μ©μ μλ£νμ΅λλ€!! κ³ μνμ ¨μ΅λλ€π π π\n" | ||
else | ||
echo "" | ||
printf "β SwiftLint Failed μλ λ΄μ©μ νμΈν΄μ£ΌμΈμ:\n" | ||
while read -r line; do | ||
FILEPATH=$(echo $line | cut -d : -f 1) | ||
L=$(echo $line | cut -d : -f 2) | ||
C=$(echo $line | cut -d : -f 3) | ||
TYPE=$(echo $line | cut -d : -f 4 | cut -c 2-) | ||
MESSAGE=$(echo $line | cut -d : -f 5 | cut -c 2-) | ||
DESCRIPTION=$(echo $line | cut -d : -f 6 | cut -c 2-) | ||
if [ $TYPE == 'warning' ]; then | ||
printf "\n π§ $TYPE\n" | ||
elif [ $TYPE == 'error' ]; then | ||
printf "\n π¨ $TYPE\n" | ||
fi | ||
printf " β $FILEPATH:$L:$C\n" | ||
printf " π $MESSAGE: - $DESCRIPTION\n" | ||
done <<< "$RESULT" | ||
|
||
printf "\n π 컀λ°μ€ν¨!! Swiftlint ruleμ λ§κ² μ½λλ₯Ό λ³κ²½ν΄μ£ΌμΈμ:)\n" | ||
exit 1 | ||
fi |