Skip to content

Commit

Permalink
Add SwiftUI properties sort (#289)
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-jimenez-0529 authored Sep 3, 2024
1 parent 6022593 commit 0e09033
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ let package = Package(

.binaryTarget(
name: "swiftformat",
url: "https://github.com/calda/SwiftFormat/releases/download/0.55-beta-11/SwiftFormat.artifactbundle.zip",
checksum: "421884ecccc34b75135e9aa4b80e21ee6d9985084896fe8d58e07b28d9a2e0f6"),
url: "https://github.com/calda/SwiftFormat/releases/download/0.55-beta-12/SwiftFormat.artifactbundle.zip",
checksum: "8783cefc0837416759f81064df7907cc60ddca6d3f8c3b301b123a2193a8585b"),

.binaryTarget(
name: "SwiftLintBinary",
Expand Down
33 changes: 32 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3936,7 +3936,7 @@ _You can enable the following settings in Xcode by running [this script](resourc
* Static properties
* Static property with body
* Class properties with body
* SwiftUI dynamic properties (@State, @Environment, @Binding, etc)
* SwiftUI dynamic properties (@State, @Environment, @Binding, etc), grouped by type
* Instance properties
* Instance properties with body
* Static methods
Expand Down Expand Up @@ -4029,6 +4029,37 @@ _You can enable the following settings in Xcode by running [this script](resourc
private let step: Double.Stride
}
```

Additionally, within the grouping of SwiftUI properties, it is preferred that the properties are also grouped by their dynamic property type. The group order applied by the formatter is determined by the first time a type appears:

```swift
// WRONG
struct CustomSlider: View {

@Binding private var value: Value
@State private var foo = Foo()
@Environment(\.sliderStyle) private var style
@State private var bar = Bar()
@Environment(\.layoutDirection) private var layoutDirection

private let range: ClosedRange<Double>
private let step: Double.Stride
}

// RIGHT
struct CustomSlider: View {

@Binding private var value: Value
@State private var foo = Foo()
@State private var bar = Bar()
@Environment(\.sliderStyle) private var style
@Environment(\.layoutDirection) private var layoutDirection

private let range: ClosedRange<Double>
private let step: Double.Stride
}
```

</details>


Expand Down
1 change: 1 addition & 0 deletions Sources/AirbnbSwiftFormatTool/airbnb.swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
--organizetypes class,struct,enum,extension,actor # organizeDeclarations
--visibilityorder beforeMarks,instanceLifecycle,open,public,package,internal,fileprivate,private # organizeDeclarations
--typeorder nestedType,staticProperty,staticPropertyWithBody,classPropertyWithBody,swiftUIPropertyWrapper,instanceProperty,instancePropertyWithBody,staticMethod,classMethod,instanceMethod # organizeDeclarations
--sortswiftuiprops first-appearance-sort #organizeDeclarations
--extensionacl on-declarations # extensionAccessControl
--patternlet inline # hoistPatternLet
--redundanttype inferred # redundantType, propertyType
Expand Down

0 comments on commit 0e09033

Please sign in to comment.