Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ jobs:
sudo xcodebuild -runFirstLaunch
sudo xcrun simctl list
sudo xcodebuild -downloadPlatform visionOS
sudo xcodebuild -runFirstLaunch
- name: Build Framework
run: xcrun xcodebuild -skipMacroValidation -skipPackagePluginValidation build -scheme SafeDI-Package -destination ${{ matrix.platforms }}

Expand Down Expand Up @@ -116,8 +115,13 @@ jobs:
run: sudo xcode-select --switch /Applications/Xcode_16.4.0.app/Contents/Developer
- name: Install Pod
run: bundle exec pod install --project-directory=Examples/ExampleCocoaPodsIntegration
- name: Download iOS
run: |
sudo xcodebuild -runFirstLaunch
sudo xcrun simctl list
sudo xcodebuild -downloadPlatform iOS -buildVersion 22F77
- name: Build CocoaPods Integration
run: xcrun xcodebuild build -scheme ExampleCocoaPodsIntegration -configuration Debug -workspace Examples/ExampleCocoaPodsIntegration/ExampleCocoaPodsIntegration.xcworkspace -destination 'platform=iOS Simulator,OS=18.4,name=iPad (10th generation)' # Explicitly test the Debug build. Our pod lint jobs are already testing the Release build.
run: xcrun xcodebuild build -scheme ExampleCocoaPodsIntegration -configuration Debug -workspace Examples/ExampleCocoaPodsIntegration/ExampleCocoaPodsIntegration.xcworkspace -destination 'platform=iOS Simulator,OS=18.5,name=iPad (10th generation)' # Explicitly test the Debug build. Our pod lint jobs are already testing the Release build.

spm:
name: Build and Test on Xcode 16
Expand Down Expand Up @@ -174,7 +178,6 @@ jobs:
sudo xcodebuild -runFirstLaunch
sudo xcrun simctl list
sudo xcodebuild -downloadPlatform ${{ matrix.platforms }}
sudo xcodebuild -runFirstLaunch
- name: Lint Podspec
run: bundle exec pod lib lint --verbose --fail-fast --swift-version=6.0 --platforms=${{ matrix.platforms }}

Expand Down
4 changes: 3 additions & 1 deletion Sources/SafeDIMacros/Macros/InstantiableMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,9 @@ public struct InstantiableMacro: MemberMacro {
return existingAssignment
} else {
var propertyAssignment = $0.asPropertyAssignment()
propertyAssignment.leadingTrivia = body.statements.first?.leadingTrivia ?? []
if let leadingTrivia = body.statements.first?.leadingTrivia {
propertyAssignment.leadingTrivia = leadingTrivia
}
return propertyAssignment
}
}
Expand Down
70 changes: 70 additions & 0 deletions Tests/SafeDIMacrosTests/InstantiableMacroTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1935,6 +1935,76 @@ import SafeDICore
}
}

@Test
func declaration_fixit_updatesRequiredInitializerWhenAllDependenciesMissingFromInit() {
assertMacro {
"""
@Instantiable
public struct ExampleService: Instantiable {
public init() {
}

@Received let received: Received
@Instantiated let instantiated: Instantiated
@Forwarded let forwarded: Forwarded
}
"""
} diagnostics: {
"""
@Instantiable
public struct ExampleService: Instantiable {
public init() {
╰─ 🛑 @Instantiable-decorated type must have a `public` or `open` initializer with a parameter for each @Instantiated, @Received, or @Forwarded-decorated property.
✏️ Add arguments for received: Received, instantiated: Instantiated, forwarded: Forwarded
}

@Received let received: Received
@Instantiated let instantiated: Instantiated
@Forwarded let forwarded: Forwarded
}
"""
} fixes: {
"""
@Instantiable
public struct ExampleService: Instantiable {
public init(
received: Received,
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Xcode will handle adding the correct indentation

instantiated: Instantiated,
forwarded: Forwarded
) {
self.received = received
self.instantiated = instantiated
self.forwarded = forwarded
}

@Received let received: Received
@Instantiated let instantiated: Instantiated
@Forwarded let forwarded: Forwarded
}
"""
} expansion: {
"""
public struct ExampleService: Instantiable {
public init(
received: Received,
instantiated: Instantiated,
forwarded: Forwarded
) {
self.received = received
self.instantiated = instantiated
self.forwarded = forwarded
}

let received: Received
let instantiated: Instantiated
let forwarded: Forwarded

public typealias ForwardedProperties = Forwarded
}
"""
}
}

@Test
func declaration_fixit_updatesRequiredInitializerWhenIncorrectAccessibilityOnInitAndOtherNonConformingInitializersExist() {
assertMacro {
Expand Down
Loading