Skip to content

Commit a2d3f59

Browse files
authored
Enable parameter and return value validation by default (#882)
* Enable parameter and return value validation by default rdar://125835874 * Remove various links to symbols that no longer exist * Fix warnings about undocumented parameters * Add article about documenting multi-source-language APIs * Fix additional warnings about undocumented parameters * Refine the synthesized content phrasing for ObjC API with errors rdar://125835874 * Clarify documentation about documenting return values. * Update example error documentation * Rename feature flag to remove "experimental" * Remove redundant test setup * Fix test that documented parameters that the symbol didn't have * Fix test that was expecting the wrong number of diagnostics * Add license comment to new documentation article
1 parent c6e32f6 commit a2d3f59

File tree

47 files changed

+410
-227
lines changed

Some content is hidden

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

47 files changed

+410
-227
lines changed

Sources/SwiftDocC/Benchmark/Benchmark.swift

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -94,38 +94,48 @@ private extension Benchmark {
9494
}
9595

9696
/// Logs a one-off metric value.
97-
/// - Parameter event: The metric to add to the log.
98-
public func benchmark<E>(add event: @autoclosure () -> E, benchmarkLog log: Benchmark = .main) where E: BenchmarkMetric {
97+
/// - Parameters:
98+
/// - metric: The one-off metric
99+
/// - log: The log to add the metric to.
100+
public func benchmark<E>(add metric: @autoclosure () -> E, benchmarkLog log: Benchmark = .main) where E: BenchmarkMetric {
99101
guard log.shouldLogMetricType(E.self) else { return }
100102

101-
log.metrics.append(event())
103+
log.metrics.append(metric())
102104
}
103105

104-
/// Starts the given metric.
105-
/// - Parameter event: The metric to start.
106-
public func benchmark<E>(begin event: @autoclosure () -> E, benchmarkLog log: Benchmark = .main) -> E? where E: BenchmarkBlockMetric {
106+
/// Begins the given metric.
107+
/// - Parameters:
108+
/// - metric: The metric to begin measuring.
109+
/// - log: The log that may filter out the metric.
110+
public func benchmark<E>(begin metric: @autoclosure () -> E, benchmarkLog log: Benchmark = .main) -> E? where E: BenchmarkBlockMetric {
107111
guard log.shouldLogMetricType(E.self) else { return nil }
108112

109-
let event = event()
110-
event.begin()
111-
return event
113+
let metric = metric()
114+
metric.begin()
115+
return metric
112116
}
113117

114118
/// Ends the given metric and adds it to the log.
115-
/// - Parameter event: The metric to end and log.
116-
public func benchmark<E>(end event: @autoclosure () -> E?, benchmarkLog log: Benchmark = .main) where E: BenchmarkBlockMetric {
117-
guard log.shouldLogMetricType(E.self), let event = event() else { return }
119+
/// - Parameters:
120+
/// - metric: The metric to end and log.
121+
/// - log: The log to add the metric to.
122+
public func benchmark<E>(end metric: @autoclosure () -> E?, benchmarkLog log: Benchmark = .main) where E: BenchmarkBlockMetric {
123+
guard log.shouldLogMetricType(E.self), let metric = metric() else { return }
118124

119-
event.end()
120-
log.metrics.append(event)
125+
metric.end()
126+
log.metrics.append(metric)
121127
}
122128

123-
/// Ends the given metric and adds it to the log.
124-
/// - Parameter event: The metric to end and log.
125129
@discardableResult
126-
public func benchmark<E, Result>(wrap event: @autoclosure () -> E, benchmarkLog log: Benchmark = .main, body: () throws -> Result) rethrows -> Result where E: BenchmarkBlockMetric {
130+
/// Measures a metric around the given closure.
131+
/// - Parameters:
132+
/// - metric: The metric to measure and log.
133+
/// - log: The log to add the metric to.
134+
/// - body: The closure around which to measure the metric.
135+
/// - Returns: The return value from the closure.
136+
public func benchmark<E, Result>(wrap metric: @autoclosure () -> E, benchmarkLog log: Benchmark = .main, body: () throws -> Result) rethrows -> Result where E: BenchmarkBlockMetric {
127137
if log.shouldLogMetricType(E.self) {
128-
let event = event()
138+
let event = metric()
129139
event.begin()
130140
let result = try body()
131141
event.end()

Sources/SwiftDocC/Checker/Checkers/MissingAbstract.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -23,7 +23,6 @@ public struct MissingAbstract: Checker {
2323

2424
/// Creates a new checker that detects documents without abstracts.
2525
///
26-
/// - Parameter document: The documentation node that the checker checks.
2726
/// - Parameter sourceFile: The URL to the documentation file that the checker checks.
2827
public init(sourceFile: URL?) {
2928
self.sourceFile = sourceFile

Sources/SwiftDocC/Converter/DocumentationContextConverter.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -37,6 +37,7 @@ public class DocumentationContextConverter {
3737
/// Whether the documentation converter should include access level information for symbols.
3838
let shouldEmitSymbolAccessLevels: Bool
3939

40+
/// A list of symbol IDs that have version of their documentation page with more content that a renderer can link to.
4041
let symbolIdentifiersWithExpandedDocumentation: [String]?
4142

4243
/// The remote source control repository where the documented module's source is hosted.
@@ -56,7 +57,9 @@ public class DocumentationContextConverter {
5657
/// Before passing `true` please confirm that your use case doesn't include public
5758
/// distribution of any created render nodes as there are filesystem privacy and security
5859
/// concerns with distributing this data.
60+
/// - emitSymbolAccessLevels: Whether the documentation converter should include access level information for symbols.
5961
/// - sourceRepository: The source repository where the documentation's sources are hosted.
62+
/// - symbolIdentifiersWithExpandedDocumentation: A list of symbol IDs that have version of their documentation page with more content that a renderer can link to.
6063
public init(
6164
bundle: DocumentationBundle,
6265
context: DocumentationContext,

Sources/SwiftDocC/DocumentationService/Models/Services/Convert/ConvertRequest.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -98,6 +98,8 @@ public struct ConvertRequest: Codable {
9898
/// Creates a request to convert in-memory documentation.
9999
/// - Parameters:
100100
/// - bundleInfo: Information about the bundle to convert.
101+
/// - featureFlags: Feature flags to enable when performing this convert request.
102+
/// - externalIDsToConvert: The external IDs of the symbols to convert.
101103
/// - documentPathsToConvert: The paths of the documentation nodes to convert.
102104
/// - includeRenderReferenceStore: Whether the conversion's render reference store should be included in the
103105
/// response.

Sources/SwiftDocC/Indexing/Navigator/NavigatorIndex.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021-2022 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -553,16 +553,16 @@ extension NavigatorIndex {
553553
/// for any custom icons used in this navigator index.
554554
var iconReferences = [String : ImageReference]()
555555

556-
/**
557-
Initialize a `Builder` with the given data provider and output URL.
558-
- Parameters:
559-
- renderNodeProvider: The `RenderNode` provider to use.
560-
- outputURL: The URL to which the data should be written.
561-
- bundleIdentifier: The identifier of the bundle the index is built for.
562-
- sortRootChildren: Indicates if the root's children must be sorted by name.
563-
- groupByLanguage: Indicates if the tree needs to group the entries by language.
564-
- usePageTitle: Use the page title instead of the navigator title as the entry title.
565-
*/
556+
557+
/// Create a new a builder with the given data provider and output URL.
558+
/// - Parameters:
559+
/// - renderNodeProvider: The `RenderNode` provider to use.
560+
/// - outputURL: The location where the builder will write the the built navigator index.
561+
/// - bundleIdentifier: The bundle identifier of the documentation that the builder builds a navigator index for.
562+
/// - sortRootChildrenByName: Configure the builder to sort root's children by name.
563+
/// - groupByLanguage: Configure the builder to group the entries by language.
564+
/// - writePathsOnDisk: Configure the builder to write each navigator item's path components to the location.
565+
/// - usePageTitle: Configure the builder to use the "page title" instead of the "navigator title" as the title for each entry.
566566
public init(renderNodeProvider: RenderNodeProvider? = nil, outputURL: URL, bundleIdentifier: String, sortRootChildrenByName: Bool = false, groupByLanguage: Bool = false, writePathsOnDisk: Bool = true, usePageTitle: Bool = false) {
567567
self.renderNodeProvider = renderNodeProvider
568568
self.outputURL = outputURL

Sources/SwiftDocC/Indexing/Navigator/NavigatorItem.swift

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
This source file is part of the Swift.org open source project
33

4-
Copyright (c) 2021 Apple Inc. and the Swift project authors
4+
Copyright (c) 2021-2024 Apple Inc. and the Swift project authors
55
Licensed under Apache License v2.0 with Runtime Library Exception
66

77
See https://swift.org/LICENSE.txt for license information
@@ -42,10 +42,10 @@ public final class NavigatorItem: Serializable, Codable, Equatable, CustomString
4242
public let availabilityID: UInt64
4343

4444
/// The path information of the item (might be a URL as well).
45-
internal var path: String = ""
45+
var path: String = ""
4646

4747
/// If available, a hashed USR of this entry and its language information.
48-
internal var usrIdentifier: String? = nil
48+
var usrIdentifier: String? = nil
4949

5050
var icon: RenderReferenceIdentifier? = nil
5151

@@ -59,6 +59,7 @@ public final class NavigatorItem: Serializable, Codable, Equatable, CustomString
5959
- platformMask: The mask indicating for which platform the page is available.
6060
- availabilityID: The identifier of the availability information of the page.
6161
- path: The path to load the content.
62+
- icon: A reference to a custom image for this navigator item.
6263
*/
6364
init(pageType: UInt8, languageID: UInt8, title: String, platformMask: UInt64, availabilityID: UInt64, path: String, icon: RenderReferenceIdentifier? = nil) {
6465
self.pageType = pageType
@@ -79,6 +80,7 @@ public final class NavigatorItem: Serializable, Codable, Equatable, CustomString
7980
- title: The user facing page title.
8081
- platformMask: The mask indicating for which platform the page is available.
8182
- availabilityID: The identifier of the availability information of the page.
83+
- icon: A reference to a custom image for this navigator item.
8284
*/
8385
public init(pageType: UInt8, languageID: UInt8, title: String, platformMask: UInt64, availabilityID: UInt64, icon: RenderReferenceIdentifier? = nil) {
8486
self.pageType = pageType

Sources/SwiftDocC/Indexing/RenderIndexJSON/RenderIndex.swift

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ extension RenderIndex {
128128
/// Allows renderers to use a specific design treatment for render index nodes that mark the node as in beta.
129129
public let isBeta: Bool
130130

131-
/// Reference to the image that should be used to represent this node.
131+
/// A reference to a custom image for this node.
132132
public let icon: RenderReferenceIdentifier?
133133

134134
enum CodingKeys: String, CodingKey {
@@ -197,10 +197,11 @@ extension RenderIndex {
197197
/// - path: The relative path to the page represented by this node.
198198
/// - type: The type of this node.
199199
/// - children: The children of this node.
200-
/// - isDeprecated : If the current node has been marked as deprecated.
200+
/// - isDeprecated: If the current node has been marked as deprecated.
201201
/// - isExternal: If the current node belongs to an external
202202
/// documentation archive.
203203
/// - isBeta: If the current node is in beta.
204+
/// - icon: A reference to a custom image for this node.
204205
public init(
205206
title: String,
206207
path: String?,

Sources/SwiftDocC/Infrastructure/Bundle Assets/DataAssetManager.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ public struct DataAsset: Codable, Equatable {
187187
/// - Parameters:
188188
/// - url: The location of the variant.
189189
/// - traitCollection: The trait collection associated with the variant.
190+
/// - metadata: Metadata specific to this variant of the asset.
190191
public mutating func register(_ url: URL, with traitCollection: DataTraitCollection, metadata: Metadata = Metadata()) {
191192
variants[traitCollection] = url
192193
self.metadata[url] = metadata

Sources/SwiftDocC/Infrastructure/CoverageDataEntry.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ public struct CoverageDataEntry: CustomStringConvertible, Codable {
104104
}
105105

106106
/// Outputs a short table summarizing the coverage statistics for a list of data entries.
107-
/// - Parameter coverageInfo: An array of entries to summarize.
108107
public static func generateSummary(
109108
of coverageInfo: [CoverageDataEntry],
110109
shouldGenerateBrief: Bool,

Sources/SwiftDocC/Infrastructure/Diagnostics/DiagnosticConsoleWriter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public final class DiagnosticConsoleWriter: DiagnosticFormattingConsumer {
2424
/// Creates a new instance of this class with the provided output stream.
2525
/// - Parameters:
2626
/// - stream: The output stream to which this instance will write.
27-
/// - formattingOptions: The formatting options for the diagnostics.
28-
/// - baseUrl: A url to be used as a base url when formatting diagnostic source path.
27+
/// - options: The formatting options for the diagnostics.
28+
/// - baseURL: A url to be used as a base url when formatting diagnostic source path.
2929
/// - highlight: Whether or not to highlight the default diagnostic formatting output.
3030
public convenience init(
3131
_ stream: TextOutputStream = LogHandle.standardError,

0 commit comments

Comments
 (0)