WebStorm 2017.2 Help

Creating JSDoc Comments

On this page:

Introduction

To make your code easy to use by other developers it is considered good practice to provide an HTML documentation of its Application Programming Interface (API). Such documentation can be generated automatically by the JSDoc tool. All you need, is supply your code with documentation comments in accordance with the JSDoc standard. The tool retrieves information from your comments and renders it in HTML using a built-in template.

You can find a detailed description of the JSDoc syntax with examples and explanation of their use in the article An Introduction to JSDoc.

WebStorm creates stubs of JSDoc comments on typing the opening tag /** and pressing Enter. If this feature is applied to a method or a function, @param tags are created. In any other places WebStorm adds an empty documentation stub.

TODO patterns and Closure Compiler annotations inside documentation comments are also recognized and are involved in code completion, intention actions, and other types of coding assistance.

Documentation comments in your source code are available for the Quick Documentation Lookup and open for review on pressing Ctrl+Q.

WebStorm checks syntax in the comments and treats it according to the Code Inspections settings.

Example of JavaScript comment

Consider the following function:

function loadDocs(myParam1, myParam2){}

Type the opening documentation comment and press Enter to generate the documentation comment stub:

/** * @param myParam1 * @param myParam2 */

Enabling documentation comments

  1. Open the Editor | General | Smart Keys page of WebStorm settings (Ctrl+Alt+S).
  2. In the Enter section, select or clear Insert documentation comment stub check box.

Creating a JSDoc comment block

  1. Place the caret before the method or function declaration.
  2. Type the opening block comment /** and press Enter.
  3. Describe the listed parameters and return values.

Documentation comment can be created with the dedicated action Fix Doc Comment. It can be invoked by means of Find Action command.

Press Ctrl+Shift+A, with the caret somewhere within a class, method, function, or field, which should be documented, and enter the action name Fix Doc String. The missing documentation stub with the corresponding tags is added. For example:

function loadDocs(myParam1, myParam2){}

Type the opening documentation comment and press Enter to generate the documentation comment stub:

/** * @param myParam1 * @param myParam2 */

The next case lays with fixing problems in the existing documentation comments.

For example, if a method signature has been changed, WebStorm highlights a tag that doesn't match the method signature, and suggests a quick fix.

For JavaScript, WebStorm suggests an intention action UpdateJSDoc comment. You can also press Ctrl+Shift+A, and type the action name:

fix doc comment js
Last modified: 29 November 2017

See Also