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

Optionally allow adding - returns: docs to initializers #557

Closed
mohpor opened this issue Feb 22, 2016 · 7 comments
Closed

Optionally allow adding - returns: docs to initializers #557

mohpor opened this issue Feb 22, 2016 · 7 comments
Labels

Comments

@mohpor
Copy link
Contributor

mohpor commented Feb 22, 2016

Hi,
I use VVDocumenter to help me document my codes.
init() functions return an objects, although not explicitly defined in their syntax. For this particular reason, SwiftLint-ing them complains that their documentations are invalid.

example:

 /**
   Generates the view programatically to avoid giving out informations about the alert's views.   
   - parameter frame: A frame. Will be ignored.   
   - returns: An instance of UIView.
   */
  override init(frame: CGRect) {...}

(Disclaimer: This is just an example)

Swift lint will complain and say:

warning: Valid Docs Violation: Documented declarations should be valid. (valid_docs)

Although it is perfectly valid. You might argue that we don't need to document the return part, but I have many cases that it helps clarify the resulted instance, especially in case of failable initializers.

UPDATE:
Just to be clear, removing - returns from documentation does actually solve the validation problem.

@mohpor
Copy link
Contributor Author

mohpor commented Feb 22, 2016

I'm more than happy to submit a PR but I jus don't know how to check if the kind is a constructor.

func delcarationReturns(declaration: String, kind: SwiftDeclarationKind? = nil) -> Bool {
    if let kind = kind where SwiftDeclarationKind.variableKinds().contains(kind) {
        return true
    }

    guard let outsideBracesMatch = matchOutsideBraces(declaration) else {
        return false
    }

    return outsideBracesMatch.containsString("->")
}

in ValidDocsRule.swift should return true in case kind is FunctionConstructor but no matter what, it never detects init functions as one!

To sum it up I felt pretty stupid trying to contribute to this repo. I couldn't find a way to extract function name from SourceKitten and .... (sigh)

@thebarndog
Copy link

thebarndog commented Mar 22, 2016

There's another thing it misses too:

func myFunction(closure: (firstInt: Int, secondInt: Int) throws -> Void) { 
}

If a closure argument can throw an error, valid_docs complains because - throws: isn't in the documentation. In this example though, the function itself doesn't throw, the closure parameter does.

@chadmoone
Copy link

Dupe of #439?

@Grubas7
Copy link

Grubas7 commented Jul 5, 2016

I have same issue.

@jpsim jpsim changed the title valid_docs wrongly accuses init() function documentation because of the return clause Optionally allow adding - returns: docs to initializers Jul 8, 2016
@jpsim
Copy link
Collaborator

jpsim commented Jul 8, 2016

this is a good "starter bug" if anyone is interested in contributing to SwiftLint.

@mohpor
Copy link
Contributor Author

mohpor commented Aug 2, 2016

@startupthekid

If a closure argument can throw an error, valid_docs complains because - throws: isn't in the documentation. In this example though, the function itself doesn't through, the closure parameter does.

It seems like a separate issue.
Care to open a new issue?

@jpsim
Copy link
Collaborator

jpsim commented Dec 22, 2016

Fixed in #739.

@jpsim jpsim closed this as completed Dec 22, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants