You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Improve the diagnostics about cyclic curation (#984)
* Improve diagnostics about disallowed cyclic curation
rdar://131477513
* Shorten cyclic diagnostic summary message
Add debug assert when task group link has no list item
Use consistent arrow thickness in cyclic diagnostic explanation
Fix grammar in internal code comment
// A solution that suggests removing the list item that contain this link
236
+
varremoveListItemSolutions:[Solution]{
237
+
// Traverse the markup parents up to the nearest list item
238
+
guardlet listItem =sequence(first: link as(anyMarkup), next: \.parent).mapFirst(where:{ $0 as?ListItem}),
239
+
let listItemRange = listItem.range
240
+
else{
241
+
assertionFailure("Unable to find the list item element that contains \(link.format()) in the markup for \(describeForDiagnostic(nodeReference).singleQuoted)")
problems.append(Problem(diagnostic:Diagnostic(source:source(), severity:.warning, range:range(), identifier:"org.swift.docc.ModuleCuration", summary:"Linking to \((link.destination ??"").singleQuoted) from a Topics group in \(nodeReference.absoluteString.singleQuoted) isn't allowed", explanation:"The former is a module, and modules only exist at the root"), possibleSolutions:[]))
summary:"Organizing the module \(childReference.lastPathComponent.singleQuoted) under \(describeForDiagnostic(nodeReference).singleQuoted) isn't allowed",
265
+
explanation:"\(topicSectionBaseExplanation). Modules should be roots in the documentation hierarchy."),
266
+
possibleSolutions: removeListItemSolutions))
246
267
continue
247
268
}
248
269
}
249
270
250
271
// Verify we are not creating a graph cyclic relationship.
251
272
guard childReference != nodeReference else{
252
-
problems.append(Problem(diagnostic:Diagnostic(source:source(), severity:.warning, range:range(), identifier:"org.swift.docc.CyclicReference", summary:"A symbol can't link to itself from within its Topics group in \(nodeReference.absoluteString.singleQuoted)"), possibleSolutions:[]))
problems.append(Problem(diagnostic:Diagnostic(source:source(), severity:.warning, range:range(), identifier:"org.swift.docc.CyclicReference", summary:"Linking to \((link.destination ??"").singleQuoted) from a Topics group in \(nodeReference.absoluteString.singleQuoted) isn't allowed", explanation:"The former is an ancestor of the latter"), possibleSolutions:[]))
284
+
// Adding this edge in the topic graph _would_ introduce a cycle.
285
+
// In order to produce more actionable diagnostics, create a new graph that has this cycle.
Organizing \(describeForDiagnostic(childReference).singleQuoted) under \(describeForDiagnostic(nodeReference).singleQuoted)\
297
+
forms \(cycleDescriptions.count ==1?"a cycle":"\(cycleDescriptions.count) cycles")
298
+
""",
299
+
explanation:"""
300
+
\(topicSectionBaseExplanation). The documentation hierarchy shouldn't contain cycles.
301
+
If this link contributed to the documentation hierarchy it would introduce \(cycleDescriptions.count ==1?"this cycle":"these \(cycleDescriptions.count) cycles"):
Copy file name to clipboardExpand all lines: Tests/SwiftDocCTests/Infrastructure/DocumentationCuratorTests.swift
+75-2Lines changed: 75 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -13,6 +13,7 @@ import Foundation
13
13
import XCTest
14
14
import SymbolKit
15
15
@testableimport SwiftDocC
16
+
import SwiftDocCTestUtilities
16
17
import Markdown
17
18
18
19
classDocumentationCuratorTests:XCTestCase{
@@ -129,8 +130,11 @@ class DocumentationCuratorTests: XCTestCase {
129
130
)
130
131
XCTAssertEqual(
131
132
moduleCurationProblem?.diagnostic.summary,
132
-
"Linking to \'doc://org.swift.docc.example/documentation/MyKit\' from a Topics group in \'doc://org.swift.docc.example/documentation/MyKit/MyClass/myFunction()\' isn't allowed"
133
+
"Organizing the module 'MyKit' under 'MyKit/MyClass/myFunction()' isn't allowed"
0 commit comments