X Tutup
Skip to content

[MDX] Make format tests pass#18935

Merged
seiyab merged 5 commits intoprettier:mdxfrom
seiyab:mdx-work-6
Mar 10, 2026
Merged

[MDX] Make format tests pass#18935
seiyab merged 5 commits intoprettier:mdxfrom
seiyab:mdx-work-6

Conversation

@seiyab
Copy link
Collaborator

@seiyab seiyab commented Mar 9, 2026

Description

FULL_TEST=1 yarn test tests/format/mdx passes on this branch.

[mise]user@projects/prettier [mdx-work-6] % FULL_TEST=1 yarn test --runInBand tests/format/mdx
 PASS  tests/format/mdx/mdx/format.test.js
 PASS  tests/format/mdx/import-export/format.test.js
 PASS  tests/format/mdx/embedded-language-formatting/format.test.js
 PASS  tests/format/mdx/attribute/format.test.js

Test Suites: 4 passed, 4 total
Tests:       27 passed, 27 total
Snapshots:   27 passed, 27 total
Time:        1.115 s
Ran all test suites matching tests/format/mdx.

Failing tests

FULL_TEST=1 yarn test --runInBand tests/format/mdx
...
 FAIL  tests/format/misc/embedded_language_formatting/mdx/format.test.js
...
 FAIL  tests/unit/visitor-keys.js

Checklist

  • I’ve added tests to confirm my change works.
  • (If changing the API or CLI) I’ve documented the changes I’ve made (in the docs/ directory).
  • (If the change is user-facing) I’ve added my changes to changelog_unreleased/*/XXXX.md file following changelog_unreleased/TEMPLATE.md.
  • I’ve read the contributing guidelines.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 9, 2026

Open in StackBlitz

yarn add https://pkg.pr.new/@prettier/plugin-hermes@18935.tgz
yarn add https://pkg.pr.new/@prettier/plugin-oxc@18935.tgz
yarn add https://pkg.pr.new/prettier@18935.tgz

commit: aac29a1

@netlify
Copy link

netlify bot commented Mar 9, 2026

Deploy Preview for prettier ready!

Built without sensitive environment variables

Name Link
🔨 Latest commit e90111f
🔍 Latest deploy log https://app.netlify.com/projects/prettier/deploys/69aed58fe68bc00008c25f89
😎 Deploy Preview https://deploy-preview-18935--prettier.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

Comment on lines 82 to 85
export const Test = () => {
return <p>test</p>;
};

return <p>test</p>;
};
<Test />
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Input:

{/* prettier-ignore-start */}
export const Test = () => {
   return <p>test</p>;
 };
   <Test />
{/* prettier-ignore-end */}

Comment on lines 705 to 708
<ul>
<li>item </li>
<li>item {" "} </li>
<li />
</ul>
Copy link
Collaborator Author

@seiyab seiyab Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Input:

<ul>
      <li   >item    {' '} </li>
      <li/>
         </ul >

As another approach, we can probably render mdxFlowElement as embedded JSX expression. It will output <li>item </li> as main, I guess.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you are right about this.

Comment on lines +183 to +188
if (options.parser === "mdx") {
const paragraph = path.findAncestor((node) => node.type === "paragraph");
if (paragraph?.hasMdxJsx) {
return true;
}
}
Copy link
Collaborator Author

@seiyab seiyab Mar 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without this:

- <ExternalLink href="http://example.com">Prettier</ExternalLink> is an
- opinionated-code-formatter-that-support-many-languages-and-integrate-with-most-editors
+ <ExternalLink href="http://example.com">Prettier</ExternalLink> is an opinionated-code-formatter-that-support-many-languages-and-integrate-with-most-editors

Note that the failed on on branch mdx might somewhat make sense because the option proseWrap is preserve in the test. With proseWrap: 'always', mdx branch breaks the paragraph.
IMO, it should break such paragraph because:

  • It's more compatible to current Prettier
  • JSX looks more appropriate as its context than prose

@seiyab seiyab merged commit ca6d3bf into prettier:mdx Mar 10, 2026
10 of 34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

X Tutup