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

Parsing error: Invalid left-hand side in prefix operation in mdx frontmatter #150

Closed
janosh opened this issue Jul 14, 2020 · 2 comments
Closed
Labels

Comments

@janosh
Copy link

janosh commented Jul 14, 2020

I added a file association in VS Code settings from .mdx to .md so that this plugin is applied to .mdx files.

"files.associations": {
  "*.mdx": "markdown",
},

When opening an .mdx file with frontmatter,

---
title: Some Title
slug: /some-title
---

import MyComponent from 'components'

# Heading

<MyComponent />

this plugin raises the error

Parsing error: Invalid left-hand side in prefix operation

> 1 | ---
    |   ^

Any way to avoid this? Can this plugin be used with .mdx files?

Related issues

@btmills
Copy link
Member

btmills commented Jul 22, 2020

I see a couple things going on here.

  1. That parse error suggests that it's trying to parse the --- in the first line of the file as a -- prefix unary decrement operator. That normally wouldn't happen. Is there something in your config that might cause ESLint to parse a .mdx file as JS?
  2. I explained a bit in MDX support #134 (comment), but I don't expect this plugin would work with MDX syntax currently since it's so different from Markdown. Based on a skim of the MDX docs, it shouldn't crash on the syntax, and in fact it shouldn't do anything. The plugin works by looking for ```js fenced code blocks, and since MDX doesn't need those, it shouldn't find any code to pass to ESLint in the first place. My guess is it should treat all the embedded JSX as regular text and ignore it like it ignores all the rest of the file outside of fenced code blocks.

You're probably best using https://github.com/mdx-js/eslint-mdx to lint .mdx files since it's maintained by the MDX team.

@btmills
Copy link
Member

btmills commented Aug 22, 2020

I'll close this since MDX is out of scope right now and encourage https://github.com/mdx-js/eslint-mdx instead.

@btmills btmills closed this as completed Aug 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants