Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed returns doc for init methods issue-557 #739

Merged
merged 1 commit into from
Aug 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@

* Adds 'ConditionalReturnsOnNewLineRule' rule.
[Rohan Dhaimade](https://github.com/HaloZero)

* Made `- returns:` doc optional for initializers.
[Mohpor](https://github.com/mohpor)
[#557](https://github.com/realm/SwiftLint/issues/557)

##### Bug Fixes

Expand Down
13 changes: 12 additions & 1 deletion Source/SwiftLintFramework/Rules/ValidDocsRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func declarationReturns(declaration: String, kind: SwiftDeclarationKind? = nil)
guard let outsideBracesMatch = matchOutsideBraces(declaration) else {
return false
}

return outsideBracesMatch.containsString("->")
}

Expand All @@ -66,6 +65,12 @@ func matchOutsideBraces(declaration: String) -> NSString? {
return NSString(string: declaration).substringWithRange(outsideBracesMatch.range)
}

func declarationIsInitializer(declaration: String) -> Bool {
return !regex("^((.+)?\\s+)?init\\?*\\(.*\\)")
.matchesInString(declaration, options: [],
range: NSRange(location: 0, length: declaration.characters.count)).isEmpty
}

func commentHasBatchedParameters(comment: String) -> Bool {
return comment.lowercaseString.containsString("- parameters:")
}
Expand All @@ -76,11 +81,17 @@ func commentReturns(comment: String) -> Bool {
}

func missingReturnDocumentation(declaration: String, comment: String) -> Bool {
guard !declarationIsInitializer(declaration) else {
return false
}
return declarationReturns(declaration) && !commentReturns(comment)
}

func superfluousReturnDocumentation(declaration: String, comment: String,
kind: SwiftDeclarationKind) -> Bool {
guard !declarationIsInitializer(declaration) else {
return false
}
return !declarationReturns(declaration, kind: kind) && commentReturns(comment)
}

Expand Down