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 #403

Closed frankandrobot closed 2 years ago

frankandrobot commented 2 years ago

Initial checklist

Affected packages and versions

2.0.0

Link to runnable example

No response

Steps to reproduce

The following sample file fails to lint:

---
title: "Summer Duran"
type: art
draft: false
created: "2021-05-28"
---

<SummerDuran1 />

eslint config:

"eslintConfig": {
    "parser": "@typescript-eslint/parser",
    "plugins": [
      "@typescript-eslint"
    ],
    "extends": [
      "eslint:recommended",
      "plugin:react/recommended",
      "plugin:@typescript-eslint/recommended",
      "plugin:react-hooks/recommended",
      "prettier"
    ],
    "overrides": [
      {
        "files": [
          "*.mdx"
        ],
        "extends": [
          "plugin:mdx/recommended"
        ],
        "globals": {
          "AwesomeCutScenes": "readonly"
        },
        "rules": {
          "react/jsx-no-undef": [
            2,
            {
              "allowGlobals": true
            }
          ]
        }
      }
    ],
    "env": {
      "es6": true,
      "browser": true,
      "jest": true,
      "node": true
    },
    "rules": {
      "react/react-in-jsx-scope": 0,
      "react/display-name": 0,
      "react/prop-types": 0,
      "@typescript-eslint/explicit-function-return-type": 0,
      "@typescript-eslint/explicit-module-boundary-types": 0,
      "@typescript-eslint/explicit-member-accessibility": 0,
      "@typescript-eslint/indent": 0,
      "@typescript-eslint/member-delimiter-style": 0,
      "@typescript-eslint/no-explicit-any": 0,
      "@typescript-eslint/no-var-requires": 0,
      "@typescript-eslint/no-use-before-define": 0,
      "@typescript-eslint/no-unused-vars": [
        2,
        {
          "argsIgnorePattern": "^_"
        }
      ],
      "no-console": [
        2,
        {
          "allow": [
            "warn",
            "error"
          ]
        }
      ]
    },
    "settings": {
      "react": {
        "version": "detect"
      }
    }
  },

Expected behavior

Actual behavior

environment

"eslint": "8.18.0",
    "eslint-config-prettier": "8.1.0",
    "eslint-plugin-mdx": "2.0.0",
    "eslint-plugin-react": "7.21.5",
    "eslint-plugin-react-hooks": "4.6.0",

Runtime

Node v16

Package manager

yarn v1

OS

macOS

Build and bundle tools

Next.js

JounQin commented 2 years ago

A minimal reproduction is required.

frankandrobot commented 2 years ago

I don't understand. You have a config, plus a failing mdx file. What more do you need

On Jun 26, 2022 6:21 PM, JounQin @.***> wrote:

A minimal reproduction is required.

— Reply to this email directly, view it on GitHubhttps://github.com/mdx-js/eslint-mdx/issues/403#issuecomment-1166675836, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AAGAGMOAI4U2KOIB4UDYX6TVRDQXNANCNFSM5Z4VRNQQ. You are receiving this because you authored the thread.Message ID: @.***>

JounQin commented 2 years ago

Please remember, we're using our free time to support OSS, a minimal reproduction is a basic respect for us so that we don't waste time to reproduce.

A GitHub repository or fork this repository and PR with a failing test will save time both of us.

JounQin commented 2 years ago

Like https://github.com/privatenumber/get-tsconfig/pull/19, you can add a test case at https://github.com/mdx-js/eslint-mdx/tree/master/test/fixtures

If it can't be reproduced this way, then a GitHub repository minimal reproduction is required.

JounQin commented 2 years ago

close for now, feel free to comment if you provide reproduction correctly.

Manubi commented 2 years ago

I do get the same error: Parsing error: visit is not a function eslint

CleanShot 2022-06-27 at 15 12 10@2x
JounQin commented 2 years ago

Again, please provide a runnable reproduction instead of just screenshots. That doesn’t help anything.

JounQin commented 2 years ago

Just guessing, it should be related to different version of unist-util-visit installed, it can be added into package.json.

JounQin commented 2 years ago

workaround yarn add -D unist-util-visit vfile

I'll raise a PR to fix it soon.

JounQin commented 2 years ago

Please try for testing 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) $ 
frankandrobot commented 2 years ago

What's the workaround @JounQin ? When I try to install vifile, yarn says that package doesn't exist :-)

Update: BTW, when I yarn install the build, still getting the same error.

JounQin commented 2 years ago

What's the workaround @JounQin ? When I try to install vifile, yarn says that package doesn't exist :-)

Update: BTW, when I yarn install the build, still getting the same error.

Sorry, it's vfile.

And a new temporary fixed version of eslint-plugin-mdx is

yarn add https://pkg.csb.dev/mdx-js/eslint-mdx/commit/98013f6e/eslint-plugin-mdx

See https://ci.codesandbox.io/status/mdx-js/eslint-mdx/pr/405/builds/265745 for more installation details for other npm clients.