@@ -200,56 +200,64 @@ public final class Metadata: Semantic, AutomaticDirectiveConvertible {
200200
201201 /// Validates the use of this Metadata directive in a documentation comment.
202202 ///
203- /// Some configuration options of Metadata are invalid in documentation comments. This function
204- /// emits warnings for illegal uses and sets their values to `nil`.
205- func validateForUseInDocumentationComment(
206- symbolSource: URL ? ,
207- problems: inout [ Problem ]
208- ) {
209- let invalidDirectives : [ ( any AutomaticDirectiveConvertible ) ? ] = [
210- documentationOptions,
211- technologyRoot,
212- displayName,
213- callToAction,
214- pageKind,
215- _pageColor,
216- titleHeading,
217- ] + ( redirects ?? [ ] )
218- + supportedLanguages
219- + pageImages
220-
221- let namesAndRanges = invalidDirectives
222- . compactMap { $0 }
223- . map { ( type ( of: $0) . directiveName, $0. originalMarkup. range) }
203+ /// Some configuration options of Metadata are not supported in documentation comments.
204+ /// This function emits warnings for unsupported uses and resets their values (to `nil` or `[]`) .
205+ func validateForUseInDocumentationComment( symbolSource: URL ? , problems: inout [ Problem ] ) {
206+ func validateUnsupportedMetadataDirective< Directive: AutomaticDirectiveConvertible > ( for directives: [ Directive ] ? ) {
207+ for directive in directives ?? [ ] {
208+ validateUnsupportedMetadataDirective ( for: directive)
209+ }
210+ }
224211
225- problems. append (
226- contentsOf: namesAndRanges. map { ( name, range) in
227- let diagnostic = Diagnostic (
228- source: symbolSource,
229- severity: . warning,
230- range: range,
231- identifier: " org.swift.docc. \( Metadata . directiveName) .Invalid \( name) InDocumentationComment " ,
232- summary: " Invalid use of \( name. singleQuoted) directive in documentation comment; configuration will be ignored " ,
233- explanation: " Specify this configuration in a documentation extension file "
234- )
235-
236- let solutions : [ Solution ] = range. map { range in
237- [ Solution (
238- summary: " Remove invalid \( name. singleQuoted) directive " ,
239- replacements: [
240- Replacement ( range: range, replacement: " " )
241- ]
242- ) ]
243- } ?? [ ]
244-
245- return Problem ( diagnostic: diagnostic, possibleSolutions: solutions)
212+ func validateUnsupportedMetadataDirective< Directive: AutomaticDirectiveConvertible > ( for directive: Directive ? ) {
213+ guard let directive else {
214+ return
246215 }
247- )
216+
217+ let name = Directive . directiveName
218+ let range = directive. originalMarkup. range
219+
220+ let diagnostic = Diagnostic (
221+ source: symbolSource,
222+ severity: . warning,
223+ range: range,
224+ identifier: " org.swift.docc. \( Metadata . directiveName) .Invalid \( name) InDocumentationComment " ,
225+ summary: " Invalid use of \( name. singleQuoted) directive in documentation comment; configuration will be ignored " ,
226+ explanation: " Specify this configuration in a documentation extension file "
227+ )
228+
229+ let solutions : [ Solution ] = range. map { range in
230+ [ Solution (
231+ summary: " Remove invalid \( name. singleQuoted) directive " ,
232+ replacements: [
233+ Replacement ( range: range, replacement: " " )
234+ ]
235+ ) ]
236+ } ?? [ ]
237+
238+ problems. append ( Problem ( diagnostic: diagnostic, possibleSolutions: solutions) )
239+ }
240+
241+ validateUnsupportedMetadataDirective ( for: documentationOptions)
242+ validateUnsupportedMetadataDirective ( for: technologyRoot)
243+ validateUnsupportedMetadataDirective ( for: displayName)
244+ validateUnsupportedMetadataDirective ( for: callToAction)
245+ validateUnsupportedMetadataDirective ( for: pageKind)
246+ validateUnsupportedMetadataDirective ( for: _pageColor)
247+ validateUnsupportedMetadataDirective ( for: titleHeading)
248+ validateUnsupportedMetadataDirective ( for: redirects)
249+ validateUnsupportedMetadataDirective ( for: supportedLanguages)
250+ validateUnsupportedMetadataDirective ( for: pageImages)
248251
249252 documentationOptions = nil
250- technologyRoot = nil
251- displayName = nil
252- pageKind = nil
253- _pageColor = nil
253+ technologyRoot = nil
254+ displayName = nil
255+ callToAction = nil
256+ pageKind = nil
257+ _pageColor = nil
258+ titleHeading = nil
259+ redirects = nil
260+ supportedLanguages = [ ]
261+ pageImages = [ ]
254262 }
255263}
0 commit comments