-
Notifications
You must be signed in to change notification settings - Fork 119
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
Parameters shadow properties in dartdocs (lots of broken links in Flutter docs as a result) #1486
Comments
The scoping change to arguments is fairly recent (around the time of canonicalization) in order to reduce warnings, as I recall there were many places which had arguments referenced in square brackets. We could alter the scoping rules to only consider arguments if other possibilities fail, reducing their priority in the lookup order. |
Sounds reasonable. For Flutter we have the convention that square brackets shouldn't be used for arguments at all, though I understand this isn't the case for other projects so it may be impractical to implement that uniformly. |
Today, when there's is a name conflict between a field and a parameter. There is a way to resolve it: class Foo {
int foo;
/// [foo] points to the parameter.
/// [Foo.foo] points to the field.
void bar(int foo) {}
} If we change scoping rules, we should also update the way such conflicts are resolved. |
I would just remove the I would strongly discourage using |
Since there's nothing to link to for an argument, providing a way to resolve the conflict so you don't link to something seems like a lower priority to me? After all, if you don't want a link, you'd just not put one there... Removing the I think what I'm leaning toward is to make the warning system more granular so we can enable and disable specific warnings and implement this by reducing the priority in the parser. |
@jcollins-g What would the warning system produce in the example above? |
Yeah I'm totally fine with [foo] linking to the argument if there's nothing else it could plausibly link to. Yegor on a thread internally has been arguing that he wants a way to unambiguously link to arguments even if the arguments clash with a property name, hence my suggestion for a separate syntax. But that's not a high priority for me personally. |
Expanded the example slightly for clarity. For completeness, current behavior:
If support for argument linking is removed entirely:
If argument linking is deprioritized:
|
FWIW, either of the latter two sounds good to me. |
Neither of the options offer conflict resolution, which is a regression from the status quo. However, if #1259 is fixed first, then this would not be an issue. |
#1259 will require sdk #27570 first, so that's not likely to happen quickly. Ideally dartdoc and analyzer would have the same idea about what's going on here, with dartdoc inheriting knowledge about that from the analyzer. If there's not a clearly awesome choice here, it might be better to put off trying to hack this up in dartdoc. |
If I understand correctly, the two issues are unrelated. dart-lang/sdk#27570 is about allowing putting However, now that I think of #1259, I don't think it would completely eliminate the issue. Sometimes you want to refer to multiple parameters in one sentence. #1259 is only about documenting one parameter at a time. Of course, the chance of name conflict is smaller in this situation, it does remove the reliability of the feature. I want to be able to trust dartdoc links 100%, just like I trust Dart's lexical scoping rules. Example: /// Adds [a] and [b], and divides the result by `2.0`.
average(double a, double b) => (a + b) / 2.0; Even with #1259 fixed, I'd still want to be able to refer from the dartdoc of one parameter to another parameter. Example: /// Computes the average of two numbers.
average(
/// Added to [b].
double a,
/// Added to [a].
double b,
) => (a + b) / 2.0; |
+1000. I'd love to see dartdocs become part of the language and understood by all static analysis tools (code search, navigation, language-aware code highlighting, refactoring, formatting, etc, etc) |
Please don't let the perfect become the enemy of the good. What matters with dartdoc is that the documentation on the Web site be optimal for our developers. That's a completely separate problem from whatever the analyzer does. We already have completely different resolution rules (for example the analyzer doesn't know what's in scope for dartdocs), this is a minor issue compared to that. If given the choice between "regressing" what dartdoc internally thinks |
I generally concur with @Hixie in that the regression is the least bad option on the table right now. |
Right back at you. What we did is invent our own Flutter-specific dartdoc syntax and now asking the dartdoc tool to change so it works for us. This will make all of non-Flutter dartdocs, some of which we're re-exporting on docs.flutter.io, incompatible with our internal dartdocs.
I think your logic is broken. The reason our links are broken is because we're not using the syntax and semantics we're given. Had we used it according to the current semantics, we wouldn't have broken links. Maybe the syntax is not ideal for us readability-wise, so sure, let's file feature requests (e.g. I think |
@yjbanov To be fair, we've already taken semantics developers made up in the doc comments and changed dartdoc to make them work (for Flutter, the Dart SDK, and Angular). Indeed, at one point during the canonicalization and warning cleanup hackfest I went through every single warning in all three checking for semantics that were made up and implemented high-value ones that seemed reasonable to me, where they didn't introduce regressions that were worse than the original missing/broken links. It's a little excessively bottom-up, but because I had really little direct user feedback on how users would prefer dartdoc to operate I treated violations of existing semantics as feature requests.(*) So I don't think it's a completely unreasonable thing to do if it generally improves the docs. If the preferred outcome is (*) - IMO, until dartdoc's warnings are locked down far enough to be reliably paid attention to by engineers, some level of bottom-up feature request inference is going to be part of the mix in dartdoc. |
There's quite a bit of |
I'm slightly favoring the |
To be clear, the
It does not require fixing the following:
|
I think our docs would be substantially harder to read if you had to write |
I can't imagine that
|
The dartdocs are frequently read in the raw form, so the syntax matters. I disagree that switching between Let's just have a dedicated syntax for the case where you want to refer to the arguments and not the properties. Maybe that can be |
Sorry to revive this old issue, but I encountered something that this affects: refactoring in the IDE. If I rename a parameter that uses I'd be in favor of the deprioritized argument linking proposed above, since it matches what the IDEs already do. In combination with #3149, which I just filed, this should disambiguate references on the API docs pages, since plain parameters would not be linked, and constructor parameters that were also fields would still be linked. |
You can't rely on the refactoring tool to correct the documentation anyway. For example, you have to make sure you go through and correct |
Yes, of course you still have to proof the result, but it helps reduce the chance of errors quite a lot. |
I find I get fewer errors using global search, auditing every match for the string being renamed, than from refactoring tools (since with the latter I'm too tempted to avoid doing the global search as well, and only review code near where the changes happened, which may not include all the references in prose). But YMMV. |
The
Opacity
constructor looks like this:Our goal in writing this was that the constructor docs would link to the
opacity
field's page. Instead, it doesn't link anywhere.It would be much nicer if arguments were not considered "in scope" for
[...]
links, since they don't actually have their own page to link to, so it doesn't really do any good to link to them.Technically in the Flutter docs this manifests as "Broken links, widespread", but I guess it's really a mistake on our part (we didn't understand that arguments would be considered "in scope" and would thus prevent the links from working) so it's also "Enhancements considered important but without significant data indicating they are a big win" and I've marked it P2.
The text was updated successfully, but these errors were encountered: