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

Lint for missing doc-comments on public declarations #57203

Closed
zoechi opened this issue Mar 19, 2015 · 8 comments
Closed

Lint for missing doc-comments on public declarations #57203

zoechi opened this issue Mar 19, 2015 · 8 comments
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-lint-request type-enhancement A request for a change that isn't a bug

Comments

@zoechi
Copy link
Contributor

zoechi commented Mar 19, 2015

Public declarations should have a doc comment and it would be great if the linter could list missing comments.

@pq
Copy link
Member

pq commented Mar 19, 2015

👍

I've been thinking about this. I chimed in on the dartdoc issue. By public do you mean non-package private or do you mean non-package private and in lib/. (IOW: is the desired definition the same as dartdoc's take on "Public API"?)

@pq pq added type-enhancement A request for a change that isn't a bug linter-lint-request labels Mar 19, 2015
@zoechi
Copy link
Contributor Author

zoechi commented Mar 20, 2015

Ideally there would be two rules.
I'm not sure if it is easy to split.

  1. Enabled by default: everything exported by files in pkg/lib and reachable from there using public methods/getters (can include files from pkg/lib/src/**)
  2. Opt-in: everything not starting with _
    1b) An alternative for the first rule would be to check everything in lib/** not starting with _ and use configuration to exclude what's supposed to be just private implementation.

@pq
Copy link
Member

pq commented Mar 23, 2015

Regarding:

  1. Enabled by default: everything exported by files in pkg/lib and reachable from there using public methods/getters (can include files from pkg/lib/src/)
    I see the non-public members that leak into your API as a problem actually. Really there shouldn't be any. I think this should be the thrust of another lint.

All the variations are interesting actually. From my perspective maybe the best to start with would be one that aligns with what dartdoc treats as public API. In other words:

1b) An alternative for the first rule would be to check everything in lib/ not starting with _ and use configuration to exclude what's supposed to be just private implementation.

@zoechi
Copy link
Contributor Author

zoechi commented Mar 23, 2015

I'm not sure I understand 1b)
Usually in lib are dart files without actual code except one or more export src/xxx/xxx/x.dart which are the entry points of the API. If there is a getter which returns ../yyy/y.dart/SomeClass this should be documented.
I have the suspicion that the only reasonable way is to use a configuration to exclude directories if any and otherwise show a hint/warning for everything not starting with _.

@pq
Copy link
Member

pq commented Mar 24, 2015

I think there's some confusion (mine included) on what constitutes package API. My temptation is to start with a lint that is consistent with dartdoc (more on that perspective here: dart-lang/dartdoc#284). Whether we want a more strict variation down the line is an open question.

@pq
Copy link
Member

pq commented Mar 24, 2015

A stab at wording:

DO provide doc comments for all public APIs.

As described in the pub package layout doc, public APIs consist in everything in your package's lib folder, minus implementation files in lib/src, adding elements explicitly exported with an export directive.

For example, given lib/foo.dart:

export 'src/bar.dart' show Bar;
export 'src/baz.dart';

class Foo { }

class _Foo { }

it's API includes:

  • Foo (but not _Foo)
  • Bar (exported) and
  • all public elements in src/baz.dart

All public API members should be documented with /// doc-style comments.

Good:

/// A Foo.
abstract class Foo {
  /// Start foo-ing.
  void start() => _start();

  _start(); 
}

Bad:

class Bar {
  void bar();
}

Advice for writing good doc comments can be found in the Doc Writing Guidelines.

@zoechi
Copy link
Contributor Author

zoechi commented Mar 24, 2015

I think it's a proper defined set and a good starting point. I guess everything else will require a longer discussion. I hope there will be an extended lint which lists all elements not starting with _

@pq
Copy link
Member

pq commented Apr 27, 2016

This one is implemented as public_member_api_docs.

@pq pq closed this as completed Apr 27, 2016
@devoncarew devoncarew added analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. labels Nov 18, 2024
@devoncarew devoncarew transferred this issue from dart-lang/linter Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-linter Issues with the analyzer's support for the linter package area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. linter-lint-request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

3 participants