Skip to content

Commit

Permalink
Merge pull request #450 from wakmusic/417-swiftlint-and-swiftformat-s…
Browse files Browse the repository at this point in the history
…etting

🔀 :: (#417) SwiftLint와 SwiftFormat 설정
  • Loading branch information
baekteun authored Mar 9, 2024
2 parents 6cccf07 + b5c13f1 commit 27fc658
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 15 deletions.
Empty file removed .githooks/.gitkeep
Empty file.
41 changes: 41 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/sh

FORMAT=$(which swiftformat)

if [[ -e "${FORMAT}" ]]; then
echo "🚀 SwiftFormat 시작..."
echo "🔍 SwiftFormat 적용 경로: $(pwd)/Projects"
else
echo "SwiftFormat이 존재하지 않습니다. 설치해주세요 ! 'brew install swiftformat'"
exit 1
fi

RESULT=$($FORMAT ./Projects --config .swiftformat)

if [ "$RESULT" == '' ]; then
printf "\n 🎉 SwiftFormat 적용을 완료했습니다 !! \n"
else
echo ""
printf "❌ SwiftFormat 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"
printf " $FILEPATH:$L:$C\n"
printf " 📌 $MESSAGE: - $DESCRIPTION\n"
exit 0
elif [ $TYPE == 'error' ]; then
printf "\n 🚨 $TYPE\n"
fi
printf "$FILEPATH:$L:$C\n"
printf " 📌 $MESSAGE: - $DESCRIPTION\n"
done <<< "$RESULT"

printf "\n 🚑 커밋실패!! SwiftFormat 실행이 실패하였습니다 🥺 \n"
exit 1
fi
64 changes: 64 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@

--exclude fastlane,Tuist,Dependencies,Carthage

# options
--maxwidth 120
--indent 4
--trimwhitespace always # trailingSpace
--lineaftermarks false # fileHeader
--wraparguments before-first # wrapArguments
--wrapparameters before-first # wrapArguments
--wrapcollections before-first # wrapArguments

# rules
--rules anyObjectProtocol
--rules blankLineAfterImports
--rules blankLinesAroundMark
--rules blankLinesAtEndOfScope
--rules blankLinesAtStartOfScope
--rules blankLinesBetweenImports
--rules blankLinesBetweenScopes
--rules braces
--rules consecutiveBlankLines
--rules consecutiveSpaces
--rules docComments
--rules duplicateImports
--rules elseOnSameLine
--rules emptyBraces
--rules enumNamespaces
--rules extensionAccessControl
--rules fileHeader
--rules hoistAwait
--rules hoistPatternLet
--rules hoistTry
--rules initCoderUnavailable
--rules indent
--rules isEmpty
--rules leadingDelimiters
--rules linebreakAtEndOfFile
--rules modifierOrder
--rules numberFormatting
--rules opaqueGenericParameters
--rules redundantExtensionACL
--rules redundantOptionalBinding
--rules redundantParens
--rules redundantVoidReturnType
--rules semicolons
--rules sortImports
--rules spaceAroundBraces
--rules spaceAroundBrackets
--rules spaceAroundComments
--rules spaceAroundGenerics
--rules spaceAroundOperators
--rules spaceInsideBraces
--rules spaceInsideBrackets
--rules spaceInsideComments
--rules spaceInsideGenerics
--rules spaceInsideParens
--rules todos
--rules trailingClosures
--rules trailingSpace
--rules typeSugar
--rules void
--rules wrap
--rules wrapArguments
26 changes: 12 additions & 14 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
excluded:
- "**/*/NeedleGenerated.swift"
- "Tuist"
- "Plugin"

force_cast: # From https://realm.github.io/SwiftLint/force_cast.html
warning # 강제 캐스팅은 error에서 warning으로 변경

disabled_rules:
- trailing_whitespace
- vertical_whitespace
- colon
- comma
- comment_spacing # 주석 여백
- mark # //MARK 관련 warning
- opening_brace # 괄호 열 때 줄바꿈을 했는지 안했는지, (안했으면 warning)
- line_length # 한줄에 글자 수 제한 , warning: 120, error: 200 (default)
- statement_position # if는 반드시 else로 끝나야한다.
- identifier_name #변수명 글자 수 제한
- function_body_length
- function_parameter_count
- nesting
identifier_name:
min_length:
warning: 1

nesting:
type_label:
warning: 3

type_name:
max_length:
warning: 60
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,7 @@ module:
swift Scripts/GenerateModule.swift

setup:
sh Scripts/Setup.sh
sh Scripts/Setup.sh

format:
swiftformat ./Projects --config .swiftformat

0 comments on commit 27fc658

Please sign in to comment.