hosseinmd / prettier-plugin-jsdoc

A Prettier plugin to format JSDoc comments.
MIT License
232 stars 28 forks source link

`@default []` and `@default {}` turns into `@default` #159

Closed Dan503 closed 2 years ago

Dan503 commented 2 years ago

Input

interface Test {
    /**
     * The value
     *
     * @default []
     */
    value?: Array<string>
}

Output (unwanted change to @default value)

interface Test {
    /**
     * The value
     *
     * @default
     */
    value?: Array<string>
}
Dan503 commented 2 years ago

This problem also exists for {}

Input

interface Test {
    /**
     * The value
     *
     * @default {}
     */
    value?: object
}

Output (unwanted change to @default value)

interface Test {
    /**
     * The value
     *
     * @default
     */
    value?: object
}
hosseinmd commented 2 years ago

Unfortunately, jsdoc don't support array or object https://jsdoc.app/tags-default.html . This is a big problem I can't know how we could solve this, if we solve this it means we changed jsdoc standard

Dan503 commented 2 years ago

The documentation in JS Doc doesn't have specific examples on how to handle objects or arrays as default values.

It says this is the syntax

@default [<some value>]

Which suggests that maybe it wants arrays and objects to look like this:

// array
@default [[]]

//object
@default [{}]

I really don't like that syntax though. It looks like an array of arrays/objects.

Can this plugin just not delete [] and {} in an @default tag please?

Dan503 commented 2 years ago

If I made a PR to fix this issue, would you accept it?

Since this is just a code formatting plugin, I don’t see choosing not to delete something as going against JS Doc standard.

This isn't trying to transform valid JS Doc syntax into non-valid JS Doc syntax. This is just ignoring something the author is trying to write as valid syntax.

The plugin is overreaching at the moment trying to format something that the author doesn't want formatted.

hosseinmd commented 2 years ago

Yes. Please PR.

Dan503 commented 2 years ago

I'm struggling a bit with figuring out where the in the code it deletes the [] and {} from @default :(

hosseinmd commented 2 years ago

We used comment-parser and it has a problem with this and your type deleted by it. Maybe we should move issue to comment-parser

Dan503 commented 2 years ago

Maybe though this is a good work around in the mean time.

hosseinmd commented 2 years ago

Fixed v0.3.38