Latest Threat Research:Malicious dYdX Packages Published to npm and PyPI After Maintainer Compromise.Details
Socket
Book a DemoInstallSign in
Socket

prettier-plugin-jsdoc

Package Overview
Dependencies
Maintainers
1
Versions
105
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prettier-plugin-jsdoc

A Prettier plugin to format JSDoc comments.

latest
Source
npmnpm
Version
1.8.0
Version published
Weekly downloads
187K
-1.38%
Maintainers
1
Weekly downloads
 
Created
Source

NPM

Installation size

prettier-plugin-jsdoc

Prettier plugin for formatting comment blocks and converting to a standard. Match with Visual Studio Code and other IDEs that support JSDoc and comments as Markdown.

Many good examples of how this plugin works are in the /tests directory. Compare tests and their snapshots.

Configured with best practices of JSDoc style guides.

Contents

Installation

npm install prettier-plugin-jsdoc --save-dev
yarn add prettier-plugin-jsdoc --dev

Configuration

Add prettier-plugin-jsdoc to your plugins list.

Important: When using multiple plugins, add prettier-plugin-jsdoc to the end of the plugins list.

.prettierrc:

{
  "plugins": ["prettier-plugin-jsdoc"]
}

With other plugins:

{
  "plugins": [..., "prettier-plugin-jsdoc"]
}

prettier.config.js:

export default {
  plugins: ["prettier-plugin-jsdoc"],
};

If you want to ignore some types of files, use overrides with an empty plugins:

{
  "plugins": ["prettier-plugin-jsdoc"],
  "overrides": [
    {
      "files": "*.tsx",
      "options": {
        "plugins": []
      }
    }
  ]
}

Ignore

To prevent Prettier from formatting, use /* */ or // instead of /** */, or see Ignoring Code.

Examples

Single line

/**
 * @param {  string   }    param0 description
 */
function fun(param0) {}

Formats to:

/** @param {string} param0 Description */
function fun(param0) {}

React component

/**
 * @type {React.FC<{   message:string}   >}
 */
const Component = memo(({ message }) => {
  return <p>{message}</p>;
});

Formats to:

/** @type {React.FC<{message: string}>} */
const Component = memo(({ message }) => {
  return <p>{message}</p>;
});

TypeScript objects

/**
 @typedef {
    {
        "userId": {
        "profileImageLink": *,
        "isBusinessUser": "isResellerUser"|"isBoolean"|  "isSubUser" |    "isNot",
        "shareCode": number,
        "referredBy": any,
        },
        id:number
      }
     } User
     */

Format to:

/**
 * @typedef {{
 *   userId: {
 *     profileImageLink: any;
 *     isBusinessUser: "isResellerUser" | "isBoolean" | "isSubUser" | "isNot";
 *     shareCode: number;
 *     referredBy: any;
 *   };
 *   id: number;
 * }} User
 */

Example

Add code to @examples tag.

/**
 * @examples
 *   var one= 5
 *   var two=10
 *
 *   if(one > 2) { two += one }
 */

Formats to:

/**
 * @example
 *   var one = 5;
 *   var two = 10;
 *
 *   if (one > 2) {
 *     two += one;
 *   }
 */

Description

@description is formatted as Markdown so that you can use any features of Markdown on that. Like code tags (```js), header tags like # Header, or other Markdown features.

Options

KeyTypeDefaultDescription
jsdocSpacesNumber1
jsdocDescriptionWithDotBooleanfalse
jsdocDescriptionTagBooleanfalse
jsdocVerticalAlignmentBooleanfalse
jsdocKeepUnParseAbleExampleIndentBooleanfalse
jsdocCommentLineStrategy("singleLine","multiline","keep")"singleLine"
jsdocCapitalizeDescriptionBooleantrue
jsdocSeparateReturnsFromParamBooleanfalseAdds a space between last @param and @returns
jsdocSeparateTagGroupsBooleanfalseAdds a space between tag groups
jsdocPreferCodeFencesBooleanfalseAlways fence code blocks (surround them by triple backticks)
jsdocEmptyCommentStrategy("remove","keep")"remove"How to handle empty JSDoc comment blocks
jsdocBracketSpacingBooleanfalseWhether to add spaces inside JSDoc type brackets. {string} (false) vs { string } (true)
tsdocBooleanfalseSee TSDoc
jsdocPrintWidthNumberundefinedIf you don't set the value to jsdocPrintWidth, printWidth will be used as jsdocPrintWidth
jsdocLineWrappingStyleString"greedy""greedy": lines wrap as soon as they reach printWidth. "balance": preserve existing line breaks if lines are shorter than printWidth, otherwise use greedy wrapping
jsdocTagsOrderString (object)undefinedSee Custom Tags Order

TSDoc

We hope to support the whole TSDoc. If we missed something, please create an issue.

To enable, add:

{
  "tsdoc": true
}

Supported Prettier versions

Plugin versionPrettier version
1.0.0+3.0.0+
0.4.22.x+

Contributing

  • Fork and clone the repository

  • Install Yarn

  • Install project dependencies:

    yarn install
    
  • Make changes and make sure that tests pass:

    yarn run test
    
  • Update or add tests to your changes if needed

  • Create PR

Acknowledge

This project extended from the @gum3n worked project on GitLab.

Keywords

prettier

FAQs

Package last updated on 07 Dec 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts