Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
arthurgubaidullin opened this issue Aug 30, 2022 · 5 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@arthurgubaidullin
Copy link

arthurgubaidullin commented Aug 30, 2022

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:

  • prettier-plugin-jsdoc@0.4.2
  • prettier@2.7.1
@hosseinmd hosseinmd added bug Something isn't working good first issue Good for newcomers labels Aug 30, 2022
@arthurgubaidullin
Copy link
Author

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

description = description.replace(/[ \t]*Default is `.*`\.?$/, "");

@levithomason
Copy link

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
Copy link
Owner

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

@wreckah
Copy link

wreckah commented Apr 6, 2023

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 added a commit that referenced this issue Oct 5, 2023
@hosseinmd
Copy link
Owner

fixed: v1.0.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants