Skip to content

Commit f2f263b

Browse files
authored
Merge branch 'main' into enable-external-link-support-by-default
2 parents e99a593 + cffe76c commit f2f263b

File tree

187 files changed

+999
-939
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

187 files changed

+999
-939
lines changed

Sources/SwiftDocC/Model/Rendering/DocumentationContentRenderer.swift

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -214,16 +214,12 @@ public class DocumentationContentRenderer {
214214
guard let symbol = node.semantic as? Symbol,
215215
let currentPlatforms = documentationContext.configuration.externalMetadata.currentPlatforms,
216216
!currentPlatforms.isEmpty,
217-
let symbolAvailability = symbol.availability?.availability,
217+
let symbolAvailability = symbol.availability?.availability.filter({ !$0.isUnconditionallyUnavailable }), // symbol that's unconditionally unavailable in all the platforms can't be in beta.
218218
!symbolAvailability.isEmpty // A symbol without availability items can't be in beta.
219219
else { return false }
220220

221221
// Verify that if current platforms are in beta, they match the introduced version of the symbol
222222
for availability in symbolAvailability {
223-
// If not available on this platform, skip to next platform.
224-
guard !availability.isUnconditionallyUnavailable else {
225-
continue
226-
}
227223

228224
// If the symbol doesn't have an introduced version for one of those platforms, we don't consider it "in beta".
229225
guard let introduced = availability.introducedVersion else {

Sources/SwiftDocC/Utility/FileManagerProtocol+FilesSequence.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,24 @@ extension FileManagerProtocol {
1616
/// - startingPoint: The file or directory that's the top of the directory structure that the file manager traverses.
1717
/// - options: Options for how the file manager enumerates the contents of directories. Defaults to `.skipsHiddenFiles`.
1818
/// - Returns: A sequence of the files in the directory structure.
19-
package func recursiveFiles(startingPoint: URL, options: FileManager.DirectoryEnumerationOptions = .skipsHiddenFiles) -> some Sequence<URL> {
20-
IteratorSequence(FilesIterator(fileManager: self, startingPoint: startingPoint, options: options))
19+
package func recursiveFiles(startingPoint: URL, options: FileManager.DirectoryEnumerationOptions = .skipsHiddenFiles) -> IteratorSequence<_FilesIterator> {
20+
IteratorSequence(_FilesIterator(fileManager: self, startingPoint: startingPoint, options: options))
2121
}
2222
}
2323

24+
// FIXME: This should be private and `FileManagerProtocol.recursiveFiles(startingPoint:options:)` should return `some Sequence<ULR>`
25+
// but because of https://github.com/swiftlang/swift/issues/77955 it needs to be exposed as an explicit type to avoid a SIL Validation error in the Swift compiler.
26+
2427
/// An iterator that traverses the directory structure and returns the files in breadth-first order.
25-
private struct FilesIterator<FileManager: FileManagerProtocol>: IteratorProtocol {
28+
package struct _FilesIterator: IteratorProtocol {
2629
/// The file manager that the iterator uses to traverse the directory structure.
27-
var fileManager: FileManager
28-
var options: Foundation.FileManager.DirectoryEnumerationOptions
30+
private var fileManager: any FileManagerProtocol // This can't be a generic because of https://github.com/swiftlang/swift/issues/77955
31+
private var options: FileManager.DirectoryEnumerationOptions
2932

3033
private var foundFiles: [URL]
3134
private var foundDirectories: [URL]
3235

33-
init(fileManager: FileManager, startingPoint: URL, options: Foundation.FileManager.DirectoryEnumerationOptions) {
36+
fileprivate init(fileManager: any FileManagerProtocol, startingPoint: URL, options: FileManager.DirectoryEnumerationOptions) {
3437
self.fileManager = fileManager
3538
self.options = options
3639

@@ -44,7 +47,7 @@ private struct FilesIterator<FileManager: FileManagerProtocol>: IteratorProtocol
4447
}
4548
}
4649

47-
mutating func next() -> URL? {
50+
package mutating func next() -> URL? {
4851
// If the iterator has already found some files, return those first
4952
if !foundFiles.isEmpty {
5053
return foundFiles.removeFirst()

Sources/docc/DocCDocumentation.docc/other-formatting-options.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@ configuration. For those situations, use an aside.
1414

1515
DocC supports the following types of asides:
1616

17-
| Type | Usage |
18-
| ----- | ------ |
19-
| Note | General information that applies to some users. |
20-
| Important | Important information, such as a requirement. |
21-
| Warning | Critical information, like potential data loss or an irrecoverable state. |
22-
| Tip | Helpful information, such as shortcuts, suggestions, or hints. |
23-
| Experiment | Instructional information to reinforce a learning objective, or to encourage developers to try out different parts of your framework. |
17+
> Note: General information that applies to some users.
18+
19+
> Important: Important information, such as a requirement.
20+
21+
> Warning: Critical information, like potential data loss or an irrecoverable state.
22+
23+
> Tip: Helpful information, such as shortcuts, suggestions, or hints.
24+
25+
> Experiment: Instructional information to reinforce a learning objective, or to encourage developers to try out different parts of your framework.
2426
2527
To create an aside, begin a new line with a greater-than symbol (`>`), add a space,
2628
the type of the aside, a colon (`:`), and the content of the aside.

Tests/SwiftDocCTests/Benchmark/ExternalTopicsHashTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ExternalTopicsGraphHashTests: XCTestCase {
3939

4040
func testNoMetricAddedIfNoExternalTopicsAreResolved() throws {
4141
// Load bundle without using external resolvers
42-
let (_, context) = try testBundleAndContext(named: "TestBundle")
42+
let (_, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
4343
XCTAssertTrue(context.externallyResolvedLinks.isEmpty)
4444

4545
// Try adding external topics metrics
@@ -55,7 +55,7 @@ class ExternalTopicsGraphHashTests: XCTestCase {
5555

5656
// Add external links and verify the checksum is always the same
5757
let hashes: [String] = try (0...10).map { _ -> MetricValue? in
58-
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in
58+
let (_, _, context) = try testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in
5959
try """
6060
# ``SideKit/SideClass``
6161
@@ -93,7 +93,7 @@ class ExternalTopicsGraphHashTests: XCTestCase {
9393

9494
// Add external links and verify the checksum is always the same
9595
let hashes: [String] = try (0...10).map { _ -> MetricValue? in
96-
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", externalResolvers: [externalResolver.bundleID: externalResolver], externalSymbolResolver: externalSymbolResolver) { url in
96+
let (_, _, context) = try testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver], externalSymbolResolver: externalSymbolResolver) { url in
9797
try """
9898
# ``SideKit/SideClass``
9999
@@ -131,7 +131,7 @@ class ExternalTopicsGraphHashTests: XCTestCase {
131131
let externalResolver = self.externalResolver
132132

133133
// Load a bundle with external links
134-
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in
134+
let (_, _, context) = try testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [externalResolver.bundleID: externalResolver]) { url in
135135
try """
136136
# ``SideKit/SideClass``
137137

Tests/SwiftDocCTests/Benchmark/TopicGraphHashTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import XCTest
1414
class TopicGraphHashTests: XCTestCase {
1515
func testTopicGraphSameHash() throws {
1616
let hashes: [String] = try (0...10).map { _ -> MetricValue? in
17-
let (_, context) = try testBundleAndContext(named: "TestBundle")
17+
let (_, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
1818
let testBenchmark = Benchmark()
1919
benchmark(add: Benchmark.TopicGraphHash(context: context), benchmarkLog: testBenchmark)
2020
return testBenchmark.metrics[0].result
@@ -32,7 +32,7 @@ class TopicGraphHashTests: XCTestCase {
3232
func testTopicGraphChangedHash() throws {
3333
// Verify that the hash changes if we change the topic graph
3434
let initialHash: String
35-
let (_, context) = try testBundleAndContext(named: "TestBundle")
35+
let (_, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
3636

3737
do {
3838
let testBenchmark = Benchmark()
@@ -88,7 +88,7 @@ class TopicGraphHashTests: XCTestCase {
8888
"/externally/resolved/path/to/article2": .success(.init(referencePath: "/externally/resolved/path/to/article2")),
8989
]
9090

91-
let (_, bundle, context) = try testBundleAndContext(copying: "TestBundle", externalResolvers: [
91+
let (_, bundle, context) = try testBundleAndContext(copying: "LegacyBundle_DoNotUseInNewTests", externalResolvers: [
9292
"com.external.testbundle" : resolver
9393
]) { url in
9494
// Add external links to the MyKit Topics.

Tests/SwiftDocCTests/Checker/Checkers/NonInclusiveLanguageCheckerTests.swift

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import XCTest
1212
import Markdown
1313
@testable import SwiftDocC
14+
import SwiftDocCTestUtilities
1415

1516
class NonInclusiveLanguageCheckerTests: XCTestCase {
1617

@@ -167,9 +168,9 @@ func aBlackListedFunc() {
167168
}
168169

169170
private let nonInclusiveContent = """
170-
# ``SideKit``
171+
# Some root page
171172
172-
SideKit module root symbol. And here is a ~~whitelist~~:
173+
Some custom root page. And here is a ~~whitelist~~:
173174
174175
- item one
175176
- item two
@@ -178,11 +179,12 @@ func aBlackListedFunc() {
178179

179180
func testDisabledByDefault() throws {
180181
// Create a test bundle with some non-inclusive content.
181-
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", diagnosticEngine: .init(filterLevel: .error)) { url in
182-
try self.nonInclusiveContent.write(to: url.appendingPathComponent("documentation").appendingPathComponent("sidekit.md"), atomically: true, encoding: .utf8)
183-
}
182+
let catalog = Folder(name: "unit-test.docc", content: [
183+
TextFile(name: "Root.md", utf8Content: nonInclusiveContent)
184+
])
185+
let (_, context) = try loadBundle(catalog: catalog)
184186

185-
XCTAssertEqual(context.problems.count, 0)
187+
XCTAssertEqual(context.problems.count, 0) // Non-inclusive content is an info-level diagnostic, so it's filtered out.
186188
}
187189

188190
func testEnablingTheChecker() throws {
@@ -196,9 +198,12 @@ func aBlackListedFunc() {
196198
]
197199

198200
for (severity, enabled) in expectations {
199-
let (_, _, context) = try testBundleAndContext(copying: "TestBundle", diagnosticEngine: .init(filterLevel: severity)) { url in
200-
try self.nonInclusiveContent.write(to: url.appendingPathComponent("documentation").appendingPathComponent("sidekit.md"), atomically: true, encoding: .utf8)
201-
}
201+
let catalog = Folder(name: "unit-test.docc", content: [
202+
TextFile(name: "Root.md", utf8Content: nonInclusiveContent)
203+
])
204+
var configuration = DocumentationContext.Configuration()
205+
configuration.externalMetadata.diagnosticLevel = severity
206+
let (_, context) = try loadBundle(catalog: catalog, diagnosticEngine: .init(filterLevel: severity), configuration: configuration)
202207

203208
// Verify that checker diagnostics were emitted or not, depending on the diagnostic level set.
204209
XCTAssertEqual(context.problems.contains(where: { $0.diagnostic.identifier == "org.swift.docc.NonInclusiveLanguage" }), enabled)

Tests/SwiftDocCTests/Converter/DocumentationContextConverterTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import XCTest
1414

1515
class DocumentationContextConverterTests: XCTestCase {
1616
func testRenderNodesAreIdentical() throws {
17-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
17+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
1818

1919
// We'll use this to convert nodes ad-hoc
2020
let perNodeConverter = DocumentationNodeConverter(bundle: bundle, context: context)
@@ -41,7 +41,7 @@ class DocumentationContextConverterTests: XCTestCase {
4141
}
4242

4343
func testSymbolLocationsAreOnlyIncludedWhenRequested() throws {
44-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
44+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
4545
let renderContext = RenderContext(documentationContext: context, bundle: bundle)
4646

4747
let fillIntroducedSymbolNode = try XCTUnwrap(
@@ -71,7 +71,7 @@ class DocumentationContextConverterTests: XCTestCase {
7171
}
7272

7373
func testSymbolAccessLevelsAreOnlyIncludedWhenRequested() throws {
74-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
74+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
7575
let renderContext = RenderContext(documentationContext: context, bundle: bundle)
7676

7777
let fillIntroducedSymbolNode = try XCTUnwrap(

Tests/SwiftDocCTests/Converter/RenderContextTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import XCTest
1414

1515
class RenderContextTests: XCTestCase {
1616
func testCreatesRenderReferences() throws {
17-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
17+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
1818

1919
let renderContext = RenderContext(documentationContext: context, bundle: bundle)
2020

Tests/SwiftDocCTests/Converter/TopicRenderReferenceEncoderTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ class TopicRenderReferenceEncoderTests: XCTestCase {
158158
/// Verifies that when JSON encoder should sort keys, the custom render reference cache
159159
/// respects that setting and prints the referencs in alphabetical order.
160160
func testSortedReferences() throws {
161-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
161+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
162162
let converter = DocumentationNodeConverter(bundle: bundle, context: context)
163163

164164
// Create a JSON encoder
@@ -218,7 +218,7 @@ class TopicRenderReferenceEncoderTests: XCTestCase {
218218

219219
// Verifies that there is no extra comma at the end of the references list.
220220
func testRemovesLastReferencesListDelimiter() throws {
221-
let (bundle, context) = try testBundleAndContext(named: "TestBundle")
221+
let (bundle, context) = try testBundleAndContext(named: "LegacyBundle_DoNotUseInNewTests")
222222
let converter = DocumentationNodeConverter(bundle: bundle, context: context)
223223

224224
// Create a JSON encoder

Tests/SwiftDocCTests/Diagnostics/DiagnosticConsoleWriterDefaultFormattingTest.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ class DiagnosticConsoleWriterDefaultFormattingTest: XCTestCase {
229229
let summary = "Test diagnostic summary"
230230
let explanation = "Test diagnostic explanation."
231231
let baseURL = Bundle.module.url(
232-
forResource: "TestBundle", withExtension: "docc", subdirectory: "Test Bundles")!
232+
forResource: "LegacyBundle_DoNotUseInNewTests", withExtension: "docc", subdirectory: "Test Bundles")!
233233
let source = baseURL.appendingPathComponent("TestTutorial.tutorial")
234234
let range = SourceLocation(line: 44, column: 59, source: source)..<SourceLocation(line: 44, column: 138, source: source)
235235

@@ -307,7 +307,7 @@ class DiagnosticConsoleWriterDefaultFormattingTest: XCTestCase {
307307
let summary = "Test diagnostic summary"
308308
let explanation = "Test diagnostic explanation."
309309
let baseURL = Bundle.module.url(
310-
forResource: "TestBundle", withExtension: "docc", subdirectory: "Test Bundles")!
310+
forResource: "LegacyBundle_DoNotUseInNewTests", withExtension: "docc", subdirectory: "Test Bundles")!
311311
let source = baseURL.appendingPathComponent("TestTutorial.tutorial")
312312
let diagnosticRange = SourceLocation(line: 44, column: 59, source: source)..<SourceLocation(line: 44, column: 138, source: source)
313313
let diagnostic = Diagnostic(source: source, severity: .warning, range: diagnosticRange, identifier: identifier, summary: summary, explanation: explanation)

0 commit comments

Comments
 (0)