diff --git a/.githooks/.gitkeep b/.githooks/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/.githooks/pre-commit b/.githooks/pre-commit new file mode 100755 index 000000000..208c401d8 --- /dev/null +++ b/.githooks/pre-commit @@ -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 \ No newline at end of file diff --git a/.swiftformat b/.swiftformat new file mode 100644 index 000000000..1a57e0ea0 --- /dev/null +++ b/.swiftformat @@ -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 \ No newline at end of file diff --git a/.swiftlint.yml b/.swiftlint.yml index 2bdb24d37..ff404805e 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -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 diff --git a/Makefile b/Makefile index 164be2f8e..089a56b90 100644 --- a/Makefile +++ b/Makefile @@ -25,4 +25,7 @@ module: swift Scripts/GenerateModule.swift setup: - sh Scripts/Setup.sh \ No newline at end of file + sh Scripts/Setup.sh + +format: + swiftformat ./Projects --config .swiftformat \ No newline at end of file