Skip to content

Commit

Permalink
Run swift-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Matejkob authored and github-actions[bot] committed Feb 5, 2024
1 parent 8ced7a5 commit 36617f2
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 21 deletions.
9 changes: 5 additions & 4 deletions Sources/Spyable/Spyable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@
/// - NOTE: The `@Spyable` macro should only be applied to protocols. Applying it to other
/// declarations will result in an error.
@attached(peer, names: suffixed(Spy))
public macro Spyable(behindPreprocessorFlag: String? = nil) = #externalMacro(
module: "SpyableMacro",
type: "SpyableMacro"
)
public macro Spyable(behindPreprocessorFlag: String? = nil) =
#externalMacro(
module: "SpyableMacro",
type: "SpyableMacro"
)
7 changes: 4 additions & 3 deletions Sources/SpyableMacro/Diagnostics/SpyableDiagnostic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ enum SpyableDiagnostic: String, DiagnosticMessage, Error {
var severity: DiagnosticSeverity {
switch self {
case .onlyApplicableToProtocol,
.variableDeclInProtocolWithNotSingleBinding,
.variableDeclInProtocolWithNotIdentifierPattern,
.behindPreprocessorFlagArgumentRequiresStaticStringLiteral: .error
.variableDeclInProtocolWithNotSingleBinding,
.variableDeclInProtocolWithNotIdentifierPattern,
.behindPreprocessorFlagArgumentRequiresStaticStringLiteral:
.error
}
}

Expand Down
15 changes: 9 additions & 6 deletions Sources/SpyableMacro/Extractors/Extractor.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import SwiftDiagnostics
import SwiftSyntax
import SwiftSyntaxMacros
import SwiftDiagnostics

/// A utility responsible for extracting specific syntax elements from Swift Syntax.
///
Expand Down Expand Up @@ -48,9 +48,11 @@ struct Extractor {
return nil
}

guard let behindPreprocessorFlagArgument = argumentList.first(where: { argument in
argument.label?.text == "behindPreprocessorFlag"
}) else {
guard
let behindPreprocessorFlagArgument = argumentList.first(where: { argument in
argument.label?.text == "behindPreprocessorFlag"
})
else {
// The `behindPreprocessorFlag` argument is missing.
return nil
}
Expand All @@ -60,8 +62,9 @@ struct Extractor {
.segments

guard let segments,
segments.count == 1,
case let .stringSegment(literalSegment)? = segments.first else {
segments.count == 1,
case let .stringSegment(literalSegment)? = segments.first
else {
// The `behindPreprocessorFlag` argument's value is not a static string literal.
context.diagnose(
Diagnostic(
Expand Down
18 changes: 10 additions & 8 deletions Tests/SpyableMacroTests/Macro/UT_SpyableMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -291,10 +291,11 @@ final class UT_SpyableMacro: XCTestCase {
column: 1,
notes: [
NoteSpec(
message: "Provide a literal string value without any dynamic expressions or interpolations to meet the static string literal requirement.",
line: 1,
column: 34
)
message:
"Provide a literal string value without any dynamic expressions or interpolations to meet the static string literal requirement.",
line: 1,
column: 34
)
]
)
],
Expand Down Expand Up @@ -326,10 +327,11 @@ final class UT_SpyableMacro: XCTestCase {
column: 1,
notes: [
NoteSpec(
message: "Provide a literal string value without any dynamic expressions or interpolations to meet the static string literal requirement.",
line: 3,
column: 34
)
message:
"Provide a literal string value without any dynamic expressions or interpolations to meet the static string literal requirement.",
line: 3,
column: 34
)
]
)
],
Expand Down

0 comments on commit 36617f2

Please sign in to comment.