12 This rule was [**deprecated**](https://eslint.org/blog/2018/11/jsdoc-end-of-life) in ESLint v5.10.0.
14 [JSDoc](http://usejsdoc.org) generates application programming interface (API) documentation from specially-formatted comments in JavaScript code. For example, this is a JSDoc comment for a function:
19 * @param {number} num1 The first number.
20 * @param {number} num2 The second number.
21 * @returns {number} The sum of the two numbers.
23 function add(num1, num2) {
28 If comments are invalid because of typing mistakes, then documentation will be incomplete.
30 If comments are inconsistent because they are not updated when function definitions are modified, then readers might become confused.
34 This rule enforces valid and consistent JSDoc comments. It reports any of the following problems:
36 * missing parameter tag: `@arg`, `@argument`, or `@param`
37 * inconsistent order of parameter names in a comment compared to the function or method
38 * missing return tag: `@return` or `@returns`
39 * missing parameter or return type
40 * missing parameter or return description
43 This rule does not report missing JSDoc comments for classes, functions, or methods.
45 **Note:** This rule does not support all of the Google Closure documentation tool's use cases. As such, some code such as `(/**number*/ n => n * 2);` will be flagged as missing appropriate function JSDoc comments even though `/**number*/` is intended to be a type hint and not a documentation block for the function. We don't recommend using this rule if you use type hints in this way.
47 Examples of **incorrect** code for this rule:
52 /*eslint valid-jsdoc: "error"*/
54 // expected @param tag for parameter num1 but found num instead
55 // missing @param tag for parameter num2
56 // missing return type
59 * @param {number} num The first number.
60 * @returns The sum of the two numbers.
62 function add(num1, num2) {
67 // missing @returns tag
69 * @param {string name Whom to greet.
71 function greet(name) {
72 console.log("Hello " + name);
75 // missing parameter type for num1
76 // missing parameter description for num2
80 * @param num1 The first number.
81 * @param {number} num2
83 function sum(num1, num2) {
91 Examples of **correct** code for this rule:
96 /*eslint valid-jsdoc: "error"*/
101 * @param {number} num1 The first number.
102 * @param {number} num2 The second number.
103 * @returns {number} The sum of the two numbers.
105 function add(num1, num2) {
109 // default options allow missing function description
110 // return type `void` means the function has no `return` statement
112 * @param {string} name Whom to greet.
115 function greet(name) {
116 console.log("Hello " + name);
119 // @constructor tag allows missing @returns tag
123 * @param {number} num1 The first number.
124 * @param {number} num2 The second number.
126 function sum(num1, num2) {
131 // class constructor allows missing @returns tag
137 * @param {number} num1 The first number.
138 * @param {number} num2 The second number.
140 constructor(num1, num2) {
146 // @abstract tag allows @returns tag without `return` statement
149 * When the state changes, does it affect the rendered appearance?
151 * @param {Object} state The new state of the widget.
152 * @returns {boolean} Is current appearance inconsistent with new state?
155 throw new Error("Widget subclass did not implement mustRender");
159 // @override tag allows missing @param and @returns tags
160 class WonderfulWidget extends Widget {
165 return state !== this.state; // shallow comparison
174 This rule has an object option:
176 * `"prefer"` enforces consistent documentation tags specified by an object whose properties mean instead of key use value (for example, `"return": "returns"` means instead of `@return` use `@returns`)
177 * `"preferType"` enforces consistent type strings specified by an object whose properties mean instead of key use value (for example, `"object": "Object"` means instead of `object` use `Object`)
178 * `"requireReturn"` requires a return tag:
179 * `true` (default) **even if** the function or method does not have a `return` statement (this option value does not apply to constructors)
180 * `false` **if and only if** the function or method has a `return` statement or returns a value e.g. `async` function (this option value does apply to constructors)
181 * `"requireReturnType": false` allows missing type in return tags
182 * `"matchDescription"` specifies (as a string) a regular expression to match the description in each JSDoc comment (for example, `".+"` requires a description; this option does not apply to descriptions in parameter or return tags)
183 * `"requireParamDescription": false` allows missing description in parameter tags
184 * `"requireReturnDescription": false` allows missing description in return tags
185 * `"requireParamType": false` allows missing type in parameter tags
189 Examples of additional **incorrect** code for this rule with sample `"prefer": { "arg": "param", "argument": "param", "class": "constructor", "return": "returns", "virtual": "abstract" }` options:
194 /*eslint valid-jsdoc: ["error", { "prefer": { "arg": "param", "argument": "param", "class": "constructor", "return": "returns", "virtual": "abstract" } }]*/
199 * @arg {int} num1 The first number.
200 * @arg {int} num2 The second number.
201 * @return {int} The sum of the two numbers.
203 function add(num1, num2) {
210 * @argument {number} num1 The first number.
211 * @argument {number} num2 The second number.
213 function sum(num1, num2) {
220 * When the state changes, does it affect the rendered appearance?
222 * @argument {Object} state The new state of the widget.
223 * @return {boolean} Is current appearance inconsistent with new state?
226 throw new Error("Widget subclass did not implement mustRender");
235 Examples of additional **incorrect** code for this rule with sample `"preferType": { "Boolean": "boolean", "Number": "number", "object": "Object", "String": "string" }` options:
240 /*eslint valid-jsdoc: ["error", { "preferType": { "Boolean": "boolean", "Number": "number", "object": "Object", "String": "string" } }]*/
245 * @param {Number} num1 The first number.
246 * @param {Number} num2 The second number.
247 * @returns {Number} The sum of the two numbers.
249 function add(num1, num2) {
254 * Output a greeting as a side effect.
255 * @param {String} name Whom to greet.
258 function greet(name) {
259 console.log("Hello " + name);
264 * When the state changes, does it affect the rendered appearance?
266 * @param {object} state The new state of the widget.
267 * @returns {Boolean} Is current appearance inconsistent with new state?
270 throw new Error("Widget subclass did not implement mustRender");
279 Examples of additional **incorrect** code for this rule with the `"requireReturn": false` option:
284 /*eslint valid-jsdoc: ["error", { "requireReturn": false }]*/
286 // unexpected @returns tag because function has no `return` statement
288 * @param {string} name Whom to greet.
289 * @returns {string} The greeting.
291 function greet(name) {
292 console.log("Hello " + name);
295 // add @abstract tag to allow @returns tag without `return` statement
298 * When the state changes, does it affect the rendered appearance?
299 * @param {Object} state The new state of the widget.
300 * @returns {boolean} Is current appearance inconsistent with new state?
303 throw new Error("Widget subclass did not implement mustRender");
310 Example of additional **correct** code for this rule with the `"requireReturn": false` option:
315 /*eslint valid-jsdoc: ["error", { "requireReturn": false }]*/
318 * @param {string} name Whom to greet.
320 function greet(name) {
321 console.log("Hello " + name);
327 ### requireReturnType
329 Example of additional **correct** code for this rule with the `"requireReturnType": false` option:
334 /*eslint valid-jsdoc: ["error", { "requireReturnType": false }]*/
338 * @param {number} num1 The first number.
339 * @param {number} num2 The second number.
340 * @returns The sum of the two numbers.
342 function add(num1, num2) {
351 Example of additional **correct** code for this rule with the `"requireParamType": false` option:
356 /*eslint valid-jsdoc: ["error", { "requireParamType": false }]*/
360 * @param num1 The first number.
361 * @param num2 The second number.
362 * @returns {number} The sum of the two numbers.
364 function add(num1, num2) {
373 Example of additional **incorrect** code for this rule with a sample `"matchDescription": ".+"` option:
378 /*eslint valid-jsdoc: ["error", { "matchDescription": ".+" }]*/
380 // missing function description
382 * @param {string} name Whom to greet.
385 function greet(name) {
386 console.log("Hello " + name);
392 ### requireParamDescription
394 Example of additional **correct** code for this rule with the `"requireParamDescription": false` option:
399 /*eslint valid-jsdoc: ["error", { "requireParamDescription": false }]*/
405 * @returns {int} The sum of the two numbers.
407 function add(num1, num2) {
414 ### requireReturnDescription
416 Example of additional **correct** code for this rule with the `"requireReturnDescription": false` option:
421 /*eslint valid-jsdoc: ["error", { "requireReturnDescription": false }]*/
425 * @param {number} num1 The first number.
426 * @param {number} num2 The second number.
429 function add(num1, num2) {
436 ## When Not To Use It
438 If you aren't using JSDoc, then you can safely turn this rule off.