mdx-js / eslint-mdx

ESLint Parser/Plugin for MDX
https://npmjs.org/eslint-plugin-mdx
MIT License
258 stars 29 forks source link

There are serious issues when used with the `react/self-closing-comp` / `react/jsx-sort-props` rules. #488

Closed u3u closed 6 months ago

u3u commented 7 months ago

Initial checklist

Affected packages and versions

2.2.0

Link to runnable example

No response

Steps to reproduce

❌ Empty components are self-closing eslint(react/self-closing-comp)
<span>test</span>

💡 Fix this react/jsx-sort-props problem
<Image alt="alt" src="src" width="315" height="100" format="svg" />
↓↓↓↓↓
<Image alt="alt" format="src" height="315" src="100" width="svg" />

Clone this repository u3u/eslint-config, and input the above content in any mdx file to reproduce.

Expected behavior

Keep consistent with mdx/code-blocks.

Actual behavior

  1. <span>test</span> Regarded as an empty tag self-closing, it will be fixed to <span />, directly losing the content.
  2. After automatic sorting of JSX attributes, the content and attributes no longer correspond.

Runtime

Node v20

Package manager

pnpm

OS

macOS

Build and bundle tools

esbuild

JounQin commented 7 months ago

OK, the react/self-closing-comp part is just as same as #437.

After automatic sorting of JSX attributes, the content and attributes no longer correspond.

Just for confirming, react/jsx-sort-props itself runs correctly for normal .jsx files or mdx code blocks, right?

u3u commented 7 months ago

@JounQin Yes, they have no issues in the code block.

JounQin commented 7 months ago

@u3u Please help to test:

# yarn 1
yarn add https://pkg.csb.dev/mdx-js/eslint-mdx/commit/2dbcb20a/eslint-mdx https://pkg.csb.dev/mdx-js/eslint-mdx/commit/2dbcb20a/eslint-plugin-mdx
# yarn 2, 3
yarn add eslint-mdx@https://pkg.csb.dev/mdx-js/eslint-mdx/commit/2dbcb20a/eslint-mdx/_pkg.tgz eslint-plugin-mdx@https://pkg.csb.dev/mdx-js/eslint-mdx/commit/2dbcb20a/eslint-plugin-mdx/_pkg.tgz
# npm
npm i https://pkg.csb.dev/mdx-js/eslint-mdx/commit/2dbcb20a/eslint-mdx https://pkg.csb.dev/mdx-js/eslint-mdx/commit/2dbcb20a/eslint-plugin-mdx
u3u commented 7 months ago

🥳 Perfect!

https://github.com/mdx-js/eslint-mdx/assets/20062482/0d2a8073-8e0f-4280-a19c-6c1b14b909a1

JounQin commented 6 months ago

v2.2.1 has already been released.

u3u commented 6 months ago

Thanks!