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 to prefer providing type annotations on public APIs (Style Guide). #57170

Closed
pq opened this issue Feb 11, 2015 · 5 comments
Closed

Lint to prefer providing type annotations on public APIs (Style Guide). #57170

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

Comments

@pq
Copy link
Member

pq commented Feb 11, 2015

From effective dart:

DO type annotate public APIs.

Type annotations are important documentation for how a library should be used.
Annotating the parameter and return types of public methods and functions helps
users understand what the API expects and what it provides.

Note that if a public API accepts a range of values that Dart's type system
cannot express, then it is acceptable to leave that untyped. In that case, the
implicit dynamic is the correct type for the API.

For code internal to a library (either private, or things like nested functions)
annotate where you feel it helps, but don't feel that you must provide them.

BAD:

install(id, destination) {
  // ...
}

Here, it's unclear what id is. A string? And what is destination? A string
or a File object? Is this method synchronous or asynchronous?

GOOD:

Future<bool> install(PackageId id, String destination) {
  // ...
}

With types, all of this is clarified.

@pq pq added the type-enhancement A request for a change that isn't a bug label Feb 11, 2015
@seaneagan
Copy link

Until dart gets union types, I think there will be a lot of false positives with this one.

@pq
Copy link
Member Author

pq commented Feb 11, 2015

@seaneagan : you may well be right. The interesting thing will be gathering some hard data. You'll notice too that Bob flagged this as PREFER. I'm guessing, in general, those will be hard to get crisp agreement on.

There's also the question of what constitutes privacy. In my case I really dislike using underscores everywhere and have lots of "public" code that is actually private since it never gets exported.

Net-net: turning this on by default (without a bunch of fine tuning or configurability) will be contentious for sure!

@pq
Copy link
Member Author

pq commented Mar 24, 2015

Conversation related to what constitutes public API from dartdoc's perspective over here: dart-lang/dartdoc#284.

@pq
Copy link
Member Author

pq commented Nov 5, 2015

Updated text with new reference to effective dart.

pq referenced this issue in dart-lang/linter Nov 5, 2015
* Implements #24.
* Tweaks the rule boilerplate generator.

BUG=
[email protected]

Review URL: https://codereview.chromium.org//1407283008 .
@pq
Copy link
Member Author

pq commented Nov 5, 2015

Implemented w/ 4b2af08.

@pq pq closed this as completed Nov 5, 2015
@devoncarew devoncarew added devexp-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
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. devexp-linter Issues with the analyzer's support for the linter package linter-lint-request type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants