mdx-js / mdx-analyzer

MDX extension for Visual Studio Code
https://marketplace.visualstudio.com/items?itemName=unifiedjs.vscode-mdx
MIT License
347 stars 21 forks source link

Prettier formatting breaks JSDoc comments #454

Closed karlhorky closed 4 months ago

karlhorky commented 4 months ago

Initial checklist

Affected packages and versions

prettier@3.3.2, @mdx-js/react@3.0.1, next@14.2.4, react@^18

Link to runnable example

No response

Steps to reproduce

  1. Ensure Prettier is installed
  2. Copy the example from the Props section in the readme to an MDX file
  3. Format the file with Prettier
  4. Observe backslashes added before asterisk characters and the error message below
    Could not parse expression with acorn MDX micromark-extension-mdx-expression:acorn
  5. Replace the multi-line JSDoc comment with a single-line JSDoc block
  6. Format the file with Prettier
  7. Observe space being added before second asterisk character and error message below
    Property 'name' does not exist on type '{ readonly components?: {} | undefined; }'. ts-plugin(2339)

Prettier Input/Output:

Input:

{/**
  * @typedef Props
  * @property {string} name
  *   Who to greet.
  */}

{/** @typedef Props @property {string} name2 Who to greet. */}

# Hello {props.name} and {props.name2}

Output:

{/\*\*

- @typedef Props
- @property {string} name
- Who to greet.
  \*/}

{/* * @typedef Props @property {string} name2 Who to greet. */}

# Hello {props.name} and {props.name2}

https://github.com/mdx-js/mdx-analyzer/assets/1935696/8967a357-a093-4137-93ae-0144874834e9

Companion issue in prettier/prettier

I've also reported this as an issue in prettier/prettier:

If it's desired to only track it in prettier/prettier, then this issue can be closed.

Expected behavior

No problems with Prettier formatting using MDX comments with JSDoc

Actual behavior

Problems with Prettier formatting using MDX comments with JSDoc

Runtime

Node v20

Package manager

No response

OS

macOS

Build and bundle tools

No response

ChristianMurphy commented 4 months ago

Thanks for sharing @karlhorky! Prettier has a number of issues with MDX 3 comments. I'm not sure the language server can smooth those over, it probably needs to be reolved upstream, but @remcohaszing may know best.

remcohaszing commented 4 months ago

Duplicate of #415

github-actions[bot] commented 4 months ago

Hi! This was closed. Team: If this was fixed, please add phase/solved. Otherwise, please add one of the no/* labels.

github-actions[bot] commented 4 months ago

Hi team! Could you describe why this has been marked as external?

Thanks, — bb

github-actions[bot] commented 4 months ago

Hi team! Could you describe why this has been marked as external?

Thanks, — bb

karlhorky commented 4 months ago

Workaround

Ignore any JSDoc comments until MDX v2+ comments w. JSDoc support or MDX v3 support added:

{/* prettier-ignore-start */}

{/**
  * @typedef Props
  * @property {string} name
  *   Who to greet.
  */}

{/* prettier-ignore-end */}

# Hello {props.name}

Also added an PR to document this in the readme here: