Skip to content

Enable parameter and return value validation by default #882

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions Sources/SwiftDocC/Benchmark/Benchmark.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

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

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

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

log.metrics.append(event())
log.metrics.append(metric())
}

/// Starts the given metric.
/// - Parameter event: The metric to start.
public func benchmark<E>(begin event: @autoclosure () -> E, benchmarkLog log: Benchmark = .main) -> E? where E: BenchmarkBlockMetric {
/// Begins the given metric.
/// - Parameters:
/// - metric: The metric to begin measuring.
/// - log: The log that may filter out the metric.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add a Returns: doc comment for this function also?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal of this PR isn't to extensively document all the parameters and return values, only to fix the warnings about mis-documented parameters or return values.

public func benchmark<E>(begin metric: @autoclosure () -> E, benchmarkLog log: Benchmark = .main) -> E? where E: BenchmarkBlockMetric {
guard log.shouldLogMetricType(E.self) else { return nil }

let event = event()
event.begin()
return event
let metric = metric()
metric.begin()
return metric
}

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

event.end()
log.metrics.append(event)
metric.end()
log.metrics.append(metric)
}

/// Ends the given metric and adds it to the log.
/// - Parameter event: The metric to end and log.
@discardableResult
public func benchmark<E, Result>(wrap event: @autoclosure () -> E, benchmarkLog log: Benchmark = .main, body: () throws -> Result) rethrows -> Result where E: BenchmarkBlockMetric {
/// Measures a metric around the given closure.
/// - Parameters:
/// - metric: The metric to measure and log.
/// - log: The log to add the metric to.
/// - body: The closure around which to measure the metric.
/// - Returns: The return value from the closure.
public func benchmark<E, Result>(wrap metric: @autoclosure () -> E, benchmarkLog log: Benchmark = .main, body: () throws -> Result) rethrows -> Result where E: BenchmarkBlockMetric {
if log.shouldLogMetricType(E.self) {
let event = event()
let event = metric()
event.begin()
let result = try body()
event.end()
Expand Down
3 changes: 1 addition & 2 deletions Sources/SwiftDocC/Checker/Checkers/MissingAbstract.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

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

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

/// Creates a new checker that detects documents without abstracts.
///
/// - Parameter document: The documentation node that the checker checks.
/// - Parameter sourceFile: The URL to the documentation file that the checker checks.
public init(sourceFile: URL?) {
self.sourceFile = sourceFile
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

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

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

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

/// The remote source control repository where the documented module's source is hosted.
Expand All @@ -56,7 +57,9 @@ public class DocumentationContextConverter {
/// Before passing `true` please confirm that your use case doesn't include public
/// distribution of any created render nodes as there are filesystem privacy and security
/// concerns with distributing this data.
/// - emitSymbolAccessLevels: Whether the documentation converter should include access level information for symbols.
/// - sourceRepository: The source repository where the documentation's sources are hosted.
/// - symbolIdentifiersWithExpandedDocumentation: A list of symbol IDs that have version of their documentation page with more content that a renderer can link to.
public init(
bundle: DocumentationBundle,
context: DocumentationContext,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

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

See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -98,6 +98,8 @@ public struct ConvertRequest: Codable {
/// Creates a request to convert in-memory documentation.
/// - Parameters:
/// - bundleInfo: Information about the bundle to convert.
/// - featureFlags: Feature flags to enable when performing this convert request.
/// - externalIDsToConvert: The external IDs of the symbols to convert.
/// - documentPathsToConvert: The paths of the documentation nodes to convert.
/// - includeRenderReferenceStore: Whether the conversion's render reference store should be included in the
/// response.
Expand Down
22 changes: 11 additions & 11 deletions Sources/SwiftDocC/Indexing/Navigator/NavigatorIndex.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

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

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

/**
Initialize a `Builder` with the given data provider and output URL.
- Parameters:
- renderNodeProvider: The `RenderNode` provider to use.
- outputURL: The URL to which the data should be written.
- bundleIdentifier: The identifier of the bundle the index is built for.
- sortRootChildren: Indicates if the root's children must be sorted by name.
- groupByLanguage: Indicates if the tree needs to group the entries by language.
- usePageTitle: Use the page title instead of the navigator title as the entry title.
*/

/// Create a new a builder with the given data provider and output URL.
/// - Parameters:
/// - renderNodeProvider: The `RenderNode` provider to use.
/// - outputURL: The location where the builder will write the the built navigator index.
/// - bundleIdentifier: The bundle identifier of the documentation that the builder builds a navigator index for.
/// - sortRootChildrenByName: Configure the builder to sort root's children by name.
/// - groupByLanguage: Configure the builder to group the entries by language.
/// - writePathsOnDisk: Configure the builder to write each navigator item's path components to the location.
/// - usePageTitle: Configure the builder to use the "page title" instead of the "navigator title" as the title for each entry.
public init(renderNodeProvider: RenderNodeProvider? = nil, outputURL: URL, bundleIdentifier: String, sortRootChildrenByName: Bool = false, groupByLanguage: Bool = false, writePathsOnDisk: Bool = true, usePageTitle: Bool = false) {
self.renderNodeProvider = renderNodeProvider
self.outputURL = outputURL
Expand Down
8 changes: 5 additions & 3 deletions Sources/SwiftDocC/Indexing/Navigator/NavigatorItem.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

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

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

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

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

var icon: RenderReferenceIdentifier? = nil

Expand All @@ -59,6 +59,7 @@ public final class NavigatorItem: Serializable, Codable, Equatable, CustomString
- platformMask: The mask indicating for which platform the page is available.
- availabilityID: The identifier of the availability information of the page.
- path: The path to load the content.
- icon: A reference to a custom image for this navigator item.
*/
init(pageType: UInt8, languageID: UInt8, title: String, platformMask: UInt64, availabilityID: UInt64, path: String, icon: RenderReferenceIdentifier? = nil) {
self.pageType = pageType
Expand All @@ -79,6 +80,7 @@ public final class NavigatorItem: Serializable, Codable, Equatable, CustomString
- title: The user facing page title.
- platformMask: The mask indicating for which platform the page is available.
- availabilityID: The identifier of the availability information of the page.
- icon: A reference to a custom image for this navigator item.
*/
public init(pageType: UInt8, languageID: UInt8, title: String, platformMask: UInt64, availabilityID: UInt64, icon: RenderReferenceIdentifier? = nil) {
self.pageType = pageType
Expand Down
5 changes: 3 additions & 2 deletions Sources/SwiftDocC/Indexing/RenderIndexJSON/RenderIndex.swift
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ extension RenderIndex {
/// Allows renderers to use a specific design treatment for render index nodes that mark the node as in beta.
public let isBeta: Bool

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

enum CodingKeys: String, CodingKey {
Expand Down Expand Up @@ -197,10 +197,11 @@ extension RenderIndex {
/// - path: The relative path to the page represented by this node.
/// - type: The type of this node.
/// - children: The children of this node.
/// - isDeprecated : If the current node has been marked as deprecated.
/// - isDeprecated: If the current node has been marked as deprecated.
/// - isExternal: If the current node belongs to an external
/// documentation archive.
/// - isBeta: If the current node is in beta.
/// - icon: A reference to a custom image for this node.
public init(
title: String,
path: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public struct DataAsset: Codable, Equatable {
/// - Parameters:
/// - url: The location of the variant.
/// - traitCollection: The trait collection associated with the variant.
/// - metadata: Metadata specific to this variant of the asset.
public mutating func register(_ url: URL, with traitCollection: DataTraitCollection, metadata: Metadata = Metadata()) {
variants[traitCollection] = url
self.metadata[url] = metadata
Expand Down
1 change: 0 additions & 1 deletion Sources/SwiftDocC/Infrastructure/CoverageDataEntry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ public struct CoverageDataEntry: CustomStringConvertible, Codable {
}

/// Outputs a short table summarizing the coverage statistics for a list of data entries.
/// - Parameter coverageInfo: An array of entries to summarize.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it's an experimental API that result in warnings about not having all of its parameters documented.

public static func generateSummary(
of coverageInfo: [CoverageDataEntry],
shouldGenerateBrief: Bool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public final class DiagnosticConsoleWriter: DiagnosticFormattingConsumer {
/// Creates a new instance of this class with the provided output stream.
/// - Parameters:
/// - stream: The output stream to which this instance will write.
/// - formattingOptions: The formatting options for the diagnostics.
/// - baseUrl: A url to be used as a base url when formatting diagnostic source path.
/// - options: The formatting options for the diagnostics.
/// - baseURL: A url to be used as a base url when formatting diagnostic source path.
/// - highlight: Whether or not to highlight the default diagnostic formatting output.
public convenience init(
_ stream: TextOutputStream = LogHandle.standardError,
Expand Down
15 changes: 7 additions & 8 deletions Sources/SwiftDocC/Infrastructure/DocumentationBundle.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift.org open source project

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

See https://swift.org/LICENSE.txt for license information
Expand All @@ -23,8 +23,6 @@ import Foundation
- ``displayName``
- ``identifier``
- ``version``
- ``defaultCodeListingLanguage``
- ``defaultAvailability``
Comment on lines -26 to -27
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why removing these symbols from here? There are also part of the Documentation Bundle.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are not. These links don't resolve to anything.

*/
public struct DocumentationBundle {
public enum PropertyListError: DescribedError {
Expand Down Expand Up @@ -81,13 +79,13 @@ public struct DocumentationBundle {
/// Miscellaneous resources of the bundle.
public let miscResourceURLs: [URL]

/// Custom HTML file to use as the header for rendered output.
/// A custom HTML file to use as the header for rendered output.
public let customHeader: URL?

/// Custom HTML file to use as the footer for rendered output.
/// A custom HTML file to use as the footer for rendered output.
public let customFooter: URL?

/// JSON settings file used to theme renderer output.
/// A custom JSON settings file used to theme renderer output.
public let themeSettings: URL?

/**
Expand All @@ -106,8 +104,9 @@ public struct DocumentationBundle {
/// - symbolGraphURLs: Symbol Graph JSON files for the modules documented by the bundle.
/// - markupURLs: DocC Markup files of the bundle.
/// - miscResourceURLs: Miscellaneous resources of the bundle.
/// - customHeader: Custom HTML file to use as the header for rendered output.
/// - customFooter: Custom HTML file to use as the footer for rendered output.
/// - customHeader: A custom HTML file to use as the header for rendered output.
/// - customFooter: A custom HTML file to use as the footer for rendered output.
/// - themeSettings: A custom JSON settings file used to theme renderer output.
public init(
info: Info,
baseURL: URL = URL(string: "/")!,
Expand Down
3 changes: 2 additions & 1 deletion Sources/SwiftDocC/Infrastructure/DocumentationContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2726,7 +2726,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
- Parameters:
- reference: An unresolved (or resolved) reference.
- parent: The *resolved* reference that serves as an enclosing search context, especially the parent reference's bundle identifier.
- fromSymbolLink: If `true` will try to resolve relative links *only* in documentation symbol locations in the hierarchy. If `false` it will try to resolve relative links as tutorials, articles, symbols, etc.
- isCurrentlyResolvingSymbolLink: If `true` will try to resolve relative links *only* in documentation symbol locations in the hierarchy. If `false` it will try to resolve relative links as tutorials, articles, symbols, etc.
- Returns: Either the successfully resolved reference for the topic or error information about why the reference couldn't resolve.
*/
public func resolve(_ reference: TopicReference, in parent: ResolvedTopicReference, fromSymbolLink isCurrentlyResolvingSymbolLink: Bool = false) -> TopicReferenceResolutionResult {
Expand Down Expand Up @@ -2756,6 +2756,7 @@ public class DocumentationContext: DocumentationContextDataProviderDelegate {
/// - Parameters:
/// - name: The name of the asset.
/// - parent: The topic where the asset is referenced.
/// - type: A restriction for what type of asset to resolve.
/// - Returns: The data that's associated with an image asset if it was found, otherwise `nil`.
public func resolveAsset(named name: String, in parent: ResolvedTopicReference, withType type: AssetType? = nil) -> DataAsset? {
let bundleIdentifier = parent.bundleIdentifier
Expand Down
Loading