hosseinmd / prettier-plugin-jsdoc

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

Poor handling for @example with a JS decorator #224

Open jfairley opened 9 months ago

jfairley commented 9 months ago

The plugin splits up code examples that include a decorator. It seems the jsdoc parser interprets the @ as a jsdoc tag.

example 1

@example is removed entirely because the parser thinks there is no content

before

/**
 * Decorate my injectable service.
 * 
 * @example
 *   @Inject()
 *   private readonly someService: SomeService;
 * 
 * @example
 *   @Inject() private readonly someService: SomeService;
 */
export class SomeService {}

after

/**
 * Decorate my injectable service.
 *
 * @Inject() private readonly someService: SomeService;
 *
 * @Inject() private readonly someService: SomeService;
 */
export class SomeService {}

example 2

I added code comments to prove my hypothesis from example 1 (above).

You can see that the @Inject is extracted and moved down below the @example blocks.

before

/**
 * Decorate my injectable service.
 * 
 * @example
 *   // example 1
 *   @Inject()
 *   private readonly someService: SomeService;
 * 
 * @example
 *   // example 2
 *   @Inject() private readonly someService: SomeService;
 */
export class SomeService {}

after

/**
 * Decorate my injectable service.
 *
 * @example // example 1
 *
 * @example // example 2
 *
 * @Inject() private readonly someService: SomeService;
 *
 * @Inject() private readonly someService: SomeService;
 */
export class SomeService {}