You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: doc/dart_documentation_comment_specification.md
+3-50Lines changed: 3 additions & 50 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,8 +9,6 @@ Version: 1.0.0
9
9
10
10
The purpose of this document is to provide a single specification for documentation comments in the Dart programming language. Its goal is to ensure that documentation is parsed consistently by all tools and to serve as a definitive standard for developers and tool authors.
11
11
12
-
###
13
-
14
12
### **1.2. Scope**
15
13
16
14
**In Scope**
@@ -22,18 +20,15 @@ This specification covers the following topics:
22
20
* The mechanism for *resolving* references between elements.
23
21
* The logic for *associating* documentation with code elements.
24
22
25
-
###
26
-
27
23
**Out of Scope**
28
24
29
25
This document does not cover:
30
26
31
-
* The implementation details of specific documentation tools (e.g., `dartdoc`).
27
+
* The implementation details of specific documentation tools (e.g., `dartdoc`, `analysis server`).
32
28
* The syntax and behavior of tool-specific directives (e.g., `@template`, `@canonicalFor`).
33
29
* Any details related to the visual styling or HTML layout of generated documentation.
34
30
* Best practices or style guides for writing effective documentation content.
35
31
36
-
37
32
### **1.3. Terminology**
38
33
39
34
***Doc Comment:** A comment intended to be processed by documentation generation tools, like dartdoc.
@@ -49,8 +44,6 @@ This document does not cover:
49
44
* Starts with `///`.
50
45
* All consecutive lines starting with `///` are treated as part of the same comment block.
51
46
52
-
###
53
-
54
47
### **2.2. Block-Based Doc Comments (Historic, not recommended)**
55
48
56
49
* Starts with `/**` and ends with the matching `*/`.
@@ -67,8 +60,6 @@ This document does not cover:
67
60
*/
68
61
```
69
62
70
-
###
71
-
72
63
### **2.3. Content Format (Markdown)**
73
64
74
65
The text within a documentation comment block is parsed as Markdown, allowing for rich text formatting. This includes headings, lists, code blocks, and emphasis, which are converted for instance to HTML in the generated documentation.
@@ -79,8 +70,6 @@ A reference is a special directive within the Markdown content that creates a hy
79
70
80
71
Conceptually, these behave like [reference-style links](https://www.markdownguide.org/basic-syntax/#reference-style-links) in Markdown. The documentation generator resolves the name against the available source code to create the link's destination. See [Section 5](#5.-reference-lookup-and-resolution) for detailed resolution rules.
81
72
82
-
##
83
-
84
73
## **3\. Placement of Documentation Comments**
85
74
86
75
Doc comments are associated with the declaration that immediately follows them. They are only considered valid when placed directly before the following types of declarations:
@@ -89,8 +78,6 @@ Doc comments are associated with the declaration that immediately follows them.
89
78
90
79
*`library` directives.
91
80
92
-
###
93
-
94
81
### **3.2. Top-Level Declarations**
95
82
96
83
*`class`
@@ -111,8 +98,6 @@ Doc comments are associated with the declaration that immediately follows them.
111
98
* Fields (instance, static)
112
99
* Getters or setters (Not both, prefer getter)
113
100
114
-
###
115
-
116
101
### **3.4. Enum Constants**
117
102
118
103
* A doc comment can be placed before an individual enum value.
@@ -121,14 +106,10 @@ Doc comments are associated with the declaration that immediately follows them.
121
106
122
107
While not strictly disallowed by the language, any other placement of a comment with the /// syntax, is not considered a doc comment, and hence should be ignored by documentation tools.
123
108
124
-
##
125
-
126
109
## **4\. Referenceable Elements**
127
110
128
111
A reference in a doc comment (e.g., `[name]`) can link to any Dart element that is visible from the Dart scope of the documented element. See [Section 5](#5.-reference-lookup-and-resolution) for more details about scoping. This includes:
129
112
130
-
###
131
-
132
113
### **4.1. Types**
133
114
134
115
* Classes (e.g., `[MyClass]`)
@@ -138,8 +119,6 @@ A reference in a doc comment (e.g., `[name]`) can link to any Dart element that
138
119
* Extension types (e.g., `[MyExtensionType]`)
139
120
* Type aliases (Typedefs) (e.g., `[MyTypedef]`)
140
121
141
-
###
142
-
143
122
### **4.2. Top-Level Declarations:**
144
123
145
124
* Functions (e.g., `[myTopLevelFunction]`)
@@ -153,13 +132,11 @@ A reference in a doc comment (e.g., `[name]`) can link to any Dart element that
**4.4. Local Scope Parameters (within a member's doc comment):**
135
+
### **4.4. Local Scope Parameters (within a member's doc comment):**
157
136
158
137
* Parameters of the documented method/function (e.g., `[parameterName]`)
159
138
* Type parameters of the documented element (e.g., `[T]`)
160
139
161
-
##
162
-
163
140
## **5\. Reference Lookup and Resolution**
164
141
165
142
When a name is enclosed in square brackets (e.g., `[MyClass.myMethod]`), documentation tools attempt to resolve it to a specific API member. This section details the principles of that resolution process, the scope hierarchy it follows, and how to handle special cases.
@@ -174,7 +151,7 @@ When a name is enclosed in square brackets (e.g., `[MyClass.myMethod]`), documen
174
151
175
152
### **5.2. Scope Precedence Hierarchy**
176
153
177
-
The resolution process for a reference \[name\] follows the standard Dart scope of the documented element with the extension of the doc imported scope at the end. Search is done in a specific order of precedence from the narrowest (most local) scope to the broadest (globally available).
154
+
The resolution process for a reference `[name]` follows the standard Dart scope of the documented element with the extension of the doc imported scope at the end. Search is done in a specific order of precedence from the narrowest (most local) scope to the broadest (globally available).
178
155
179
156
The hierarchy is searched from the inside out. Below is an example for an instance method:
180
157
```
@@ -201,8 +178,6 @@ The hierarchy is searched from the inside out. Below is an example for an instan
**Note on Nested Scopes:** The lookup only applies to the *immediate* parameters or fields of the typedef. It does not extend into parameters of nested function types.
380
345
381
346
### **5.4. Resolving Qualified Names**
382
347
383
348
When a reference contains a qualified name (e.g., `[prefix.ClassName.member]`), the resolution process is an iterative, left-to-right evaluation of each Identifier.
384
349
385
-
####
386
-
387
350
#### **1\. Resolve the First Identifier**
388
351
389
352
The tool first resolves the first identifier in the qualified name (e.g., prefix) using the standard lookup process ([Section 5.3](#5.3.-detailed-lookup-process)), starting from the doc comment's current scope.
@@ -394,8 +357,6 @@ Once an identifier is resolved, the element it resolves to establishes a new **"
394
357
395
358
The namespace available depends on the type of element the previous identifier resolved to. Below are the primary cases.
396
359
397
-
###
398
-
399
360
**Namespace-Providing Elements**
400
361
401
362
If an Identifier resolves to one of the following elements, it establishes a new namespace for resolving the next identifier in the chain.
@@ -406,8 +367,6 @@ If an Identifier resolves to one of the following elements, it establishes a new
406
367
***Example:** In `[math.pi]`, the identifier `math` resolves to an import prefix (e.g., from `import dart:math' as math;`). The tool then searches the public namespace of dart:math for the identifier pi.
407
368
***Combinator Example:** If the import was import 'dart:math' as math show sin;, the namespace for math would *only* contain sin. A reference to `[math.pi]` would fail to resolve, as `pi` was not included in the show list.
408
369
409
-
###
410
-
411
370
*Case 2: Class-like top-level declaration*
412
371
413
372
***Namespace:** The set of all members declared within that element, including:
@@ -423,14 +382,10 @@ If an Identifier resolves to one of the following elements, it establishes a new
423
382
* The identifier BoolList resolves to a class element within the collection library's public namespace.
424
383
* The identifier empty resolves to a named constructor element within the BoolList class's member namespace.
425
384
426
-
###
427
-
428
385
**Leaf Elements (Empty Namespace)**
429
386
430
387
The following elements are "leaf" nodes. If an Identifier resolves to one of these, it provides no further namespace, and the chain of resolution must end.
431
388
432
-
###
433
-
434
389
*Case 3: Function, or Method*
435
390
436
391
***Namespace**: Empty.
@@ -445,8 +400,6 @@ The following elements are "leaf" nodes. If an Identifier resolves to one of the
445
400
***Explanation:** These elements are also "leaf" nodes. They represent values and do not have their own member namespaces.
446
401
***Example**: If `myField` is a class field, a Reference like `[myField.something]` is invalid. Similarly, if `param` is a method parameter, `[param.something]` is also invalid.
0 commit comments