Join our webinar on Wednesday, June 26, at 1pm EDTHow Chia Mitigates Risk in the Crypto Industry.Register
Socket
Socket
Sign inDemoInstall

prettier-plugin-jsdoc

Package Overview
Dependencies
37
Maintainers
1
Versions
99
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    prettier-plugin-jsdoc

A Prettier plugin to format JSDoc comments.


Version published
Weekly downloads
77K
increased by7.91%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

NPM

install size dependencies

Prettier Banner

prettier-plugin-jsdoc

Prettier plugin for format comment blocks and convert to standard Match with Visual studio and other IDE which support jsdoc and comments as markdown.

Many good examples of how this plugin work, are in tests directory. Compare tests and their snapshot

Configured with best practices of jsDoc style guides.

TOC

Installation

  1. Install and configure Prettier as usual
  2. Install prettier-plugin-jsdoc
npm i prettier-plugin-jsdoc --save
yarn add prettier-plugin-jsdoc

Config

Set prettier-plugin-jsdoc to your plugins list.

.prettierrc

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

Prettier v3

{
  "plugins": ["./node_modules/prettier-plugin-jsdoc/dist/index.js"]
};

If you want ignore some type of files remove "prettier-plugin-jsdoc" from plugins or add empty plugins

module.exports = {
  "plugins": ["prettier-plugin-jsdoc"]
  overrides: [
    {
      files: '*.tsx',
      options: {
        "plugins": []
      },
    },
  ],
};

Ignore

To ignore prettier use /* */ or // instead of /** */

Examples

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

Format to

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

Format 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 example tag

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

to

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

Description is formatting as Markdown, so you could use any features of Markdown on that. Like code tags ("```js"), header tags like "# AHeader" or other markdown features.

Options

KeytypeDefaultdescription
jsdocSpacesNumber1
jsdocDescriptionWithDotBooleanfalse
jsdocDescriptionTagBooleanfalse
jsdocVerticalAlignmentBooleanfalse
jsdocKeepUnParseAbleExampleIndentBooleanfalse
jsdocCommentLineStrategy("singleLine","multiline","keep")"singleLine
jsdocCapitalizeDescriptionBooleantrue
jsdocSeparateReturnsFromParamBooleanfalseAdd an space between last @param and @returns
jsdocSeparateTagGroupsBooleanfalseAdd an space between tag groups
jsdocPreferCodeFencesBooleanfalseAlways fence code blocks (surround them by triple backticks)
tsdocBooleanfalse
jsdocPrintWidthNumberundefinedIf You don't set value to jsdocPrintWidth, the printWidth will be use as jsdocPrintWidth.
jsdocLineWrappingStyleString"greedy""greedy": Lines wrap as soon as they reach the print width
jsdocTagsOrderString (object)"undefined"Custom Tags Order

Full up to date list and description of options can be found in Prettier help. First install plugin then run Prettier with "--help" option.

$ prettier --help # global installation

$ ./node_modules/.bin/prettier --help # local installation

ESLint

Install eslint-plugin-prettier

$ yarn add eslint eslint-plugin-prettier

Then, in your .eslintrc.json:

{
  "plugins": ["prettier"],
  "rules": {
    "prettier/prettier": "error"
  }
}

Tsdoc

We hope to support whole tsdoc, if we missed somethings please create an issue.

{
  "tsdoc": true
};

Contribute

1- Get a clone/fork of repo

2- Install yarn

3- Add your changes

4- Add a test to your change if needed

5- Create PR

This project extended from @gum3n worked project on GitLab.

Prettier

JSDoc

Supported prettier version

versionprettier version
1.0.0+3.0.0+
0.4.22.x+

Keywords

FAQs

Last updated on 22 Dec 2023

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc