Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prettier formatting breaks JSDoc comments #454

Closed
4 tasks done
karlhorky opened this issue Jul 7, 2024 · 6 comments
Closed
4 tasks done

Prettier formatting breaks JSDoc comments #454

karlhorky opened this issue Jul 7, 2024 · 6 comments
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on

Comments

@karlhorky
Copy link

karlhorky commented Jul 7, 2024

Initial checklist

Affected packages and versions

[email protected], @mdx-js/[email protected], [email protected], 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}
Kapture.2024-07-07.at.22.17.37.mp4

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

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Jul 7, 2024
@ChristianMurphy
Copy link
Member

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
Copy link
Member

Duplicate of #415

@remcohaszing remcohaszing marked this as a duplicate of #415 Jul 8, 2024
@remcohaszing remcohaszing closed this as not planned Won't fix, can't repro, duplicate, stale Jul 8, 2024

This comment has been minimized.

@remcohaszing remcohaszing added 👯 no/duplicate Déjà vu 👀 no/external This makes more sense somewhere else labels Jul 8, 2024
@github-actions github-actions bot removed the 👀 no/external This makes more sense somewhere else label Jul 8, 2024

This comment was marked as resolved.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 👯 no/duplicate Déjà vu 🤞 phase/open Post is being triaged manually labels Jul 8, 2024
@remcohaszing remcohaszing added the 👀 no/external This makes more sense somewhere else label Jul 8, 2024

This comment was marked as resolved.

@karlhorky
Copy link
Author

karlhorky commented Jul 8, 2024

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:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👀 no/external This makes more sense somewhere else 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

3 participants