mdx-js / eslint-mdx

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

Parsing error: Expected value to be truthy #420

Closed tmpduarte closed 1 year ago

tmpduarte commented 1 year ago

Initial checklist

Affected packages and versions

2.0.2

Link to runnable example

https://github.com/tmpduarte/eslint-mdx-visit-issue/tree/issue/expected-value-to-be-truthy

Steps to reproduce

Minimal Example

Minimal repository producing this issue with a fresh Vite / TypeScript / React / Storybook / MUI project.

Steps taken Forked this repository, added the setup needed to use MUI and updated the eslint-mdx to the latest version.

kudos to @sudosilico for the setup 🙏

Expected behavior

.mdx file should should be linted without parsing errors.

Actual behavior

$ yarn lint
yarn run v1.22.15
$ eslint --ext .ts,.tsx,.js,.jsx,.mdx src

/workspaces/eslint-mdx-visit-issue/src/stories/Button.stories.mdx
  0:0  error  Parsing error: Expected value to be truthy

✖ 1 problem (1 error, 0 warnings)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Runtime

Node v16

Package manager

yarn v1

OS

macOS

Build and bundle tools

Vite

JounQin commented 1 year ago

Thanks for reproduction, I'll check later.

JounQin commented 1 year ago

See https://github.com/tmpduarte/eslint-mdx-visit-issue/pull/1

  1. You're using eslint-plugin-mdx@2.0.0, but you tricked to say the affected version was 2.0.2
  2. See also https://github.com/webpack/webpack.js.org/pull/6297#issuecomment-1195469561 and https://github.com/webpack/webpack.js.org/pull/6301
JounQin commented 1 year ago

@wooorm Do you have any idea that how can we ensure same acorn and acorn-jsx versions between eslint-mdx vs micromark-extension-mdxjs? Will an optional peer dependency declaration of micromark-extension-mdxjs work?

Because acorn.tokTypes and acornJsx.tokTypes are different between versions.

wooorm commented 1 year ago

micromark-extension-mdxjs takes acorn as an instance: https://github.com/micromark/micromark-extension-mdxjs#optionsacorn. You can pass an instance of the version you use.

JounQin commented 1 year ago

@wooorm If I didn't remember wrong, micromark-extension-mdxjs is referenced from remark-mdx, but remark-mdx doesn't provide an acorn/acornJsx options.

wooorm commented 1 year ago

And it accepts options. You can pass the acorn version you want.

https://github.com/mdx-js/mdx/blob/main/packages/remark-mdx/index.js https://github.com/micromark/micromark-extension-mdxjs/blob/main/index.js

JounQin commented 1 year ago

OK then, I think I can give it a try tonight. Thanks!

tmpduarte commented 1 year ago

@JounQin thank you very much for taking a look a this 🙏

There might have been a confusion. The link I posted on the description is for a specific branch that has the version 2.0.2 as well as the MUI button in the storybook story, and that's where the problem happens.

The main branch, used to replicate the problem actually has not problem at all. Sorry for the confusion 🙏

TxHawks commented 1 year ago

I'm also getting this with version 2.0.3, node v16.13.2 and pnpm v7.9.5

JounQin commented 1 year ago

I'm also getting this with version 2.0.3, node v16.13.2 and pnpm v7.9.5

Please provide a minimal but runnable reproduction in a new issue then.

jvdl commented 1 year ago

I've opened up #429 as a continuation of this issue with a repro / failing test.