Skip to content

Comment references to unnamed constructors do not match Dart code #1850

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

Closed
jamesderlin opened this issue Nov 26, 2018 · 8 comments
Closed

Comment references to unnamed constructors do not match Dart code #1850

jamesderlin opened this issue Nov 26, 2018 · 8 comments
Labels
P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@jamesderlin
Copy link

A specific case for #1663: The Effective Dart guidelines claim:

The dot syntax can also be used to refer to named constructors. For the unnamed constructor, put parentheses after the class name:

/// To create a point, call [Point()] or use [Point.polar()] to ...

I just tested this with dartdoc 0.24.1 from the Dart 2.1 SDK, and the unnamed constructor reference doesn't seem to work; it links to the class instead.

https://github.com/dart-lang/dartdoc/wiki/dartdoc-comment-references instead says to use [MyClass.MyClass] to reference the unnamed constructor. That does work, but the generated documentation literally has MyClass.MyClass, which looks weird since that's not what anybody uses in code. Can we do one (or both) of:

  • Make [MyClass()] refer to the unnamed constructor as claimed by Effective Dart? (Or, less desirably, fix the false claim by Effective Dart.)
  • Make [MyClass.MyClass] show up as MyClass (or MyClass()) in the generated documentation?

?

The motivation for this was my attempt at removing lingering new usage in Flutter API documentation, which was used to disambiguate references to classes from references to constructors (flutter/flutter#24625).

@jcollins-g
Copy link
Contributor

The first bullet point seems reasonable, although I don't know if there are existing references looking like that that are intended to refer to the class documentation. Dartdoc strips extraneous things like "new " and "()" because it is considered rare to refer to the unnamed constructor. Usually, the class documentation is what people seem to want.

If the () notation is not widely used to refer to the class docs, then we can implement this.

@jcollins-g jcollins-g changed the title References to unnamed constructors don't work Comment references to unnamed constructors do not match Dart code Nov 26, 2018
@jcollins-g jcollins-g added type-enhancement A request for a change that isn't a bug P2 A bug or feature request we're likely to work on labels Nov 26, 2018
@jcollins-g
Copy link
Contributor

adding @kwalrath, given the report that the () does not work as advertised on Effective Dart.

@Hixie
Copy link
Contributor

Hixie commented Nov 28, 2018

We definitely want to be able to refer to constructors (including unnamed one, which we sometimes refer to e.g. from named ones, or from properties, to say "hey look at the guidance on the argument to the constructor", etc). I admit I never tested whether that worked...

@jcollins-g
Copy link
Contributor

@Hixie You can do so now (and it is done this way in parts of the docs) with [ClassName.ClassName] for the unnamed constructor and [ClassName.fooConstructor] for others. The problem as I understand it is that it isn't very darty (noone calls constructors like that) and doesn't match what we're told to do in Effective Dart.

@jamesderlin
Copy link
Author

The documentation for the comment_references lint also claims that [Class()] should work:

In particular, code references within square brackets can consist of either
...

  • a single identifier followed by a pair of parentheses where the identifier is the name of a class that is in scope (used to refer to the unnamed constructor for the class), or

@srawlins
Copy link
Member

With constructor tearoffs, the new canonical way to reference an unnamed constructor is with .new: /// [List.new].

@jamesderlin
Copy link
Author

https://github.com/dart-lang/dartdoc/wiki/dartdoc-comment-references hasn't been updated and still refers to MyClass.MyClass. Since it's part of the dartdoc wiki, I don't think I can create a pull request to change it (and I'm guessing that I can't or shouldn't push changes directly to the wiki repo).

@jamesderlin
Copy link
Author

I just tried this again (using dart 2.16.2), and all of the following now do generate references to the unnamed constructor:

  • [Foo.new]
  • [Foo.new()]
  • [Foo()]
  • [Foo.Foo]
  • [Foo.Foo()]

And in all cases, the string within the square brackets is shown verbatim in the generated documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

4 participants