@@ -461,22 +461,48 @@ further ideas for additional warnings, lints, and quick fixes.
461
461
462
462
### API documentation generation
463
463
464
- Authors documenting an API that uses this feature should refer to the
465
- constructor parameter by its public name since that's what users will pass.
466
- Likewise, doc generators like [ ` dart doc ` ] [ dartdoc ] should document the
467
- constructor's parameter with its public name. The fact that the parameter
468
- initializes or declares a private field is an implementation detail of the
469
- class. What a user of the class cares about is the corresponding public name for
470
- the constructor parameter.
464
+ The reason a parameter has a private name is only a convenience for the
465
+ maintainer of that constructor so that they can use an initializing formal or
466
+ declaring parameter. A * user* of that constructor doesn't care about that
467
+ implementation detail.
468
+
469
+ Therefore, generated documentation from tools like [ ` dart doc ` ] [ ] and in-IDE
470
+ contextual help should show the public names for parameters. For named
471
+ parameters, the public name is what users must write for the corresponding named
472
+ argument. Even for positional parameters, the name is what matters, and not that
473
+ it happens to correspond to a private field.
471
474
472
475
[ dartdoc ] : https://dart.dev/tools/dart-doc
473
476
474
- The language already allows a * positional* parameter to have a private name
475
- since doing so has no effect on call sites. Doc generators are encouraged to
476
- also show the public name for those parameters in generated docs too. The fact
477
- that the positional parameter happens to initialize or declare a private field
478
- is again an implementation detail that shouldn't appear in the API or
479
- documentation.
477
+ When writing a doc comment that refers to a private named parameter, the
478
+ reference should be the private name. That's the name that is actually in scope
479
+ where the doc comment is resolved. But, as with the constructor's signature, doc
480
+ generators are encouraged to remove the ` _ ` and show the public name for that
481
+ reference.
482
+
483
+ For example, given some code like:
484
+
485
+ ``` dart
486
+ class C {
487
+ final int _positional;
488
+ final int _named;
489
+
490
+ /// Creates a new instance initialized from [_positional] and [_named].
491
+ C(this._positional, {this._named});
492
+ }
493
+ ```
494
+
495
+ Ideally, the generated documentation for the constructor would look something
496
+ like:
497
+
498
+ > ### C(int positional, {int named})
499
+ >
500
+ > Creates a new instance initialized from ` positional ` and ` named ` .
501
+
502
+ Or, put another way, if a class maintainer changes a parameter with a public
503
+ name to instead have a private name in order to take advantage of an
504
+ initializing formal or declaring parameter, then the generated documentation
505
+ should not change.
480
506
481
507
### Lint and quick fix to use private named parameter
482
508
0 commit comments