Detalhes do pacote

prettier-plugin-jsdoc

hosseinmd585.8kMIT1.3.3

A Prettier plugin to format JSDoc comments.

prettier, plugin, jsdoc, comment

readme (leia-me)

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

  1. Install and configure Prettier
  2. Install prettier-plugin-jsdoc:
npm install prettier-plugin-jsdoc --save-dev
yarn add prettier-plugin-jsdoc --dev

Configuration

Add prettier-plugin-jsdoc to your plugins list.

.prettierrc:

{
  "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

Key Type Default Description
jsdocSpaces Number 1
jsdocDescriptionWithDot Boolean false
jsdocDescriptionTag Boolean false
jsdocVerticalAlignment Boolean false
jsdocKeepUnParseAbleExampleIndent Boolean false
jsdocCommentLineStrategy ("singleLine","multiline","keep") "singleLine"
jsdocCapitalizeDescription Boolean true
jsdocSeparateReturnsFromParam Boolean false Adds a space between last @param and @returns
jsdocSeparateTagGroups Boolean false Adds a space between tag groups
jsdocPreferCodeFences Boolean false Always fence code blocks (surround them by triple backticks)
tsdoc Boolean false See TSDoc
jsdocPrintWidth Number undefined If you don't set the value to jsdocPrintWidth, printWidth will be used as jsdocPrintWidth
jsdocLineWrappingStyle String "greedy" "greedy": lines wrap as soon as they reach printWidth
jsdocTagsOrder String (object) undefined See 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 version Prettier version
1.0.0+ 3.0.0+
0.4.2 2.x+

Contributing

  1. Fork and clone the repository
  2. Install Yarn
  3. Install project dependencies:

    yarn install
  4. Make changes and make sure that tests pass:
    yarn run test
  5. Update or add tests to your changes if needed
  6. Create PR

Links

Acknowledge

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

changelog (log de mudanças)

Changelog

All notable changes to this project will be documented in this file. See standard-version for commit guidelines.

1.3.3 (2025-07-01)

Bug Fixes

  • add compatibility with prettier v3.6.0 (#246) (a50b62e)

1.3.1 (2025-01-03)

Bug Fixes

  • add package manager (ffafd40)
  • provide correct types path in conditional exports (#222) (7a884b6)

1.2.0 (2023-12-22)

Features

1.1.1 (2023-10-07)

Bug Fixes

  • export Options to better assist type checking for .prettierrc.js (#210) (77cf7af)

1.1.0 (2023-10-06)

Features

  • jsdocCommentLineStrategy (c4e4db5)

1.0.5 (2023-10-05)

Bug Fixes

  • long union type (4f9ba4c)
  • new line between Default is (9fbbe53)
  • wrong remove intention, make unexpected issue (de71607)

1.0.4 (2023-10-05)

1.0.3 (2023-10-04)

Bug Fixes

  • add new line to unknown tag (cdbf931)
  • new line after item list (98c42fe)

1.0.2 (2023-09-09)

Bug Fixes

  • default type format (08f834e)
  • description start with markdown (9129957)

1.0.1 (2023-07-19)

1.0.0 (2023-07-19)

Features

Bug Fixes

0.4.2 (2022-08-24)

Bug Fixes

0.4.1 (2022-08-24)

Features

0.3.37 (2022-04-11)

Bug Fixes

0.3.36 (2022-04-01)

Bug Fixes

0.3.35 (2022-03-31)

Bug Fixes

0.3.34 (2022-03-30)

Bug Fixes

0.3.33 (2022-03-25)

Features

  • add rollup script for compile to mjs (8783637)
  • support block quote (db0b07e)

Bug Fixes

0.3.32 (2022-03-24)

Features

  • add rollup script for compile to mjs (8783637)
  • support block quote (db0b07e)

Bug Fixes

0.3.31 (2022-03-12)

Bug Fixes

  • add a package description (#141) (b2f142f)
  • add jsdocPreferCodeFences documentation to README. (#146) (06ac97e)
  • clean published files (#140) (a77e0f7)
  • do not try to format tables found in code blocks (#145) (dd9e1dc)
  • ensure formatting matches Prettier markdown formatter (#147) (f735b18)
  • line breaks inside jsdoc link synonyms (#149) (092f409)

0.3.30 (2021-11-07)

Bug Fixes

  • support being called as a built-in parser (#138) (5bb0cd8)

0.3.29 (2021-11-05)

Features

  • add jsdocAddDefaultToDescription (c3fb168)

0.3.28 (2021-11-05)

Features

  • add jsdocSeparateTagGroups (d46e7f9)

0.3.27 (2021-11-05)

Features

  • add jsx tsx css less sass html yaml to markdown support (ef00318)

0.3.26 (2021-11-05)

Bug Fixes

0.3.25 (2021-11-05)

Features

  • add option to turn off capitalization (#127) (03e74ab)

Bug Fixes

0.3.24 (2021-09-02)

Bug Fixes

  • don't replace defaultvalue because of tsdoc (6eabd15)

0.3.23 (2021-06-10)

Features

  • add jsdocSeparateReturnsFromParam (1b3eb01)

0.3.22 (2021-05-01)

Bug Fixes

  • don't replace nonwhitespace characters (033ce15)

0.3.21 (2021-04-27)

Features

  • add jsdocPrintWidth to options (6fb1897)
  • add support break by backslash (4f4cd07)

Bug Fixes

0.3.20 (2021-04-23)

Bug Fixes

0.3.19 (2021-04-15)

Features

  • add jsdocPrintWidth to options (6fb1897)
  • add support break by backslash (4f4cd07)

Bug Fixes

0.3.18 (2021-04-02)

Bug Fixes

  • compatibility with other plugins (bfc9c39)
  • resolve parser of plugins (bd9be19)

0.3.17 (2021-03-31)

Bug Fixes

0.3.16 (2021-03-30)

Features

Bug Fixes

0.3.15 (2021-03-29)

Features

0.3.14 (2021-03-23)

Features

Bug Fixes

  • long single word in description (18ba560)

0.3.13 (2021-03-04)

Features

  • add @borrows @namespace @license @module (2a377f2)
  • add jsdocSingleLineComment to options (f755db1)
  • format indented code block (b5d8c9f)
  • support tsdoc (4213aed)

0.3.12 (2021-02-21)

Features

Bug Fixes

  • bold text by stars (306218b)
  • format all tags descriptions (cb815f0)
  • sort params order without name (5337018)
  • sort params order without name (5da7a26)

0.3.10 (2021-02-13)

Features

Bug Fixes

  • in block code (c864ba0)

  • add to dot to non-English descriptions (6445702)
  • better trimming + refactor (9350ee7)
  • bug in tags order (1331861)
  • indentation and printWidth fix (#56) (8361d95)
  • jsdocDescriptionWithDot with germany words (041c882)
  • jsdocKeepUnParseAbleExampleIndent (8f18200)
  • maxWidth of lines (5f807ce)
  • tags description indentation (b9c343f)
  • wrong yarn command (389f404)
  • wrong yarn command (0b9f468)
  • description: # in text mistaken for heading (d9a5617)
  • description: description start underscores (3b8bf02)
  • description: empty lines (7d89a66)
  • separate [@typedef](https://github.com/typedef) and [@callback](https://github.com/callback) (dfc78b4)
  • windows EOL now supported (4220471)

0.3.9 (2021-02-03)

Features

  • type-formatter: support rest parameters (9952ab8)
  • modernize nullable types (cf31411)
  • parser: do not remove default values (36f500d)

Bug Fixes

  • parser: jsdoc check (d9ce819)
  • * to any work with strings now (95bb610)
  • dash lines (33df06d)
  • incorrect Array type transformation (3aab697)
  • nested arrays + missing prefix (7b4eec6)
  • wrong license in package.json (0db143b)
  • parser: mordern array transformation (43aa632)
  • parser: optional parameter type (01d442a)
  • parser: tag type correction (6dc67c7)

0.3.8 (2021-01-27)

Bug Fixes

  • do not lower-case unrecognized jsdoc tags (9a3c04e)

0.3.6 (2021-01-14)

0.3.5 (2021-01-12)

Bug Fixes

  • keep empty line comments (e083299)

0.3.4 (2021-01-08)

Bug Fixes

  • add category to nameless tags (c602823)
  • add printWidth to description markdown (754031f)
  • add space to examples where accent symbol used (fd10ff1)
  • bug paraghrap with number in start of description (23297b8)
  • codes in description (2aecefd)
  • example print width (a4d0d5e)

0.3.0 (2021-01-06)

Features

  • support markdown as desscription formatter (2c14daf)

Bug Fixes

  • markdown # in description (0f7e9eb)
  • remove empty comments (3b7473e)
  • support desscription with dash (87a27a6)

0.2.14 (2021-01-06)

Features

  • support markdown as desscription formatter (2c14daf)

Bug Fixes

  • markdown # in description (0f7e9eb)
  • remove empty comments (3b7473e)
  • support desscription with dash (87a27a6)

0.2.13 (2020-12-29)

Bug Fixes

  • incorrect comment format (1ac43d1)

0.2.12 (2020-12-25)

Bug Fixes

0.2.11 (2020-12-25)

Bug Fixes

0.2.9 (2020-12-23)

Bug Fixes

  • not working for multi line union types (#17) (fee81f6)

0.2.8 (2020-12-19)

Bug Fixes

  • the "caption" should place behind the tag of "example" (#15) (b8d6e34)

0.2.7 (2020-12-17)

Bug Fixes