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: visit is not a function #404

Closed sudosilico closed 2 years ago

sudosilico commented 2 years ago

Initial checklist

Affected packages and versions

2.0.0

Link to runnable example

https://github.com/sudosilico/eslint-mdx-visit-issue

Steps to reproduce

Minimal Example

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

Seems to be the same issue as (#403).

Steps taken:

Creating a new project with Vite, TypeScript, React, and Storybook, and then configuring eslint and eslint-plugin-mdx@2.0.0 results in a Parsing error: visit is not a function.

Environment:

$ yarn --version
1.12.17
$ node --version
v17.3.0

M1 MacBook Air 16GB, macOS Monterey 12.3

Expected behavior

.mdx file should should be linted without parsing errors.

Actual behavior

ESLint gives a parsing error for .mdx files:

$ eslint --ext .mdx src

...issue-stories/src/stories/Button.stories.mdx
  0:0  error  Parsing error: visit is not a function

✖ 1 problem (1 error, 0 warnings)

error Command failed with exit code 1.

Runtime

Node v17

Package manager

yarn v1

OS

macOS

Build and bundle tools

Vite

Workaround:

Downgrading to eslint-plugin-mdx version 1.17.0 as seen in commits that reference the above issue seems to resolve this.

JounQin commented 2 years ago

Thanks for reproduction, I'll take a look soon.

JounQin commented 2 years ago

https://github.com/mdx-js/eslint-mdx/issues/403#issuecomment-1167926793 same problem

workaround yarn add -D unist-util-visit vifile

I'll raise a PR to fix it soon.

JounQin commented 2 years ago

@sudosilico Please try for testing https://ci.codesandbox.io/status/mdx-js/eslint-mdx/pr/405/builds/265745

JounQin commented 2 years ago

I can confirm it's working as expected now:

gitpod /workspace/eslint-mdx-visit-issue (main) $ yarn add -D https://pkg.csb.dev/mdx-js/eslint-mdx/commit/98013f6e/eslint-plugin-mdx

gitpod /workspace/eslint-mdx-visit-issue (main) $ yarn lint
yarn run v1.22.19
$ eslint --ext .ts,.tsx,.js,.jsx,.mdx src

/workspace/eslint-mdx-visit-issue/src/App.tsx
  1:10  warning  'useState' is defined but never used     @typescript-eslint/no-unused-vars
  5:5   error    'React' must be in scope when using JSX  react/react-in-jsx-scope
  6:7   error    'React' must be in scope when using JSX  react/react-in-jsx-scope
  7:9   error    'React' must be in scope when using JSX  react/react-in-jsx-scope

/workspace/eslint-mdx-visit-issue/src/stories/Button.stories.mdx
  1:24  warning  'Story' is defined but never used  @typescript-eslint/no-unused-vars

✖ 5 problems (3 errors, 2 warnings)

error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
gitpod /workspace/eslint-mdx-visit-issue (main) $