JSDoc error 'description does not satisfy the regex pattern' from 'Comments in Typescript' plugin

Viewed 471

The JSDoc for the code below always gives me the error

Error: JSDoc description does not satisfy the regex pattern

in typescript (using Comments in Typescript Plugin for VS Code) for producing dynamic comments in the Visual Studio Code.
We are following JsDoc standards for commenting and documenting all code.

    /**
     * Validates if entityName is present in the Json Schema
     * @param {any} obj Contains the object from the Json Schema 
     * @param {number} idx It contains the index of the object
     * @param {string} entityName It contains the entity name value which has to be validated
     * @returns {boolean} True if entity key is present
     */
    private validateEntityKey(obj: any, idx: number, entityName: string): boolean {

    }

What's wrong with the above JSDoc?

1 Answers

The VSCode plugin you are using, Comments in Typescript Plugin for VS Code explicitly say:

Typescript comes with a lot of language annotations, which should not be duplicated in the comments.

And the examples of valid JSDocs they give do not contain types (with my commentary added):

/**
  * // TODO: comment getScriptVersion
  * Gets script version
  * @param fileName // no type specified
  * @returns script version // no type specified
  */
  getScriptVersion(fileName: string): string { // type specified here, as per TypeScript conventions

Although you say

We are following JsDoc standards for commenting and documenting all code.

The plugin makes some of those standards redundant and the regex pattern will be flagging them up as errors.

Instead your code should read as:

/**
 * Validates if entityName is present in the Json Schema
 * @param obj Contains the object from the Json Schema 
 * @param idx It contains the index of the object
 * @param entityName It contains the entity name value which has to be validated
 * @returns True if entity key is present
 */
private validateEntityKey(obj: any, idx: number, entityName: string): boolean {

}

Which should now pass, if I've understood the plugin's function correctly.

What I do no know, is if the plugin incorrectly generated the JSDoc (the one from your question) with types automatically, or if you added them yourself? If it's the former something is not working as intended, otherwise you can stop adding them manually.

Related