leo-buneev / eslint-plugin-md

Allows you to lint markdown code in your *.md files.
16 stars 5 forks source link

"Cannot read property 'tokens' of undefined" error #9

Open christiansr85 opened 3 years ago

christiansr85 commented 3 years ago

Version of the eslint-plugin-md: 1.0.19

I have an error when trying to parse a markdown file wiht code snippets and when the code is fenced. I'm getting this error:

Cannot read property 'tokens' of undefined
TypeError: Cannot read property 'tokens' of undefined
    at validate (/home/[...]/node_modules/eslint/lib/util/source-code.js:28:14)
    at ...

Example of files and configuration causing the error:

README.md

npm start --dry-run

.eslintrc (yaml syntax):

extends:
    - "plugin:md/recommended"

rules:
    md/remark: 
        - error
        - plugins: 
            - "preset-lint-markdown-style-guide"
            - 
                - "lint-fenced-code-flag"
                - allowEmpty: true
            -
                - "lint-ordered-list-marker-value"
                - "ordered"

overrides:
    -
        files:
            - "*.md"
        parser: "markdown-eslint-parser"

I've seen that in the mdProcessor.js of this plugin, line 34, inside preprocess function, it is storing some sort of filename with the extension of the code snippet appended to it and perhaps it could be giving problems:

const jsBlocksResult = nonMdBlocksInner.map(({ text, lang }, i) => ({
      text,
      // eslint internal code appends this filename to real filename
      filename: `/../../${partName}.${lang}`,
    }))

As you can see in the example, I disabled the lint-fenced-code-flag in order to be able to pass the validation by removing the language from the code snippets, but this is not an option since I have many md files plenty of this feature.