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

Rule Request: Require Docstrings #3195

Closed
2 tasks done
grantneufeld opened this issue May 3, 2020 · 3 comments
Closed
2 tasks done

Rule Request: Require Docstrings #3195

grantneufeld opened this issue May 3, 2020 · 3 comments
Labels

Comments

@grantneufeld
Copy link

New Issue Checklist

New rule request

require-docstrings (e.g., /// Documentation comment) before functions, classes/enums/structs, protocols, and class/enum/struct variables.

  1. Why should this rule be added?

Enforce inclusion of documenting comments.

  1. Provide several examples of what would and wouldn't trigger violations.

Invalid:

prototype MyPrototype {}
class MyClass {
  var myVar: Int
  let myConst = "a constant"
  func myFunc() {}
}
struct MyStruct {}
enum MyEnum {
  case myCase
}

Valid:

/// This prototype…
prototype MyPrototype {}
/// A class to…
class MyClass {
  /// Tracks…
  var myVar: Int
  /// The text for…
  let myConst = "a constant"
  /// Do…
  func myFunc() {
    var ignore: Int // no need to document inside a function
  }
}
/// A struct to…
struct MyStruct {}
/// An enum to…
enum MyEnum {
  case myCase
}
  1. Should the rule be configurable, if so what parameters should be configurable?

The rule should be configurable:

  • access-levels (members of public, internal, fileprivate, private); default; public & internal.
  • entity-types [class,function,prototype,variable]; default: all.
  1. Should the rule be opt-in or enabled by default? Why?

Opt-in. Because lots of folks prefer not to include documentation comments.

@marcelofabri
Copy link
Collaborator

Isn't this the same as https://realm.github.io/SwiftLint/missing_docs.html?

@grantneufeld
Copy link
Author

Isn't this the same as https://realm.github.io/SwiftLint/missing_docs.html?

Oh, somewhat.

Turns out that I do have missing_docs active in my .swiftlint.yml file (along with various other opt_in_rules: that are working), but it is failing to generate warnings on my code that is missing docs.

Part of the problem is that missing_docs only checks public code for missing docs, but as I suggested above, I also need it for other access-levels (internal, etc.).

After some experimentation, I’ve found that missing_docs also ignores any cases where inheritance or a protocol is applied to a class/enum/struct. public struct Example {} gets a warning, but public struct Example: View {} does not. It seems that that, and the public requirement, are why I wasn’t seeing any warnings.

So, it seems that this issue is really 3 somewhat separate things:

  • Bug report for missing_docs excluding enums/classes/structs that use inheritance or protocols.
  • Feature request for options on missing_docs to include more access levels than just public.
  • Feature request for options on missing_docs to constrain which entities are checked for missing docs (class, enum, struct, prototype, function, variable, let constants).

@stale
Copy link

stale bot commented Dec 23, 2020

This issue has been automatically marked as stale because it has not had any recent activity. Please comment to prevent this issue from being closed. Thank you for your contributions!

@stale stale bot added the wontfix label Dec 23, 2020
@stale stale bot closed this as completed Dec 30, 2020
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

2 participants