Dart has a dartdoc documentation syntax with {@template}
and {@macro}
. I was wondering if there was a naming convention for it.
In the doc, they only give the {@template template_name}
example which is in snake_case
.
For now, I'm naming my templates like this:
{@template project_name.class_name.method_name}
(snake_case
separated with .
).
For example for the project project_name
:
File class_name.dart
/// {@template project_name.class_name}
/// ...
/// {@endtemplate}
class ClassName {
/// {@template project_name.class_name.method_name}
/// ...
/// {@endtemplate}
void methodName() {}
}
I was wondering if there was already some conventions for those template names?
It looks like there is no proper naming convention for naming macros. However, the Flutter team recommends flutter.library.Class.member[.optionalDescription]
:
See this documentation.
Dartdoc supports creating templates that can be reused in other parts of the code. They are defined like so:
/// {@template <id>} /// ... /// {@endtemplate}
and used via:
/// {@macro <id>}
The
<id>
should be a unique identifier that is of the formflutter.library.Class.member[.optionalDescription]
.For example:
// GOOD: /// {@template flutter.rendering.Layer.findAnnotations.aboutAnnotations} /// Annotations are great! /// {@endtemplate // BAD: /// {@template the_stuff!} /// This is some great stuff! /// {@endtemplate}
The
optionalDescription
component of the identifier is only necessary if there is more than one template defined in one Dartdoc block. If a symbol is not part of a library, or not part of a class, then just omit those parts from the ID.