Skip to content

Commit dbac532

Browse files
committed
formatting
1 parent 9baaa91 commit dbac532

File tree

1 file changed

+3
-50
lines changed

1 file changed

+3
-50
lines changed

doc/dart_documentation_comment_specification.md

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ Version: 1.0.0
99

1010
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.
1111

12-
###
13-
1412
### **1.2. Scope**
1513

1614
**In Scope**
@@ -22,18 +20,15 @@ This specification covers the following topics:
2220
* The mechanism for *resolving* references between elements.
2321
* The logic for *associating* documentation with code elements.
2422

25-
###
26-
2723
**Out of Scope**
2824

2925
This document does not cover:
3026

31-
* The implementation details of specific documentation tools (e.g., `dartdoc`).
27+
* The implementation details of specific documentation tools (e.g., `dartdoc`, `analysis server`).
3228
* The syntax and behavior of tool-specific directives (e.g., `@template`, `@canonicalFor`).
3329
* Any details related to the visual styling or HTML layout of generated documentation.
3430
* Best practices or style guides for writing effective documentation content.
3531

36-
3732
### **1.3. Terminology**
3833

3934
* **Doc Comment:** A comment intended to be processed by documentation generation tools, like dartdoc.
@@ -49,8 +44,6 @@ This document does not cover:
4944
* Starts with `///`.
5045
* All consecutive lines starting with `///` are treated as part of the same comment block.
5146

52-
###
53-
5447
### **2.2. Block-Based Doc Comments (Historic, not recommended)**
5548

5649
* Starts with `/**` and ends with the matching `*/`.
@@ -67,8 +60,6 @@ This document does not cover:
6760
*/
6861
```
6962

70-
###
71-
7263
### **2.3. Content Format (Markdown)**
7364

7465
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
7970

8071
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.
8172

82-
##
83-
8473
## **3\. Placement of Documentation Comments**
8574

8675
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.
8978

9079
* `library` directives.
9180

92-
###
93-
9481
### **3.2. Top-Level Declarations**
9582

9683
* `class`
@@ -111,8 +98,6 @@ Doc comments are associated with the declaration that immediately follows them.
11198
* Fields (instance, static)
11299
* Getters or setters (Not both, prefer getter)
113100

114-
###
115-
116101
### **3.4. Enum Constants**
117102

118103
* 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.
121106

122107
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.
123108

124-
##
125-
126109
## **4\. Referenceable Elements**
127110

128111
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:
129112

130-
###
131-
132113
### **4.1. Types**
133114

134115
* Classes (e.g., `[MyClass]`)
@@ -138,8 +119,6 @@ A reference in a doc comment (e.g., `[name]`) can link to any Dart element that
138119
* Extension types (e.g., `[MyExtensionType]`)
139120
* Type aliases (Typedefs) (e.g., `[MyTypedef]`)
140121

141-
###
142-
143122
### **4.2. Top-Level Declarations:**
144123

145124
* Functions (e.g., `[myTopLevelFunction]`)
@@ -153,13 +132,11 @@ A reference in a doc comment (e.g., `[name]`) can link to any Dart element that
153132
* Constructors (e.g., `[MyClass.new]`, `[MyClass.named]`, `[MyClass.named()]`)
154133
* Enum constants (e.g., `[MyEnum.value]`)
155134

156-
**4.4. Local Scope Parameters (within a member's doc comment):**
135+
### **4.4. Local Scope Parameters (within a member's doc comment):**
157136

158137
* Parameters of the documented method/function (e.g., `[parameterName]`)
159138
* Type parameters of the documented element (e.g., `[T]`)
160139

161-
##
162-
163140
## **5\. Reference Lookup and Resolution**
164141

165142
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
174151

175152
### **5.2. Scope Precedence Hierarchy**
176153

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).
178155

179156
The hierarchy is searched from the inside out. Below is an example for an instance method:
180157
```
@@ -201,8 +178,6 @@ The hierarchy is searched from the inside out. Below is an example for an instan
201178
+--------------------------------------------------------------------------+
202179
203180
```
204-
###
205-
206181
### **5.3. Detailed Lookup Process**
207182

208183
The lookup process begins at a specific "starting scope" determined by the context of the doc comment and then follows the scope hierarchy.
@@ -252,7 +227,6 @@ class MyClass<T> {
252227
}
253228
254229
```
255-
####
256230

257231
#### **5.3.2. Instance Fields**
258232

@@ -266,16 +240,12 @@ A top-level function operates like a method but without any enclosing class-like
266240

267241
* **Starting Scope**: Formal Parameter Scope
268242

269-
####
270-
271243
#### **5.3.4. Top-Level Variables**
272244

273245
For top-level variables, the search has no local context and must begin at the file's library scope.
274246

275247
* **Starting Scope**: Library Scope
276248

277-
####
278-
279249
#### **5.3.5. Top-Level Declarations**
280250

281251
For doc comments placed directly on classes, enums, mixins, extensions, extension types.
@@ -321,7 +291,6 @@ class MyClass<T> {
321291
}
322292
323293
```
324-
####
325294

326295
#### **5.3.6. Typedefs**
327296

@@ -333,7 +302,6 @@ The starting scope for a typedef doc comment depends on what it is an alias for.
333302
| Record Type | Record fields scope |
334303
| All Other Types | Typedef type parameter scope |
335304

336-
####
337305
**Example**
338306

339307
```
@@ -373,17 +341,12 @@ typedef void MyTypedef<T>(int p);
373341
typedef F<T> = void Function(void Function<S>(void Function(T p)) fun);
374342
```
375343

376-
377-
####
378-
379344
**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.
380345

381346
### **5.4. Resolving Qualified Names**
382347

383348
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.
384349

385-
####
386-
387350
#### **1\. Resolve the First Identifier**
388351

389352
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 **"
394357

395358
The namespace available depends on the type of element the previous identifier resolved to. Below are the primary cases.
396359

397-
###
398-
399360
**Namespace-Providing Elements**
400361

401362
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
406367
* **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.
407368
* **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.
408369

409-
###
410-
411370
*Case 2: Class-like top-level declaration*
412371

413372
* **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
423382
* The identifier BoolList resolves to a class element within the collection library's public namespace.
424383
* The identifier empty resolves to a named constructor element within the BoolList class's member namespace.
425384

426-
###
427-
428385
**Leaf Elements (Empty Namespace)**
429386

430387
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.
431388

432-
###
433-
434389
*Case 3: Function, or Method*
435390

436391
* **Namespace**: Empty.
@@ -445,8 +400,6 @@ The following elements are "leaf" nodes. If an Identifier resolves to one of the
445400
* **Explanation:** These elements are also "leaf" nodes. They represent values and do not have their own member namespaces.
446401
* **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.
447402

448-
###
449-
450403
*Case 5: Type Parameter*
451404

452405
* **Namespace:** Empty.

0 commit comments

Comments
 (0)