eslint-mdx: Parse error for multiline object props on React components
Initial checklist
- I read the support docs
- I read the contributing guide
- I agree to follow the code of conduct
- I searched issues and couldn’t find anything (or linked relevant results below)
Affected packages and versions
2.0.5
Link to runnable example
https://github.com/mike-fam/eslint-mdx-multiline-prop-error
Steps to reproduce
- Create a new workspace with npm and install
eslint
witheslint-plugin-mdx
- Eslint configuration:
{
"overrides": [
{
"files": ["*.mdx"],
"extends": "plugin:mdx/recommended"
}
],
"rules": {}
}
- Create an mdx file with a react component with a multiline object prop e.g.
<button
style={{
display: 'block'
}}
>
Test
</button>
- 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
- Fix positional info on tokens, nodes, also for tabs Related-to: mdx-js/eslint-mdx#435. — committed to micromark/micromark-extension-mdx-expression by wooorm a year ago
- chore: bump all deps, add test case for #435 — committed to mdx-js/eslint-mdx by JounQin a year ago
- chore: bump all deps, add test case for #435 (#463) — committed to mdx-js/eslint-mdx by JounQin a year ago
@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
oryarn.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:
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:I think that the reason of the offset is because when writing
<Component data={`\n `} />
,acorn
returns this node:But the offsets start & end on the
data
attribute (32, 35) don’t match the right start & end (end should have been 32, 38):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).