mirror of
https://github.com/realm/SwiftLint.git
synced 2026-06-06 20:18:40 +00:00
improve MissingDocsRule
by checking for documentation comment body rather than doc comment attribute
This commit is contained in:
@@ -9,19 +9,22 @@
|
||||
import SourceKittenFramework
|
||||
import SwiftXPC
|
||||
|
||||
private func missingDocOffsets(dictionary: XPCDictionary) -> [Int] {
|
||||
let substructureOffsets = (dictionary["key.substructure"] as? XPCArray)?
|
||||
.flatMap { $0 as? XPCDictionary }
|
||||
.flatMap(missingDocOffsets) ?? []
|
||||
let docAttribute = "source.decl.attribute.__raw_doc_comment"
|
||||
guard let _ = (dictionary["key.kind"] as? String).flatMap(SwiftDeclarationKind.init),
|
||||
offset = dictionary["key.offset"] as? Int64,
|
||||
accessibility = dictionary["key.accessibility"] as? String
|
||||
where accessibility == "source.lang.swift.accessibility.public" &&
|
||||
String(dictionary["key.attributes"]).rangeOfString(docAttribute) == nil else {
|
||||
extension File {
|
||||
private func missingDocOffsets(dictionary: XPCDictionary) -> [Int] {
|
||||
let substructureOffsets = (dictionary["key.substructure"] as? XPCArray)?
|
||||
.flatMap { $0 as? XPCDictionary }
|
||||
.flatMap(missingDocOffsets) ?? []
|
||||
guard let _ = (dictionary["key.kind"] as? String).flatMap(SwiftDeclarationKind.init),
|
||||
offset = dictionary["key.offset"] as? Int64,
|
||||
accessibility = dictionary["key.accessibility"] as? String
|
||||
where accessibility == "source.lang.swift.accessibility.public" else {
|
||||
return substructureOffsets
|
||||
}
|
||||
if getDocumentationCommentBody(dictionary, syntaxMap: syntaxMap) != nil {
|
||||
return substructureOffsets
|
||||
}
|
||||
return substructureOffsets + [Int(offset)]
|
||||
}
|
||||
return substructureOffsets + [Int(offset)]
|
||||
}
|
||||
|
||||
public struct MissingDocsRule: Rule {
|
||||
@@ -34,19 +37,21 @@ public struct MissingDocsRule: Rule {
|
||||
nonTriggeringExamples: [
|
||||
"/// docs\npublic func a() {}\n",
|
||||
"/** docs */\npublic func a() {}\n",
|
||||
"// regular comment\nfunc a() {}\n",
|
||||
"/* regular comment */\nfunc a() {}\n",
|
||||
"func a() {}\n",
|
||||
"internal func a() {}\n",
|
||||
"private func a() {}\n"
|
||||
"private func a() {}\n",
|
||||
"// regular comment\nfunc a() {}\n",
|
||||
"/* regular comment */\nfunc a() {}\n"
|
||||
],
|
||||
triggeringExamples: [
|
||||
"public func a() {}\n"
|
||||
"public func a() {}\n",
|
||||
"// regular comment\npublic func a() {}\n",
|
||||
"/* regular comment */\npublic func a() {}\n"
|
||||
]
|
||||
)
|
||||
|
||||
public func validateFile(file: File) -> [StyleViolation] {
|
||||
return missingDocOffsets(Structure(file: file).dictionary).map {
|
||||
return file.missingDocOffsets(Structure(file: file).dictionary).map {
|
||||
StyleViolation(ruleDescription: self.dynamicType.description,
|
||||
location: Location(file: file, byteOffset: $0))
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ class StringRuleTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testMissingDocs() {
|
||||
verifyRule(MissingDocsRule.description, commentDoesntViolate: false)
|
||||
verifyRule(MissingDocsRule.description)
|
||||
}
|
||||
|
||||
func testTrailingSemicolon() {
|
||||
|
||||
Reference in New Issue
Block a user