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

fix: code block in jsx should be ignored #208

Closed
wants to merge 1 commit into from
Closed

Conversation

JounQin
Copy link
Member

@JounQin JounQin commented May 30, 2020

Partially fix #207

Code blocks in jsx should always be ignored, but I don't know if it is good to drop them in AST, or is there any better way?

Additionally, <details><summary >Override element states</summary> is parsed as a single jsx node from remark-mdx, it could not be handled correctly at https://github.com/mdx-js/eslint-mdx/blob/master/packages/eslint-mdx/src/traverse.ts#L41 which expects <details> and <summary >Override element states</summary> separately, is that possible to do it in remark-mdx? @wooorm

The temporary workaround is:

<details>

<summary >Override element states</summary>

</details>

What means that depends on user to make sure that <details> is a single jsx node.

@JounQin JounQin added the 👶 semver/patch This is a backwards-compatible fix label May 30, 2020
@JounQin JounQin self-assigned this May 30, 2020
@codecov-commenter
Copy link

Codecov Report

Merging #208 into master will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##            master      #208   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           19        19           
  Lines          411       411           
  Branches        76        77    +1     
=========================================
  Hits           411       411           
Impacted Files Coverage Δ
packages/eslint-mdx/src/traverse.ts 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7edaa59...052154e. Read the comment docs.

@wooorm
Copy link
Member

wooorm commented May 30, 2020

What makes you think that this is related to code blocks?

Anyway: this is a limitation of MDX 1. And solved in MDX 2.

@JounQin
Copy link
Member Author

JounQin commented Jun 1, 2020

<details>

<summary >Override element states</summary>

```jsx
import Foo from './foo'

export const Bar = () => <Foo />
``` // 

</details>

I mean even if I separate <detail> jsx node, the inner code block will cause parsing error for now.

Because they are wrapped into a jsx node at https://github.com/mdx-js/eslint-mdx/blob/master/packages/eslint-mdx/src/traverse.ts#L24:

const jsxNode = {
  type: 'jsx',
  value: `<details>

<summary >Override element states</summary>

\`\`\`jsx
import Foo from './foo'

export const Bar = () => <Foo />
\`\`\`

</details>`
}

I don't find a good way to preserve the code block into ESLint AST without modifying its value.

@JounQin
Copy link
Member Author

JounQin commented Jul 11, 2020

It's a bad fix, we need to find a better way to handle markdown content inside jsx for ESLint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
👶 semver/patch This is a backwards-compatible fix
Development

Successfully merging this pull request may close these issues.

Parsing Errors: Unterminated JSX contents when using details element
3 participants