1
1
# Getting Started
2
2
3
- Assuming that you've installed the ` documentation ` application (` npm install -g documentation ` if you haven't), how do you
4
- get started actually using it to document your code?
3
+ ` documentation ` is a ** documentation generator** . It's used to generates documentation from
4
+ comments _ within your code_ . ` documentation ` processes JavaScript comments
5
+ in the JSDoc format.
5
6
6
- Traditionally you might write documentation by creating a new Markdown
7
- file and typing in each function name and argument. Or you might not
8
- write documentation at all.
7
+ ** But don't worry! Even though it's embedded in your code, JSDoc is not code. It's a simple and standard
8
+ syntax for writing documentation. You don't need to be a developer to use it.**
9
9
10
- ` documentation ` is a ** documentation generator** , which means that it expects
11
- you to document your code _ within the code_ : special JavaScript comments
12
- in a format called JSDoc define what ends up in the docs.
10
+ Before you continue, make sure ` documentation ` is on your system (do ` npm install -g documentation ` , if not installed).
13
11
14
- ** But don't worry! Even though it's next to code, JSDoc is a simple and standard
15
- syntax that you can learn even if you aren't a full-time JavaScript developer.**
16
-
17
- Let's dive in.
12
+ Now, let's dive in.
18
13
19
14
## The Essentials
20
15
@@ -34,8 +29,9 @@ function addOne(input) {
34
29
```
35
30
36
31
The comment before the ` addOne ` function is a JSDoc comment. Note that it
37
- begins with ` /** ` instead of ` /* ` . JSDoc requires this: if you were
38
- to write a comment like
32
+ begins with ` /** ` instead of ` /* ` . JSDoc requires this.
33
+
34
+ If you were to write a comment like
39
35
40
36
``` js
41
37
// --- INVALID - this is ignored by JSDOC ---
@@ -44,76 +40,89 @@ to write a comment like
44
40
// @returns {number} that number, plus one.
45
41
```
46
42
47
- It would be ignored by JSDoc because it uses ` // ` syntax instead of ` /** ` .
43
+ the comment would be ignored by ` documentation ` because it uses ` // ` syntax instead of ` /** ` .
44
+ It's not valid JSDoc syntax.
48
45
49
- Okay: so let 's break down that example into lines :
46
+ Let 's break down the earlier JSDoc example :
50
47
51
48
``` js
52
49
/**
53
50
* This function adds one to its input.
54
51
* ...
55
52
```
56
53
57
- The first line of the comment is typically the _description_. This part
58
- says _what the thing is or does_, within the space of a few sentences .
54
+ The first line of the comment is typically the _description_. This section
55
+ says _what the code is or does_.
59
56
60
57
```js
61
58
* @param {number} input any number
62
59
```
63
60
64
- The second line is a little more complex. The parts are
61
+ On the second line:
65
62
66
- * `@param ` is **a tag**: there are many tags, and
67
- they all begin with the `@` symbol.
68
- * `{number}` is **a type**. It says that the input to this function needs
69
- to be a JavaScript "number" type. It could also say string, like `{string}`,
63
+ * `@param ` is **a tag**: This tag indicates that we'll be documenting a function's parameter.
64
+ * `{number}` is **a type**. It says that the input to this function is
65
+ a JavaScript "number". It could also say `{string}`,
70
66
`{Object}`, `{Date}`, or any other JavaScript built-in type. And if you
71
67
defined a custom class, like `FooClass`, you can use it as a type too by
72
68
saying `{FooClass}`.
73
69
* `input` is the name of the input variable. It matches what the code
74
70
says right below it (`function addOne(input)`).
75
71
* `any number` is the description of the input.
76
72
77
- And then you see the next line: it's very similar to `@param `, but just a little
78
- different: `@returns ` instead of `@param `, and since returned values in JavaScript
79
- don't have names, it just says the description of the value.
73
+ On the third line, there's `@returns `. JavaScript returned values
74
+ don't have names, so we just have a description of the value.
80
75
81
76
## Optional Parameters
82
77
83
- Sometimes libraries allow you to omit a parameter. Documentation should
84
- make this clear, and luckily there's a syntax that describes it :
78
+ Sometimes functions allow you to omit a parameter.
79
+ This is the syntax that describes an optional parameter :
85
80
86
81
```js
87
82
* @param {number} [input= 5 ] any number
88
83
```
89
84
90
- This means that the number can be omitted, and if it is, it'll default
91
- to 5.
85
+ If an input is omitted, the default value of 5 will be passed to the function.
86
+
87
+ ## What `documentation` does, so you don't have to
88
+
89
+ `documentation` does some minor magic to auto-generate documentation. Unless
90
+ you want to read the code for yourself, here's a summary of its magic:
91
+
92
+ **Inference**: JSDoc lets you specify absolutely everything about your code:
93
+ use @name to say what something is called, @kind for whether it's a function
94
+ or a class, @param for its parameters, and so on. But writing all of that
95
+ explicitly is tedious, so where it can, `documentation` automatically
96
+ populates @name , @kind , and @memberof tags based on its reading of the
97
+ code.
98
+
99
+ **Normalization**: JSDoc has multiple words for the same thing: you can
100
+ say @augments or @extends and they'll do the same thing.
92
101
93
102
## Development Process
94
103
95
- If you're actively contributing documentation to a big project, there
104
+ If you're contributing documentation to a large project, there
96
105
are tools to help: [eslint's valid-jsdoc](http://eslint.org/docs/rules/valid-jsdoc) rule
97
- lets you confirm JSDoc comment presence & validity as part of an
106
+ lets you confirm the presence of, and validate, JSDoc comments as part of an
98
107
automated style check.
99
108
100
109
## The Tags
101
110
102
- [usejsdoc.com](http://usejsdoc.org/index.html) covers all possible tags in the
103
- JSDoc syntax, and is a great reference material . The most common tags
104
- you'll see are:
111
+ [usejsdoc.com](http://usejsdoc.org/index.html) covers all available tags in the
112
+ JSDoc syntax, and is a great reference. The most commonly used tags
113
+ are:
105
114
106
- * @param - input values given to a function as an argument
115
+ * @param - input given to a function as an argument
107
116
* @returns - output value of a function
108
117
* @name - explicitly set the documented name of a function, class, or variable
109
- * @private - along with @public and @protected , you can use @private to document
110
- something for yourself without including it in generated documentation,
111
- since it isn't part of the public API
112
- * @example - you can use the @example tag to add code examples of how to
113
- use some thing inline with the thing itself
118
+ * @private - you can use @private to document
119
+ code and not have it included in the generated documentation,
120
+ maybe it's not part of the public API. There's also @public and @protected
121
+ * @example - you can use the @example tag to add inline code examples with your
122
+ documentation
114
123
115
- It ' ll help to remember the available tags if your text editor highlights correct tags: if it
116
- doesn ' t, try [using a plugin for JSDoc](https://github.com/documentationjs/documentation/wiki/Text-editor-plugins).
124
+ If your text editor does not highlight JSDoc tags,
125
+ try [using a plugin for JSDoc](https: // github.com/documentationjs/documentation/wiki/Text-editor-plugins).
117
126
118
127
## Flow type annotations
119
128
@@ -127,20 +136,3 @@ function addOne(input: number): number {
127
136
return input + 1 ;
128
137
}
129
138
```
130
-
131
- ## What ` documentation ` does
132
-
133
- Documentation does some minor magic to generate documentation. Unless
134
- you want to read the code for yourself, here's a summary of how it connects
135
- to your task as a developer.
136
-
137
- ** Inference** : JSDoc lets you specify absolutely everything about your code:
138
- use @name to say what something is called, @kind for whether it's a function
139
- or a class, @param for its parameters, and so on. But writing all of that
140
- explicitly is tedious, so where it can, ` documentation ` can automatically
141
- fill in @name , @kind , and @memberof tags based on its reading of the source
142
- code.
143
-
144
- ** Normalization** : JSDoc has multiple words for the same thing: you can
145
- say @augments or @extends and they'll do the same thing. ` documentation `
146
- normalizes these values to make them styleable.
0 commit comments