Skip to content

Commit

Permalink
Do not use NSString's 'trimmingCharacters' API
Browse files Browse the repository at this point in the history
  • Loading branch information
dfed committed Jan 10, 2024
1 parent 6e0e67f commit 9d4225d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public final class DependencyTreeGenerator {
for try await generatedRoot in taskGroup {
generatedRoots.append(generatedRoot)
}
return generatedRoots.sorted().joined(separator: "\n\n").trimmingCharacters(in: .whitespacesAndNewlines)
return generatedRoots.sorted().joined(separator: "\n\n")
}

let importsWhitespace = imports.isEmpty ? "" : "\n"
Expand Down
14 changes: 7 additions & 7 deletions Sources/SafeDICore/Models/TypeDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public enum TypeDescription: Codable, Hashable, Comparable, Sendable {
case let .closure(arguments, isAsync, doesThrow, returnType):
return "(\(arguments.map { $0.asSource }.joined(separator: ", ")))\([isAsync ? " async" : "", doesThrow ? " throws" : ""].filter { !$0.isEmpty }.joined()) -> \(returnType.asSource)"
case let .unknown(text):
return text.trimmingCharacters(in: .whitespacesAndNewlines)
return text
}
}

Expand Down Expand Up @@ -478,7 +478,7 @@ extension TypeSyntax {
} else {
assertionFailure("TypeSyntax of unknown type. Defaulting to `description`.")
// The description is a source-accurate description of this node, so it is a reasonable fallback.
return .unknown(text: description)
return .unknown(text: trimmedDescription)
}
}
}
Expand All @@ -500,7 +500,7 @@ extension ExprSyntax {
if let base = memberAccessExpr.base {
return base.typeDescription
} else {
return .unknown(text: memberAccessExpr.description)
return .unknown(text: memberAccessExpr.trimmedDescription)
}
} else {
if let base = memberAccessExpr.base {
Expand All @@ -517,7 +517,7 @@ extension ExprSyntax {
)
}
} else {
return .unknown(text: memberAccessExpr.description)
return .unknown(text: memberAccessExpr.trimmedDescription)
}
}
} else if let genericExpr = GenericSpecializationExprSyntax(self) {
Expand All @@ -535,7 +535,7 @@ extension ExprSyntax {
parentType: parentType, generics: genericTypeVisitor.genericArguments
)
case .any, .array, .attributed, .closure, .composition, .dictionary, .implicitlyUnwrappedOptional, .metatype, .optional, .some, .tuple, .unknown:
return .unknown(text: description)
return .unknown(text: trimmedDescription)
}
} else if let tupleExpr = TupleExprSyntax(self) {
let tupleTypes = tupleExpr.elements.map(\.expression.typeDescription)
Expand Down Expand Up @@ -573,7 +573,7 @@ extension ExprSyntax {
returnType: returnType.typeDescription
)
} else {
return .unknown(text: description)
return .unknown(text: trimmedDescription)
}
} else if let optionalChainingExpr = OptionalChainingExprSyntax(self) {
return .optional(optionalChainingExpr.expression.typeDescription)
Expand All @@ -594,7 +594,7 @@ extension ExprSyntax {
value: onlyElement.value.typeDescription
)
} else {
return .unknown(text: description)
return .unknown(text: trimmedDescription)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Tests/SafeDICoreTests/TypeDescriptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -882,8 +882,8 @@ final class TypeDescriptionTests: XCTestCase {
}

func test_asSource_whenDescribingAnUnknownCase_returnsTheProvidedStringWithWhitespaceStripped() {
let sut = TypeDescription.unknown(text: " SomeTypeThatIsFormattedOddly ")
XCTAssertEqual(sut.asSource, "SomeTypeThatIsFormattedOddly")
let typeDescription = TypeSyntax(stringLiteral: " SomeTypeThatIsFormattedOddly ").typeDescription
XCTAssertEqual(typeDescription.asSource, "SomeTypeThatIsFormattedOddly")
}

// MARK: - Visitors
Expand Down

0 comments on commit 9d4225d

Please sign in to comment.