From 31a41ef53a7211fbc59d0d4e5d325561dfc387de Mon Sep 17 00:00:00 2001 From: Nick Lockwood Date: Thu, 28 Sep 2023 07:50:21 +0100 Subject: [PATCH] Fix docComments with Note: prefix --- Sources/Tokenizer.swift | 3 ++- Tests/RulesTests+Syntax.swift | 28 ++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/Sources/Tokenizer.swift b/Sources/Tokenizer.swift index e3421af1..f370daf7 100644 --- a/Sources/Tokenizer.swift +++ b/Sources/Tokenizer.swift @@ -69,7 +69,8 @@ public extension String { guard parts.count > 1 else { return false } - return !parts[0].contains(" ") && !parts[1].hasPrefix("//") + let exclude = ["note", "warning"] + return !parts[0].contains(" ") && !exclude.contains(parts[0].lowercased()) && !parts[1].hasPrefix("//") } } diff --git a/Tests/RulesTests+Syntax.swift b/Tests/RulesTests+Syntax.swift index f8a5b63c..7b45604b 100644 --- a/Tests/RulesTests+Syntax.swift +++ b/Tests/RulesTests+Syntax.swift @@ -3178,6 +3178,34 @@ class SyntaxTests: RulesTests { testFormatting(for: input, rule: FormatRules.docComments) } + func testConvertNoteCommentsToDocComments() { + let input = """ + // Does something + // Note: not really + func doSomething() {} + """ + let output = """ + /// Does something + /// Note: not really + func doSomething() {} + """ + testFormatting(for: input, output, rule: FormatRules.docComments) + } + + func testConvertURLCommentsToDocComments() { + let input = """ + // Does something + // http://example.com + func doSomething() {} + """ + let output = """ + /// Does something + /// http://example.com + func doSomething() {} + """ + testFormatting(for: input, output, rule: FormatRules.docComments) + } + func testMultilineDocCommentReplaced() { let input = """ // A class