mdx-js / eslint-mdx

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

Parsing error: <filename.mdx>: Unexpected token #250

Closed jjoselv closed 4 years ago

jjoselv commented 4 years ago

Subject of the issue

I am receiving this error with a file as simple as this:

`

Menu List

Let's define a story for our TableRowMenu component: error:

/stories/TableRowMenu.stories.mdx

1:0 error Parsing error: #####/TableRowMenu.stories.mdx: Unexpected token (1:0)

1 | # Menu List | ^ 2 | 3 | Let's define a story for our TableRowMenu component: 4 | `

Additionaly, I cannot manage to set VSCode to read the mdx files

Version of the plugin: v0.2.2

Settings: "eslint.options": { "lintFiles": ["./src/", "./stories/"], "extenstions": [".js", ".jsx", ".md", ".mdx", ".ts", ".tsx"] }, "eslint.probe": [ "javascript", "javascriptreact", "typescript", "typescriptreact", "html", "vue", "markdown", "mdx" ]

Your environment

Steps to reproduce

I launch this command: eslint --config .eslintrc.yml --ext .js,.jsx,.mdx "src/" "stories/"

The .eslintrc.yml:

`

extends:

settings: react: version: latest

parser: '@babel/eslint-parser'

parserOptions: ecmaVersion: 6 sourceType: 'module' ecmaFeatures: jsx: true experimentalDecorators: true

globals: DEV: true SERVER: true

plugins:

Expected behaviour

I think it should not through an error

Actual behaviour

The error happens

JounQin commented 4 years ago

Your posted content is unreadable, please format it correctly first, thx.

JounQin commented 4 years ago

I can imagine this is a usage question.

.mdx files require eslint-mdx as parser, but other preset overrides mdx's recommended config, so the following should do the trick:

{
  overrides: [
    {
      files: '*.mdx',
      parser: 'eslint-mdx'
    }
  ]
}
jjoselv commented 4 years ago

With the overrides I managed to make it work via command line, but VS Code MDX extension reports different from command line (basically it appears to be ignoring the yaml config)

JounQin commented 4 years ago

Maybe you just need to reload VSCode.

jjoselv commented 4 years ago

Nope, still "No Problems" in VS Code, when from the command line it says: 42 problems (22 errors, 20 warnings) 12 errors and 5 warnings potentially fixable with the '--fix' option.

JounQin commented 4 years ago

Then I have no idea what is happening, I can't reproduce it, and no helpful information.

jjoselv commented 4 years ago

What can I give you to diagnose it?

jjoselv commented 4 years ago

Hi again I've spent near 5 hours trying to make eslint extension for VSCode to run in debug mode to be able to pass a log to you, but no luck 😢 I can give you the settings that I have in my settings.json

 "eslint.probe": [
        "markdown",
        "javascript",
        "javascriptreact",
        "typescript",
        "typescriptreact",
        "html",
        "vue",
        "mdx"
    ],
    "eslint.options": {
        "extensions": [".js", ".jsx", ".md", ".mdx", ".ts", ".tsx"],
    },
    "eslint.debug": true
jjoselv commented 4 years ago

Hm, the debug mode works when typing on a js file, but doesn't when doing it on a mdx file 😩

jjoselv commented 4 years ago

OH! It started working when I added this to the settings.json:

"eslint.validate": [
        "mdx",
        "markdown",
        "javascript",
        "javascriptreact",
        "typescript",
        "typescriptreact",
        "html",
        "vue"
    ],
JounQin commented 4 years ago

OH! It started working when I added this to the settings.json:

"eslint.validate": [
        "mdx",
        "markdown",
        "javascript",
        "javascriptreact",
        "typescript",
        "typescriptreact",
        "html",
        "vue"
    ],

Wow, that's weird, it is said eslint.validate is a legacy option.

eslint.validate - an array of language identifiers specifying the files for which validation is to be enforced. This is an old legacy setting and should in normal cases not be necessary anymore. Defaults to ["javascript", "javascriptreact"].

Maybe we should report it in vscode-eslint.

jjoselv commented 4 years ago

True. Thanks for sticking and for opening the issue! And for the understanding and patience throughout this issue, very much appreciated 👍🏻

GorvGoyl commented 3 years ago

OH! It started working when I added this to the settings.json:

"eslint.validate": [
        "mdx",
        "markdown",
        "javascript",
        "javascriptreact",
        "typescript",
        "typescriptreact",
        "html",
        "vue"
    ],

Doesn't that slow it down when saving file? for me it gets stuck saying Saving 'index.mdx': Getting code actions from ''ESLint', 'Tailwind CSS IntelliSense'' and takes 10-20 seconds to save.

image

Halip26 commented 2 years ago

I have the same problems & I dont know how to fix it :(