11# Getting Started
22
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.
56
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.**
99
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).
1311
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.
1813
1914## The Essentials
2015
@@ -34,8 +29,9 @@ function addOne(input) {
3429```
3530
3631The 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
3935
4036``` js
4137// --- INVALID - this is ignored by JSDOC ---
@@ -44,76 +40,89 @@ to write a comment like
4440// @returns {number} that number, plus one.
4541```
4642
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.
4845
49- Okay: so let 's break down that example into lines :
46+ Let 's break down the earlier JSDoc example :
5047
5148``` js
5249/**
5350 * This function adds one to its input.
5451 * ...
5552```
5653
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_.
5956
6057```js
6158 * @param {number} input any number
6259```
6360
64- The second line is a little more complex. The parts are
61+ On the second line:
6562
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}`,
7066 `{Object}`, `{Date}`, or any other JavaScript built-in type. And if you
7167 defined a custom class, like `FooClass`, you can use it as a type too by
7268 saying `{FooClass}`.
7369* `input` is the name of the input variable. It matches what the code
7470 says right below it (`function addOne(input)`).
7571* `any number` is the description of the input.
7672
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.
8075
8176## Optional Parameters
8277
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 :
8580
8681```js
8782 * @param {number} [input= 5 ] any number
8883```
8984
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.
92101
93102## Development Process
94103
95- If you're actively contributing documentation to a big project, there
104+ If you're contributing documentation to a large project, there
96105are 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
98107automated style check.
99108
100109## The Tags
101110
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:
105114
106- * @param - input values given to a function as an argument
115+ * @param - input given to a function as an argument
107116* @returns - output value of a function
108117* @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
114123
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).
117126
118127## Flow type annotations
119128
@@ -127,20 +136,3 @@ function addOne(input: number): number {
127136 return input + 1 ;
128137}
129138```
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