hosseinmd/prettier-plugin-jsdoc

tsdoc @example tag loses indentation with backticks in the snippet

Shrugsy opened this issue · 2 comments

When trying to format a code snippet located under a tsdoc @example tag, the indentation becomes flattened when a backtick (`) is included in the snippet.

Example:

.prettierrc:

{
  "endOfLine": "auto",
  "jsdocParser": true,
  "tsdoc": true
}

Input 1 - single quotes on someString:

/**
 * This is a function
 * @example
 * ```ts
 * calculateStuff({
 *   query: () => ({ value: 'someString' }),
 * })
 * ```
 */
function calculateStuff(opts: Record<string, any>): number {
  // do some calculations
  return 500;
}

Output 1 - shifts the whole snippet, no problem:

/**
 * This is a function
 *
 * @example
 *   ```ts
 *   calculateStuff({
 *     query: () => ({ value: 'someString' }),
 *   })
 *   ```;
 */
function calculateStuff(opts: Record<string, any>): number {
  // do some calculations
  return 500;
}

Input 2 - changed from single quotes to backticks:

/**
 * This is a function
 * @example
 * ```ts
 * calculateStuff({
 *   query: () => ({ value: `someString` }),
 * })
 * ```
 */
function calculateStuff(opts: Record<string, any>): number {
  // do some calculations
  return 500;
}

Output 2 - indentation for the whole snippet becomes equal:

/**
 * This is a function
 *
 * @example
 *   ```ts
 *   calculateStuff({
 *   query: () => ({ value: `someString` }),
 *   })
 *   ```
 */
function calculateStuff(opts: Record<string, any>): number {
  // do some calculations
  return 500;
}

What's your prettier-plugin-jsdoc version?
In the latest version we changed some behavior of tsdoc example please test it.

Thanks @hosseinmd, I'm on the latest version of prettier-plugin-jsdoc, but you prompted me to look closer, and it turns out it was due to multiple conflicting prettier configs causing the tsdoc option to not be applied properly. Not a problem with the library.

Thanks for the good work 👍