Skip to content

Commit 379451e

Browse files
authored
Add SwiftFormat configuration and apply formatting (#210)
1 parent 27e00db commit 379451e

51 files changed

Lines changed: 568 additions & 360 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.swiftformat‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# OpenAttributeGraph SwiftFormat configuration
2+
3+
# Swift version
4+
--swiftversion 6.1
5+
6+
# Indentation
7+
--indent 4
8+
--tabwidth 4
9+
--indentcase false
10+
--ifdef no-indent
11+
--xcodeindentation enabled
12+
13+
# Wrapping
14+
--maxwidth 120
15+
--wraparguments before-first
16+
--wrapparameters before-first
17+
--wrapcollections before-first
18+
--wrapreturntype preserve
19+
--wrapconditions preserve
20+
--closingparen balanced
21+
22+
# Braces
23+
--allman false
24+
25+
# Spaces
26+
--operatorfunc spaced
27+
--nospaceoperators
28+
--ranges spaced
29+
--typeattributes prev-line
30+
31+
# Semicolons
32+
--semicolons never
33+
34+
# Trailing commas
35+
--commas inline
36+
37+
# Imports
38+
--importgrouping testable-last
39+
40+
# Void
41+
--voidtype void
42+
43+
# Self
44+
--self remove
45+
--selfrequired
46+
47+
# Redundancy
48+
--redundanttype inferred
49+
50+
# Misc
51+
--trimwhitespace always
52+
--stripunusedargs closure-only
53+
--emptybraces no-space
54+
--elseposition same-line
55+
--guardelse next-line
56+
57+
# File header (preserve existing headers)
58+
--header ignore
59+
60+
# Disabled rules - too opinionated or conflict with project conventions
61+
--disable extensionAccessControl
62+
--disable docComments
63+
--disable wrapPropertyBodies
64+
--disable wrapFunctionBodies
65+
--disable wrapSingleLineComments
66+
--disable redundantThrows
67+
--disable headerFileName
68+
--disable numberFormatting
69+
--disable swiftTestingTestCaseNames
70+
--disable noForceUnwrapInTests
71+
--disable redundantAsync
72+
--disable modifierOrder
73+
--disable todos
74+
--disable opaqueGenericParameters
75+
--disable wrapMultilineStatementBraces
76+
--disable trailingCommas
77+
--disable redundantReturn
78+
79+
# Exclusions - skip vendored/generated code
80+
--exclude Sources/SwiftCorelibs,Sources/SwiftHeaders,.build,Package.swift

‎CLAUDE.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ OpenAttributeGraph is a Swift package that provides attribute graph functionalit
77

88
### 1. Make Changes and Commit
99
- Implement your feature or fix
10+
- Format changed Swift files: `Scripts/format-swift.sh`
1011
- Test locally
1112
- Commit changes with descriptive messages
1213

@@ -54,6 +55,7 @@ gh pr create --base main --head <current-branch>
5455
```
5556

5657
## Key Scripts
58+
- `Scripts/format-swift.sh` - Formats changed Swift files (run before committing)
5759
- `Scripts/gen_ag_template.sh` - Generates AG template for compatibility testing
5860
- `Scripts/bump_ag_pr.sh` - Creates PR for DarwinPrivateFramework updates
5961

‎Scripts/format-swift.sh‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/bash
2+
# Format staged or changed Swift files using SwiftFormat.
3+
#
4+
# Usage:
5+
# Scripts/format-swift.sh # Format staged Swift files (pre-commit use)
6+
# Scripts/format-swift.sh --all # Format all Swift files in the project
7+
# Scripts/format-swift.sh <file> # Format specific file(s)
8+
9+
set -euo pipefail
10+
11+
REPO_ROOT="$(git rev-parse --show-toplevel)"
12+
13+
if ! command -v swiftformat &>/dev/null; then
14+
echo "error: swiftformat is not installed. Run: brew install swiftformat" >&2
15+
exit 1
16+
fi
17+
18+
if [ $# -eq 0 ]; then
19+
# Format staged Swift files
20+
files=$(git diff --cached --name-only --diff-filter=ACM | grep '\.swift$' || true)
21+
if [ -z "$files" ]; then
22+
# Fall back to unstaged changes
23+
files=$(git diff --name-only --diff-filter=ACM | grep '\.swift$' || true)
24+
fi
25+
if [ -z "$files" ]; then
26+
echo "No changed Swift files to format."
27+
exit 0
28+
fi
29+
echo "Formatting changed Swift files..."
30+
echo "$files" | while IFS= read -r file; do
31+
echo " $file"
32+
done
33+
echo "$files" | xargs swiftformat --config "$REPO_ROOT/.swiftformat"
34+
elif [ "$1" = "--all" ]; then
35+
echo "Formatting all Swift files..."
36+
swiftformat "$REPO_ROOT"
37+
else
38+
echo "Formatting specified files..."
39+
swiftformat --config "$REPO_ROOT/.swiftformat" "$@"
40+
fi

‎Sources/OpenAttributeGraph/Attribute/Attribute/AnyAttribute.swift‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,16 @@ extension AnyAttribute {
1919
public init<Value>(_ attribute: Attribute<Value>) {
2020
self = attribute.identifier
2121
}
22-
22+
2323
public func unsafeCast<Value>(to _: Value.Type) -> Attribute<Value> {
2424
Attribute<Value>(identifier: self)
2525
}
26-
26+
2727
public static var current: AnyAttribute? {
2828
let current = __OAGGraphGetCurrentAttribute()
2929
return current == .nil ? nil : current
3030
}
31-
31+
3232
public func unsafeOffset(at offset: Int) -> AnyAttribute {
3333
create(offset: offset)
3434
}
@@ -44,7 +44,7 @@ extension AnyAttribute {
4444
public func addInput<Value>(_ attribute: Attribute<Value>, options: OAGInputOptions = [], token: Int) {
4545
addInput(attribute.identifier, options: options, token: token)
4646
}
47-
47+
4848
// FIXME: Use AttributeType instead
4949
public func visitBody<Body: AttributeBodyVisitor>(_ visitor: inout Body) {
5050
let bodyType = info.type.advanced(by: 1).pointee.self_id.type as! _AttributeBody.Type
@@ -60,11 +60,11 @@ extension AnyAttribute {
6060
body(&value.assumingMemoryBound(to: Value.self).pointee)
6161
}
6262
}
63-
63+
6464
public func breadthFirstSearch(options _: SearchOptions = [], _: (AnyAttribute) -> Bool) -> Bool {
6565
fatalError("TODO")
6666
}
67-
67+
6868
public var _bodyType: Any.Type {
6969
info.type.pointee.self_id.type
7070
}
@@ -85,7 +85,7 @@ extension AnyAttribute {
8585
nonmutating set {
8686
_indirectDependency = newValue ?? .nil
8787
}
88-
}
88+
}
8989
}
9090

9191
// MARK: CustomStringConvertible

0 commit comments

Comments
 (0)