Skip to content

Commit

Permalink
Orders TypeName attributes (#982)
Browse files Browse the repository at this point in the history
* Fix TypeName attributes sorting

* Updates changelog
  • Loading branch information
Juhan Hion authored Aug 25, 2021
1 parent ed9a1a7 commit 2ed1c1b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Sourcery CHANGELOG

## 1.5.2
## Fixes
- Fixes unstable ordering of `TypeName.attributes`

## 1.5.1
## Fixes
- Fixing `Type.uniqueMethodFilter(_:_:)` so it compares return types of methods as well.
Expand Down
4 changes: 2 additions & 2 deletions SourceryRuntime/Sources/AST/TypeName/TypeName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ import Foundation
let specialTreatment = isOptional && name.hasPrefix("Optional<")

var description = (
attributes.flatMap({ $0.value }).map({ $0.asSource }) +
attributes.flatMap({ $0.value }).map({ $0.asSource }).sorted() +
modifiers.map({ $0.asSource }) +
[specialTreatment ? name : unwrappedTypeName]
).joined(separator: " ")
Expand Down Expand Up @@ -160,7 +160,7 @@ import Foundation

public override var description: String {
(
attributes.flatMap({ $0.value }).map({ $0.asSource }) +
attributes.flatMap({ $0.value }).map({ $0.asSource }).sorted() +
modifiers.map({ $0.asSource }) +
[name]
).joined(separator: " ")
Expand Down
11 changes: 9 additions & 2 deletions SourceryTests/Parsing/FileParser + TypeNameSpec.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,15 @@ class TypeNameSpec: QuickSpec {
}
}

it("removes attributes in unwrappedTypeName") {
expect(typeName("@escaping (@escaping ()->())->()").unwrappedTypeName).to(equal("(@escaping () -> ()) -> ()"))
context("given closure type with attributes") {
it("removes attributes in unwrappedTypeName") {
expect(typeName("@escaping (@escaping ()->())->()").unwrappedTypeName).to(equal("(@escaping () -> ()) -> ()"))
}

it("orders attributes alphabetically") {
expect(typeName("@escaping @autoclosure () -> String").asSource).to(equal("@autoclosure @escaping () -> String"))
expect(typeName("@escaping @autoclosure () -> String").description).to(equal("@autoclosure @escaping () -> String"))
}
}
}
}
Expand Down

0 comments on commit 2ed1c1b

Please sign in to comment.