Skip to content

Commit

Permalink
Introduce Swiftformat (#14)
Browse files Browse the repository at this point in the history
* Introduce Swiftformat

* Inline let

* Run swift format
  • Loading branch information
mikhailmaslo authored Feb 3, 2023
1 parent 91f8331 commit b847e09
Show file tree
Hide file tree
Showing 19 changed files with 295 additions and 120 deletions.
133 changes: 133 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Tool options
--minversion 0.48.11
--swiftversion 5.4

# Format options
--assetliterals visual-width
--beforemarks
# Uncomment if we decide to enable `organizeDeclarations` rule
#--categorymark "MARK: - %c"
--conflictmarkers reject
--exponentcase lowercase
--extensionmark "MARK: - %t + %c"
--fragment false
--funcattributes prev-line
--groupedextension "MARK: %c"
--guardelse auto
--header ignore
--hexgrouping none
--hexliteralcase lowercase
--ifdef no-indent
--importgrouping alpha
--indent 4
--indentcase false
--lifecycle
--linebreaks lf
--markextensions always
--marktypes always
--maxwidth none
--modifierorder acl,setteracl,override,dynamic,mutators,lazy,final,class,static,required,convenience,typemethods,owned
--nevertrailing
--nospaceoperators ...,..<
--nowrapoperators
--octalgrouping none
--organizetypes actor,class,enum,struct
--patternlet inline
--ranges spaced # ???
--redundanttype inferred
--self init-only
--selfrequired
--semicolons never
--smarttabs enabled
# Uncomment if we decide to enable `unusedArguments` rule
#--stripunusedargs closure-only
--structthreshold 0
--tabwidth unspecified
--trailingclosures
--trimwhitespace always
--typeattributes prev-line
--typemark "MARK: - %t"
--varattributes prev-line
--voidtype void
--wraparguments before-first
--wrapcollections before-first
--wrapconditions before-first
--wrapparameters before-first
--wrapreturntype preserve
--xcodeindentation disabled

# Rules
--rules andOperator
--rules anyObjectProtocol
--rules blankLinesAroundMark
--rules blankLinesAtEndOfScope
--rules blankLinesAtStartOfScope
--rules blankLinesBetweenScopes
--rules braces
--rules consecutiveBlankLines
--rules consecutiveSpaces
--rules duplicateImports
--rules elseOnSameLine
--rules emptyBraces
--disable enumNamespaces
--rules extensionAccessControl
--disable fileHeader
--rules hoistPatternLet
--rules indent
--rules initCoderUnavailable
--disable isEmpty
--rules leadingDelimiters
--rules linebreakAtEndOfFile
--rules linebreaks
--disable markTypes
--rules modifierOrder
--rules numberFormatting
--disable organizeDeclarations
--disable preferKeyPath
--rules redundantBackticks
--rules redundantBreak
--rules redundantExtensionACL
--rules redundantFileprivate
--rules redundantGet
--rules redundantInit
--rules redundantLet
--rules redundantLetError
--rules redundantNilInit
--rules redundantObjc
--rules redundantParens
--rules redundantPattern
--rules redundantRawValues
--rules redundantReturn
--rules redundantSelf
--rules redundantType
--rules redundantVoidReturnType
--rules semicolons
--rules sortedImports
--disable sortedSwitchCases
--rules spaceAroundBraces
--rules spaceAroundBrackets
--rules spaceAroundComments
--rules spaceAroundGenerics
--rules spaceAroundOperators
--rules spaceAroundParens
--rules spaceInsideBraces
--rules spaceInsideBrackets
--rules spaceInsideComments
--rules spaceInsideGenerics
--rules spaceInsideParens
--rules strongOutlets
--rules strongifiedSelf
--rules todos
--rules trailingClosures
--rules trailingCommas
--rules trailingSpace
--rules typeSugar
--disable unusedArguments
--rules void
--disable wrap
--rules wrapArguments
--rules wrapAttributes
--rules wrapEnumCases
--rules wrapMultilineStatementBraces
--disable wrapSwitchCases
--rules yodaConditions
22 changes: 22 additions & 0 deletions BottomSheetDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@
isa = PBXNativeTarget;
buildConfigurationList = 7D05F32E274139E100EBDBB1 /* Build configuration list for PBXNativeTarget "BottomSheet" */;
buildPhases = (
7D1A478E298DC8C2004832D4 /* Swiftformat */,
7D05F326274139E100EBDBB1 /* Sources */,
7D05F327274139E100EBDBB1 /* Frameworks */,
7D05F328274139E100EBDBB1 /* CopyFiles */,
Expand Down Expand Up @@ -488,6 +489,27 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
7D1A478E298DC8C2004832D4 /* Swiftformat */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = Swiftformat;
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "cd BuildTools\nSDKROOT=(xcrun --sdk macosx --show-sdk-path)\nswift run -c release swiftformat \"$SRCROOT\"\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
7D05F2FD2741359800EBDBB1 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{
"object": {
"pins": [
{
"package": "SnapKit",
"repositoryURL": "https://github.com/SnapKit/SnapKit",
"state": {
"branch": null,
"revision": "d458564516e5676af9c70b4f4b2a9178294f1bc6",
"version": "5.0.1"
}
"pins" : [
{
"identity" : "snapkit",
"kind" : "remoteSourceControl",
"location" : "https://github.com/SnapKit/SnapKit",
"state" : {
"revision" : "d458564516e5676af9c70b4f4b2a9178294f1bc6",
"version" : "5.0.1"
}
]
},
"version": 1
}
],
"version" : 2
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ struct ButtonAction {
let handler: () -> Void
}


extension UIButton {
private final class ButtonAdapter {
private let handler: () -> Void
Expand All @@ -24,14 +23,14 @@ extension UIButton {
self.handler = handler
self.controlEvent = controlEvent
}

@objc
func handle() {
handler()
}
}

static private var key: UInt8 = 0
private static var key: UInt8 = 0

private var adapters: [ButtonAdapter] {
get {
Expand All @@ -49,7 +48,7 @@ extension UIButton {
setTitle(buttonAction.title, for: .normal)
addEventHandler(handler: buttonAction.handler, controlEvent: .touchUpInside)
}

func addEventHandler(handler: @escaping () -> Void, controlEvent: UIControl.Event) {
let adapter = ButtonAdapter(handler: handler, controlEvent: controlEvent)
addTarget(adapter, action: #selector(ButtonAdapter.handle), for: controlEvent)
Expand Down
Loading

0 comments on commit b847e09

Please sign in to comment.