eslint-mdx: Parse error for multiline object props on React components

Initial checklist

Affected packages and versions

2.0.5

Link to runnable example

https://github.com/mike-fam/eslint-mdx-multiline-prop-error

Steps to reproduce

  1. Create a new workspace with npm and install eslint with eslint-plugin-mdx
  2. Eslint configuration:
{
   "overrides": [
   	{
   		"files": ["*.mdx"],
   		"extends": "plugin:mdx/recommended"
   	}
   ],
   "rules": {}
}
  1. Create an mdx file with a react component with a multiline object prop e.g.
<button
   style={{
   	display: 'block'
   }}
>
   Test
</button>
  1. Lint the file, note the error: Parsing error: Expected value to be truthy

Expected behavior

The file should pass linting without any problems, as this is valid mdx syntax.

Actual behavior

Linting produces the following error: 0:0 error Parsing error: Expected value to be truthy

Runtime

Node v16, Node v14

Package manager

yarn v1

OS

macOS

Build and bundle tools

webpack

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 16 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@JounQin did you see my above commit?

@wooorm Thanks! It seems working to me now. @mike-fam @morganfeeney @Ayc0 Can you help to confirm? You may need to delete your npm-lock.json or yarn.lock, etc to upgrade all related packages to confirm.

Working on a minimal reproduction without eslint-mdx.

I investigated a bit this issue.

With the following code:

-   list

    <Components data={`
    `} />

I also have the error Parsing error: Expected value to be truthy

This crashes because of this line: https://github.com/mdx-js/eslint-mdx/blob/9331895e902e4eb08cf2343bd7ccac2adf83af40/packages/eslint-mdx/src/worker.ts#L413.

When adding console.logs before and after attrValStart = prevCharOffset(attrValStart - 1); attrValEnd = nextCharOffset(attrValEnd);, here is what I have:

image

I think that the reason of the offset is because when writing <Component data={`\n `} />, acorn returns this node: image

But the offsets start & end on the data attribute (32, 35) don’t match the right start & end (end should have been 32, 38): image

I’m not sure why the spaces are dropped in this estree (which comes from this processor https://github.com/mdx-js/eslint-mdx/blob/9331895e902e4eb08cf2343bd7ccac2adf83af40/packages/eslint-mdx/src/worker.ts#L79).