prettier-plugin-jsdoc icon indicating copy to clipboard operation
prettier-plugin-jsdoc copied to clipboard

when appending "default description" to description, imported types are repeated

Open boneskull opened this issue 1 year ago • 2 comments

Given:

/**
 * A thing that does stuff
 * @template {any[]} [T=import('foo').Something]
 * @param {T} values Stuff.
 */
function doStuff (values) {
}

Invoking prettier will result in this:

/**
 * A thing that does stuff
 * @template {any[]} [T=import('foo').Something] Default is `import('foo').Something`
 * @param {T} values Stuff. 
 */
function doStuff (values) {
}

But if we invoke prettier again, we get this:

/**
 * A thing that does stuff
 * @template {any[]} [T=import('foo').Something] Default is `import('foo').Something` Default is `import('foo').Something`
 * @param {T} values Stuff. 
 */
function doStuff (values) {
}

And again:

/**
 * A thing that does stuff
 * @template {any[]} [T=import('foo').Something] Default is `import('foo').Something` Default is `import('foo').Something` Default is `import('foo').Something`
 * @param {T} values Stuff. 
 */
function doStuff (values) {
}

(linebreaks will be added to the description of values as well)

This does not happen if we do, e.g.,:

/**
 * @typedef {import('foo').Something} Something
 */

/**
 * A thing that does stuff
 * @template {any[]} [T=Something]
 * @param {T} values Stuff.
 */
function doStuff (values) {
}

This results in:

/**
 * A thing that does stuff
 * @template {any[]} [T=Something]  Default is `Something`
 * @param {T} values Stuff.
 */
function doStuff (values) {
}

Subsequent prettier invocations will not cause Default is Something to be repeated.

This may be difficult to reproduce and I'm still trying to isolate it. It may only apply to docstrings for a class (not a function), or if @implements is present.

boneskull avatar Mar 12 '24 19:03 boneskull

@boneskull

I have fixed the issue with the duplication of the "Default is ..." phrase in documentation comments. Now, repeated invocations or formatting via Prettier will no longer cause the phrase to be repeated. You can find the details and changes in my PR: link to the PR.

Poliklot avatar Dec 03 '24 05:12 Poliklot

@boneskull After 297 days, it finally happened! v1.3.2 🥳

image

Poliklot avatar Jan 15 '25 12:01 Poliklot