1.3.0 • Published 4 months ago

prettier-plugin-jsdoc v1.3.0

Weekly downloads
11,816
License
MIT
Repository
github
Last release
4 months ago

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.

Links

Prettier

JSDoc

Supported prettier version

versionprettier version
1.0.0+3.0.0+
0.4.22.x+
1.3.0

4 months ago

1.1.1

7 months ago

1.1.0

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

8 months ago

1.0.1

9 months ago

1.0.0

9 months ago

0.4.1

2 years ago

0.4.2

2 years ago

0.3.31

2 years ago

0.3.38

2 years ago

0.3.36

2 years ago

0.3.35

2 years ago

0.3.34

2 years ago

0.3.33

2 years ago

0.3.32

2 years ago

0.3.30

2 years ago

0.3.29

2 years ago

0.3.28

2 years ago

0.3.27

2 years ago

0.3.26

2 years ago

0.3.25

2 years ago

0.3.24

3 years ago

0.3.23

3 years ago

0.3.20

3 years ago

0.3.22

3 years ago

0.3.21

3 years ago

0.3.19

3 years ago

0.3.18

3 years ago

0.3.17

3 years ago

0.3.16

3 years ago

0.3.15

3 years ago

0.3.14-rc1

3 years ago

0.3.14

3 years ago

0.3.13

3 years ago

0.3.12

3 years ago

0.3.11

3 years ago

0.3.10

3 years ago

0.3.9

3 years ago

0.3.8

3 years ago

0.3.6

3 years ago

0.3.7

3 years ago

0.3.5

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.13

3 years ago

0.2.12

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.5

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.4

3 years ago

0.2.1

3 years ago

0.2.0

4 years ago

0.2.0-rc4

4 years ago

0.2.0-rc1

4 years ago

0.2.0-rc2

4 years ago

0.2.0-rc3

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago

0.0.25

4 years ago

0.0.26

4 years ago

0.0.24

4 years ago

0.0.24-rc

4 years ago

0.0.23

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.14

4 years ago

0.0.13

4 years ago

0.0.12

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago