hosseinmd / prettier-plugin-jsdoc

A Prettier plugin to format JSDoc comments.
MIT License
228 stars 29 forks source link

Incorrect handling of default type parameter values produces infinite changes #176

Closed arthurgubaidullin closed 11 months ago

arthurgubaidullin commented 2 years ago

Example of buggy code:

/**
 * @template [BAR=({bar:true}&{foo:false}&{buggy:true})] 
 * @typedef {{foo: BAR}} SomeType
 */

First formatting produces the following result:

/**
 * @template [BAR=({bar:true}&{foo:false}&{buggy:true})] Default is
 *   `({bar:true}&{foo:false}&{buggy:true})`
 * @typedef {{foo: BAR}} SomeType
 */

Second formatting produces the following result:

/**
 * @template [BAR=({bar:true}&{foo:false}&{buggy:true})] Default is
 *   `({bar:true}&{foo:false}&{buggy:true})`. Default is
 *   `({bar:true}&{foo:false}&{buggy:true})`
 * @typedef {{foo: BAR}} SomeType
 */

Third formatting produces the following result:

/**
 * @template [BAR=({bar:true}&{foo:false}&{buggy:true})] Default is
 *   `({bar:true}&{foo:false}&{buggy:true})`. Default is
 *   `({bar:true}&{foo:false}&{buggy:true})`. Default is
 *   `({bar:true}&{foo:false}&{buggy:true})`
 * @typedef {{foo: BAR}} SomeType
 */

And so on.

Prettier config:

{
  "bracketSpacing": false,
  "singleQuote": true,
  "plugins": ["./node_modules/prettier-plugin-jsdoc"]
}

Environment:

arthurgubaidullin commented 2 years ago

I think the problem is on this line. A possible line break is not checked.

https://github.com/hosseinmd/prettier-plugin-jsdoc/blob/d255d76b93aba6bb528c0db34e2de7e4a6e7ce57/src/parser.ts#L533

levithomason commented 1 year ago

I'd like to disable this feature altogether. It is unexpected for a formatter to write documentation for me. I don't want my jsdoc content changed, I only want it formatted.

The jsdoc in that file says that it is in place due to a TS issue, however, I'm not using TS and my IDE also shows the defaults already. So, the insertion is unnecessary. It is cluttering up the actual documentation in my case:

image image
hosseinmd commented 1 year ago

Yes, you are right. This feature is for VS Code. I agree with you, this feature should be optional.

wreckah commented 1 year ago

Just want to clarify that such feature is already implemented, but is not referred in the docs:


module.exports = {
  plugins: ['prettier-plugin-jsdoc'],
  jsdocAddDefaultToDescription: false
};
hosseinmd commented 11 months ago

fixed: v1.0.5