Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Commit 97b2347

Browse files
committed
Consistently return symbols in sorted order
1 parent 9554127 commit 97b2347

File tree

1 file changed

+34
-9
lines changed

1 file changed

+34
-9
lines changed

Sources/SwiftDoc/Module.swift

+34-9
Original file line numberDiff line numberDiff line change
@@ -95,40 +95,65 @@ public class Module: Codable {
9595
public init(name: String = "Anonymous", sourceFiles: [SourceFile]) {
9696
self.name = name
9797
self.sourceFiles = sourceFiles
98-
self.symbols = sourceFiles.flatMap { $0.symbols }.filter { $0.isPublic }
98+
self.symbols = sourceFiles.flatMap { $0.symbols }
99+
.filter { $0.isPublic }
100+
.sorted()
99101
}
100102

101103
// MARK: -
102104

103105
public func members(of symbol: Symbol) -> [Symbol] {
104-
return relationshipsByObject[symbol.id]?.filter { $0.predicate == .memberOf }.map { $0.subject } ?? []
106+
return relationshipsByObject[symbol.id]?
107+
.filter { $0.predicate == .memberOf }
108+
.map { $0.subject }
109+
.sorted() ?? []
105110
}
106111

107112
public func requirements(of symbol: Symbol) -> [Symbol] {
108-
return relationshipsByObject[symbol.id]?.filter { $0.predicate == .requirementOf }.map { $0.subject } ?? []
113+
return relationshipsByObject[symbol.id]?
114+
.filter { $0.predicate == .requirementOf }
115+
.map { $0.subject }
116+
.sorted() ?? []
109117
}
110118

111119
public func optionalRequirements(of symbol: Symbol) -> [Symbol] {
112-
return relationshipsByObject[symbol.id]?.filter { $0.predicate == .optionalRequirementOf }.map { $0.subject } ?? []
120+
return relationshipsByObject[symbol.id]?
121+
.filter { $0.predicate == .optionalRequirementOf }
122+
.map { $0.subject }
123+
.sorted() ?? []
113124
}
114125

115126
public func typesInherited(by symbol: Symbol) -> [Symbol] {
116-
return relationshipsBySubject[symbol.id]?.filter { $0.predicate == .inheritsFrom }.map { $0.object }.sorted() ?? []
127+
return relationshipsBySubject[symbol.id]?
128+
.filter { $0.predicate == .inheritsFrom }
129+
.map { $0.object }
130+
.sorted() ?? []
117131
}
118132

119133
public func typesInheriting(from symbol: Symbol) -> [Symbol] {
120-
return relationshipsByObject[symbol.id]?.filter { $0.predicate == .inheritsFrom }.map { $0.subject }.sorted() ?? []
134+
return relationshipsByObject[symbol.id]?
135+
.filter { $0.predicate == .inheritsFrom }
136+
.map { $0.subject }
137+
.sorted() ?? []
121138
}
122139

123140
public func typesConformed(by symbol: Symbol) -> [Symbol] {
124-
return relationshipsBySubject[symbol.id]?.filter { $0.predicate == .conformsTo }.map { $0.object }.sorted() ?? []
141+
return relationshipsBySubject[symbol.id]?
142+
.filter { $0.predicate == .conformsTo }
143+
.map { $0.object }
144+
.sorted() ?? []
125145
}
126146

127147
public func typesConforming(to symbol: Symbol) -> [Symbol] {
128-
return relationshipsByObject[symbol.id]?.filter { $0.predicate == .conformsTo }.map { $0.subject }.sorted() ?? []
148+
return relationshipsByObject[symbol.id]?
149+
.filter { $0.predicate == .conformsTo }
150+
.map { $0.subject }
151+
.sorted() ?? []
129152
}
130153

131154
public func conditionalCounterparts(of symbol: Symbol) -> [Symbol] {
132-
return symbolsByIdentifier[symbol.id]?.filter { $0 != symbol } ?? []
155+
return symbolsByIdentifier[symbol.id]?
156+
.filter { $0 != symbol }
157+
.sorted() ?? []
133158
}
134159
}

0 commit comments

Comments
 (0)