Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
christiansr85 opened this issue Dec 3, 2020 · 0 comments
Open

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

christiansr85 opened this issue Dec 3, 2020 · 0 comments

Comments

@christiansr85
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant