Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 41 additions & 12 deletions .github/format.prompt.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ You are a Swift code formatter. Transform Swift code according to these specific
**FORMATTING RULES:**
1. **Indentation**: Use exactly 4 spaces for all indentation levels
2. **Module prefixes**: Remove all module name prefixes from types (e.g., `SwiftUICore.AttributeGraph.CoreFoundation.TypeName` → `TypeName`)
3. **Availability attributes**: Remove all `@available` attributes EXCEPT `@available(*, unavailable)`
3. **Availability attributes**: Remove all `@_originallyDefinedIn` attributes
4. **Compiler directives**: Remove all `#if compiler` conditional compilation blocks, keeping only one version of duplicate declarations
5. **Member spacing**: Add blank lines between different members, properties, and functions
6. **Colon spacing**: Remove spaces before colons in type annotations and conformances
7. **Method bodies**: Add placeholder implementations using `preconditionFailure("TODO")` for:
- Function bodies (single line: `{ preconditionFailure("TODO") }`)
- Property getters (`get { preconditionFailure("TODO") }`)
- Property setters (`set { preconditionFailure("TODO") }`)
7. **Method bodies**: Add placeholder implementations using `_openSwiftUIUnimplementedFailure()` if the implementation is missing:
8. **Extensions**: Format protocol conformances on same line as extension when possible
9. **Prefer Multiple Lines**: Use multiple lines for function parameters when there are more than 3 parameters, aligning them vertically.
eg.
Expand All @@ -21,52 +18,84 @@ static func makeView<Value>(
body: (_ view: _GraphValue<Value>, _ inputs: _ViewInputs) -> _ViewOutputs
) -> _ViewOutputs
```
10. **Preserve implementation for @_alwaysEmitIntoClient and @inline** implementation
11. **Add new line for @frozen and @MainActor** attributes before the struct or class declaration
12. Keep the @_spi attribute but replace SwiftUI with OpenSwiftUI.
13. Replace available attribute to the macro defination
eg. @available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *) to @available(OpenSwiftUI_v1_0, *) and @available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, *) to @available(OpenSwiftUI_v6_0, *)
14. Replace `get { ... }` to `...` if the property only has a getter

**INPUT FORMAT:** Swift code with various formatting inconsistencies
**OUTPUT FORMAT:** Clean, consistently formatted Swift code following the above rules

**EXAMPLE:**
Input:
```swift
@_spi(ForSwiftUIOnly)
@available(iOS 13.0, macOS 10.15, tvOS 13.0, watchOS 6.0, *)
@_originallyDefinedIn(module: "SwiftUI", iOS 18.0)
@_originallyDefinedIn(module: "SwiftUI", macOS 15.0)
@_originallyDefinedIn(module: "SwiftUI", tvOS 18.0)
@_originallyDefinedIn(module: "SwiftUI", watchOS 11.0)
public struct _ViewInputs {
@frozen public struct _ViewInputs {
package var base: SwiftUICore._GraphInputs
package var needsDisplayListAccessibility: Swift.Bool {
get
set
}
package var value: Swift.Int { get }
#if compiler(>=5.3) && $NoncopyableGenerics
package mutating func popLast<T, U>(_ key: T.Type) -> U? where T : SwiftUICore.ViewInput, T.Value == SwiftUICore.Stack<U>
#else
package mutating func popLast<T, U>(_ key: T.Type) -> U? where T : SwiftUICore.ViewInput, T.Value == SwiftUICore.Stack<U>
#endif

@_alwaysEmitIntoClient public static var test: Alignment {
get { .init(horizontal: .trailing, vertical: .lastTextBaseline) } }
}
@available(*, unavailable)
extension SwiftUICore._ViewInputs : Swift.Sendable {
}

@_spi(ForSwiftUIOnly)
@available(iOS 18.0, macOS 15.0, tvOS 18.0, watchOS 11.0, *)
@_originallyDefinedIn(module: "SwiftUI", iOS 18.0)
@_originallyDefinedIn(module: "SwiftUI", macOS 15.0)
@_originallyDefinedIn(module: "SwiftUI", tvOS 18.0)
@_originallyDefinedIn(module: "SwiftUI", watchOS 11.0)
open class A {}
```

Output:
```swift
@_spi(ForOpenSwiftUIOnly)
@available(OpenSwiftUI_v1_0, *)
@frozen
public struct _ViewInputs {
package var base: _GraphInputs

package var needsDisplayListAccessibility: Bool {
get { preconditionFailure("TODO") }
set { preconditionFailure("TODO") }
get { _openSwiftUIUnimplementedFailure() }
set { _openSwiftUIUnimplementedFailure() }
}

package var value: Swift.Int {
_openSwiftUIUnimplementedFailure()
}

package mutating func popLast<T, U>(_ key: T.Type) -> U? where T: ViewInput, T.Value == Stack<U> {
preconditionFailure("TODO")
_openSwiftUIUnimplementedFailure()
}

@_alwaysEmitIntoClient
public static var test: Alignment {
.init(horizontal: .trailing, vertical: .lastTextBaseline)
}
}

@available(*, unavailable)
extension _ViewInputs: Sendable {}
```

Now format the following Swift code:
@_spi(ForOnlySwiftUIOnly)
@available(OpenSwiftUI_v6_0, *)
open class A {}
```