diff --git a/.github/workflows/swift-format.yml b/.github/workflows/swift-format.yml new file mode 100644 index 0000000..67b33d7 --- /dev/null +++ b/.github/workflows/swift-format.yml @@ -0,0 +1,25 @@ +name: Swift Format + +on: + pull_request: + branches: + - main + +jobs: + swift-format: + runs-on: macos-14 + permissions: + contents: write + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Xcode select + run: sudo xcode-select -s '/Applications/Xcode_15.2.app/Contents/Developer' + - name: Install Swift Format + run: brew install swift-format + - name: Swift Format + run: swift format --in-place --recursive ./Package.swift ./Sources ./Tests --configuration swift-format.json + - name: Commit changes + uses: stefanzweifel/git-auto-commit-action@v5 + with: + commit_message: Run swift-format \ No newline at end of file diff --git a/.github/workflows/testing.yml b/.github/workflows/testing.yml new file mode 100644 index 0000000..14033a5 --- /dev/null +++ b/.github/workflows/testing.yml @@ -0,0 +1,22 @@ +name: testing + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + testing: + runs-on: macos-14 + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Xcode select + run: sudo xcode-select -s '/Applications/Xcode_15.2.app/Contents/Developer' + - name: Build + run: swift build + - name: Test + run: swift test \ No newline at end of file diff --git a/Package.swift b/Package.swift index f5b3d24..301c2af 100644 --- a/Package.swift +++ b/Package.swift @@ -1,8 +1,8 @@ // swift-tools-version: 5.9 // The swift-tools-version declares the minimum version of Swift required to build this package. -import PackageDescription import CompilerPluginSupport +import PackageDescription let package = Package( name: "EmailValidation", @@ -20,7 +20,7 @@ let package = Package( ], dependencies: [ // Depend on the Swift 5.9 release of SwiftSyntax - .package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0"), + .package(url: "https://github.com/apple/swift-syntax.git", from: "509.0.0") ], targets: [ // Targets are the basic building blocks of a package, defining a module or a test suite. @@ -30,7 +30,7 @@ let package = Package( name: "EmailValidationMacros", dependencies: [ .product(name: "SwiftSyntaxMacros", package: "swift-syntax"), - .product(name: "SwiftCompilerPlugin", package: "swift-syntax") + .product(name: "SwiftCompilerPlugin", package: "swift-syntax"), ] ), diff --git a/Sources/EmailValidation/EmailValidation.swift b/Sources/EmailValidation/EmailValidation.swift index eb429d2..515b787 100644 --- a/Sources/EmailValidation/EmailValidation.swift +++ b/Sources/EmailValidation/EmailValidation.swift @@ -8,4 +8,5 @@ /// /// produces a tuple `(x + y, "x + y")`. @freestanding(expression) -public macro stringify(_ value: T) -> (T, String) = #externalMacro(module: "EmailValidationMacros", type: "StringifyMacro") \ No newline at end of file +public macro stringify(_ value: T) -> (T, String) = + #externalMacro(module: "EmailValidationMacros", type: "StringifyMacro") diff --git a/Sources/EmailValidationMacros/EmailValidationMacro.swift b/Sources/EmailValidationMacros/EmailValidationMacro.swift index 839563c..7672c8a 100644 --- a/Sources/EmailValidationMacros/EmailValidationMacro.swift +++ b/Sources/EmailValidationMacros/EmailValidationMacro.swift @@ -28,6 +28,6 @@ public struct StringifyMacro: ExpressionMacro { @main struct EmailValidationPlugin: CompilerPlugin { let providingMacros: [Macro.Type] = [ - StringifyMacro.self, + StringifyMacro.self ] } diff --git a/Tests/EmailValidationTests/EmailValidationTests.swift b/Tests/EmailValidationTests/EmailValidationTests.swift index 461958c..66b6486 100644 --- a/Tests/EmailValidationTests/EmailValidationTests.swift +++ b/Tests/EmailValidationTests/EmailValidationTests.swift @@ -4,43 +4,43 @@ import XCTest // Macro implementations build for the host, so the corresponding module is not available when cross-compiling. Cross-compiled tests may still make use of the macro itself in end-to-end tests. #if canImport(EmailValidationMacros) -import EmailValidationMacros + import EmailValidationMacros -let testMacros: [String: Macro.Type] = [ - "stringify": StringifyMacro.self, -] + let testMacros: [String: Macro.Type] = [ + "stringify": StringifyMacro.self + ] #endif final class EmailValidationTests: XCTestCase { func testMacro() throws { #if canImport(EmailValidationMacros) - assertMacroExpansion( - """ - #stringify(a + b) - """, - expandedSource: """ - (a + b, "a + b") - """, - macros: testMacros - ) + assertMacroExpansion( + """ + #stringify(a + b) + """, + expandedSource: """ + (a + b, "a + b") + """, + macros: testMacros + ) #else - throw XCTSkip("macros are only supported when running tests for the host platform") + throw XCTSkip("macros are only supported when running tests for the host platform") #endif } func testMacroWithStringLiteral() throws { #if canImport(EmailValidationMacros) - assertMacroExpansion( - #""" - #stringify("Hello, \(name)") - """#, - expandedSource: #""" - ("Hello, \(name)", #""Hello, \(name)""#) - """#, - macros: testMacros - ) + assertMacroExpansion( + #""" + #stringify("Hello, \(name)") + """#, + expandedSource: #""" + ("Hello, \(name)", #""Hello, \(name)""#) + """#, + macros: testMacros + ) #else - throw XCTSkip("macros are only supported when running tests for the host platform") + throw XCTSkip("macros are only supported when running tests for the host platform") #endif } } diff --git a/swift-format.json b/swift-format.json new file mode 100644 index 0000000..0145504 --- /dev/null +++ b/swift-format.json @@ -0,0 +1,5 @@ +{ + "indentation" : { + "spaces" : 4 + } +} \ No newline at end of file