Last active
July 24, 2022 15:09
-
-
Save bennokress/a1ee2071c4b61bc7c9ea75f4a37e9ab8 to your computer and use it in GitHub Desktop.
My standard code formatting definitions using SwiftFormat by nicklockwood.
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
# File options | |
--exclude Pods | |
# Rules | |
## Enabled | |
--enable andOperator | |
--enable anyObjectProtocol | |
--enable assertionFailures | |
--enable blankLinesBetweenScopes | |
--enable blockComments | |
--enable braces | |
--enable consecutiveBlankLines | |
--enable consecutiveSpaces | |
--enable duplicateImports | |
--enable elseOnSameLine | |
--enable emptyBraces | |
--enable extensionAccessControl | |
--enable fileHeader | |
--enable hoistPatternLet | |
--enable initCoderUnavailable | |
--enable isEmpty | |
--enable leadingDelimiters | |
--enable linebreakAtEndOfFile | |
--enable linebreaks | |
--enable modifierOrder | |
--enable preferDouble | |
--enable preferKeyPath | |
--enable redundantBackticks | |
--enable redundantBreak | |
--enable redundantClosure | |
--enable redundantExtensionACL | |
--enable redundantFileprivate | |
--enable redundantGet | |
--enable redundantInit | |
--enable redundantLet | |
--enable redundantLetError | |
--enable redundantNilInit | |
--enable redundantObjc | |
--enable redundantParens | |
--enable redundantPattern | |
--enable redundantRawValues | |
--enable redundantReturn | |
--enable redundantSelf | |
--enable redundantType | |
--enable redundantVoidReturnType | |
--enable semicolons | |
--enable sortedImports | |
--enable sortedSwitchCases | |
--enable spaceAroundBraces | |
--enable spaceAroundBrackets | |
--enable spaceAroundComments | |
--enable spaceAroundGenerics | |
--enable spaceAroundOperators | |
--enable spaceAroundParens | |
--enable spaceInsideBraces | |
--enable spaceInsideBrackets | |
--enable spaceInsideComments | |
--enable spaceInsideGenerics | |
--enable spaceInsideParens | |
--enable strongifiedSelf | |
--enable strongOutlets | |
--enable todos | |
--enable trailingClosures | |
--enable trailingSpace | |
--enable typeSugar | |
--enable void | |
--enable wrapEnumCases | |
--enable yodaConditions | |
## Disabled | |
--disable acronyms # -> More often than not this breaks API and Backend Call Implementations | |
--disable blankLinesAroundMark # -> Normally correct, but not for Comments after the MARK | |
--disable blankLinesAtEndOfScope # -> disabled until it is possible to add 1 line for classes, structs & enums, but 0 for func etc. --> https://github.com/nicklockwood/SwiftFormat/issues/261 | |
--disable blankLinesAtStartOfScope # -> disabled until it is possible to add 1 line for classes, structs & enums, but 0 for func etc. --> https://github.com/nicklockwood/SwiftFormat/issues/261 | |
--disable blankLinesBetweenImports # -> Normally correct, but I write the @testable import first, then a blank line and then the alphabetized list of imports | |
--disable enumNamespaces # -> Caseless enums should be avoided in my opinion | |
--disable indent # -> This destroys clarity in too many cases | |
--disable markTypes # -> MARK Comments are not always preferential | |
--disable numberFormatting # -> When working on banking related projects we have different formatting for things like bank codes than we have on normal numbers. Those can't be automatically detected. | |
--disable organizeDeclarations # -> Properties & Methods sometimes have more clarity when ordered semantically | |
--disable sortDeclarations # -> Too much overhead having to write // swiftformat:sort in files | |
--disable trailingCommas # -> A comma after the last element of a collection is never necessary | |
--disable unusedArguments # -> This destroys some Protocol implementations (applicationDidLaunch etc.) | |
--disable wrap # -> I have a widescreen monitor, I don't need wrapping | |
--disable wrapArguments # -> Normally I don't wrap arguments and if I do, it is decided on a case-by-case basis | |
--disable wrapAttributes # -> Wanted behavior: prev-line for func and computed properties, same-line for normal properties and types --> https://github.com/nicklockwood/SwiftFormat/issues/1232 | |
--disable wrapConditionalBodies # -> Please don't! 1 line guard statements should always be written in one line in my opinion | |
--disable wrapSwitchCases # -> Sometimes having all cases in one line is okay! | |
--disable wrapMultilineStatementBraces # -> Objective-C is dying for many reasons ... and this is one of them! | |
# Format options | |
--allman false | |
--closurevoid remove | |
--elseposition same-line | |
--emptybraces spaced | |
--extensionacl on-extension | |
--guardelse same-line | |
--header "\n📄 {file}\n👨🏼💻 Author: Benno Kress\n🗓️ Created: {created}\n" | |
--ifdef indent | |
--importgrouping alpha | |
--indent 4 | |
--indentcase false | |
--linebreaks lf | |
--modifierorder optional,required,convenience,override,indirect,private,fileprivate,internal,public,open,private(set),fileprivate(set),internal(set),public(set),final,dynamic,lazy,static,class,weak,unowned,mutating,nonmutating,prefix,postfix | |
--operatorfunc spaced | |
--patternlet hoist | |
--ranges spaced | |
--redundanttype inferred | |
--self init-only | |
--semicolons inline | |
--shortoptionals always | |
--smarttabs enabled | |
--stripunusedargs always | |
--swiftversion 5.2.4 | |
--tabwidth 4 | |
--trimwhitespace always | |
--voidtype void | |
--xcodeindentation disabled | |
--yodaswap always | |
# Wait for wrapAttributes to support differentiation of stored and computed properties --> https://github.com/nicklockwood/SwiftFormat/issues/1232 | |
# --funcattributes prev-line | |
# --typeattributes prev-line | |
# --varattributes same-line # but not for computed properties |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment