Skip to content

Commit

Permalink
improve MissingDocsRule
Browse files Browse the repository at this point in the history
by checking for documentation comment body rather than doc comment attribute
  • Loading branch information
jpsim committed Nov 21, 2015
1 parent 1fac360 commit aea6f49
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Cartfile
Original file line number Diff line number Diff line change
@@ -1 +1 @@
github "jpsim/SourceKitten" ~> 0.6.0
github "jpsim/SourceKitten" "master"
2 changes: 1 addition & 1 deletion Cartfile.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ github "jpsim/SwiftXPC" "1.1.0"
github "behrang/YamlSwift" "1.2.2"
github "jspahrsummers/xcconfigs" "0.8.1"
github "Carthage/Commandant" "0.7.0-beta.1"
github "jpsim/SourceKitten" "0.6.0"
github "jpsim/SourceKitten" "4d6f84f9048b3f4b086f15151322854298e7c4d7"
37 changes: 21 additions & 16 deletions Source/SwiftLintFramework/Rules/MissingDocsRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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, offset: $0))
}
Expand Down
2 changes: 1 addition & 1 deletion Source/SwiftLintFrameworkTests/StringRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ class StringRuleTests: XCTestCase {
}

func testMissingDocs() {
verifyRule(MissingDocsRule.description, commentDoesntViolate: false)
verifyRule(MissingDocsRule.description)
}

func testTrailingSemicolon() {
Expand Down

0 comments on commit aea6f49

Please sign in to comment.