Skip to content

Commit 6bc9eb8

Browse files
authored
Fix a few minor warnings (#449)
* Resolve deprecation warning in test for a renamed SwiftDocC property * Resolve warning about inferred type for an empty array literal * Resolve another deprecation warning in test for a renamed SwiftDocC property * Resolve warning about comparing non-optional value to nil * Resolve another warning about comparing non-optional value to nil Since the filter has no effect the second `count > 1` check is redundant
1 parent 87318ef commit 6bc9eb8

File tree

3 files changed

+30
-36
lines changed

3 files changed

+30
-36
lines changed

Sources/SwiftDocC/Model/Rendering/Symbol/AvailabilityRenderMetadataItem.swift

Lines changed: 3 additions & 6 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-2023 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
@@ -141,11 +141,8 @@ public struct AvailabilityRenderItem: Codable, Hashable, Equatable {
141141
}
142142

143143
init?(_ availability: Metadata.Availability, current: PlatformVersion?) {
144-
if availability.introduced == nil {
145-
// FIXME: Deprecated/Beta markings need platform versions to display properly in Swift-DocC-Render (rdar://56897597)
146-
// Fill in the appropriate values here when that's fixed (https://github.com/apple/swift-docc/issues/441)
147-
return nil
148-
}
144+
// FIXME: Deprecated/Beta markings need platform versions to display properly in Swift-DocC-Render (rdar://56897597)
145+
// Fill in the appropriate values here when that's fixed (https://github.com/apple/swift-docc/issues/441)
149146

150147
let platformName = PlatformName(metadataPlatform: availability.platform)
151148
name = platformName?.displayName

Sources/SwiftDocC/Semantics/DirectiveInfrastructure/AutomaticDirectiveConvertible.swift

Lines changed: 2 additions & 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) 2022 Apple Inc. and the Swift project authors
4+
Copyright (c) 2022-2023 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
@@ -239,7 +239,7 @@ extension AutomaticDirectiveConvertible {
239239

240240
guard let parsedDirective = parsedDirective else {
241241
if childDirective.storedAsArray && !childDirective.storedAsOptional {
242-
childDirective.setValue(on: self, to: [parsedDirective].compactMap { $0 })
242+
childDirective.setValue(on: self, to: [DirectiveConvertible.Type]())
243243
}
244244

245245
continue

Sources/SwiftDocC/Semantics/Metadata/Metadata.swift

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -150,39 +150,36 @@ public final class Metadata: Semantic, AutomaticDirectiveConvertible {
150150

151151
let categorizedAvailability = Dictionary(grouping: availability, by: \.platform)
152152

153-
for availabilityAttrs in categorizedAvailability.values {
154-
guard availabilityAttrs.count > 1 else {
153+
for duplicateIntroduced in categorizedAvailability.values {
154+
guard duplicateIntroduced.count > 1 else {
155155
continue
156156
}
157+
158+
for availability in duplicateIntroduced {
159+
let diagnostic = Diagnostic(
160+
source: availability.originalMarkup.nameLocation?.source,
161+
severity: .warning,
162+
range: availability.originalMarkup.range,
163+
identifier: "org.swift.docc.\(Metadata.Availability.self).DuplicateIntroduced",
164+
summary: "Duplicate \(Metadata.Availability.directiveName.singleQuoted) directive with 'introduced' argument",
165+
explanation: """
166+
A documentation page can only contain a single 'introduced' version for each platform.
167+
"""
168+
)
157169

158-
let duplicateIntroduced = availabilityAttrs.filter({ $0.introduced != nil })
159-
if duplicateIntroduced.count > 1 {
160-
for avail in duplicateIntroduced {
161-
let diagnostic = Diagnostic(
162-
source: avail.originalMarkup.nameLocation?.source,
163-
severity: .warning,
164-
range: avail.originalMarkup.range,
165-
identifier: "org.swift.docc.\(Metadata.Availability.self).DuplicateIntroduced",
166-
summary: "Duplicate \(Metadata.Availability.directiveName.singleQuoted) directive with 'introduced' argument",
167-
explanation: """
168-
A documentation page can only contain a single 'introduced' version for each platform.
169-
"""
170-
)
171-
172-
guard let range = avail.originalMarkup.range else {
173-
problems.append(Problem(diagnostic: diagnostic))
174-
continue
175-
}
170+
guard let range = availability.originalMarkup.range else {
171+
problems.append(Problem(diagnostic: diagnostic))
172+
continue
173+
}
176174

177-
let solution = Solution(
178-
summary: "Remove extraneous \(Metadata.Availability.directiveName.singleQuoted) directive",
179-
replacements: [
180-
Replacement(range: range, replacement: "")
181-
]
182-
)
175+
let solution = Solution(
176+
summary: "Remove extraneous \(Metadata.Availability.directiveName.singleQuoted) directive",
177+
replacements: [
178+
Replacement(range: range, replacement: "")
179+
]
180+
)
183181

184-
problems.append(Problem(diagnostic: diagnostic, possibleSolutions: [solution]))
185-
}
182+
problems.append(Problem(diagnostic: diagnostic, possibleSolutions: [solution]))
186183
}
187184
}
188185

0 commit comments

Comments
 (0)