eslint / eslint-plugin-markdown

Lint JavaScript code blocks in Markdown documents

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting it to work in VSCode?

greggman opened this issue · comments

I installed eslint-plugin-markdown in a project I'm editing with VScode and ran into issues

First I added the suggested overrides then I checked for errors in a markdown file, no errors show even thought I put intentional errors.

{
  ...
  "overrides": [
    {
      "files": [ "**/*.md" ],
      "parserOptions": {
        "ecmaFeatures": {
            "impliedStrict": true
        },
      },
      "rules": {
        "strict": "off"
      }
    }
  ]
}

I tried adding "markdown" to the eslint.validate setting as in in <projectfolder>/.vscode/settings.json

{
  "eslint.validate": [ "javascript", "html", "markdown" ]
}

But in that case VSCode seems be trying to lint the entire markdown file as JavaScript. I get errors on the entire file starting with the first line which is just normal text.

Any idea what I'm doing wrong?

I'm able to reproduce something like this with a configuration similar to yours, though I removed the overrides:

.vscode/settings.json

{
    "eslint.validate": ["javascript", "markdown"]
}

.eslintrc.js

module.exports = {
    plugins: [
    "markdown"
    ],
    extends: [
        "eslint:recommended"
    ],
    env: {
        browser: true
    }
}

In my case, lint rule failures are shown correctly:

screenshot 2019-01-02 14 46 58

But for some reason, syntax errors are all shown on the first line:

screenshot 2019-01-02 14 49 20

It got the column (7) correct, but ignored the line. Running ESLint outside the integration returns the correct line and column:

$ node_modules/.bin/eslint README.md

/Users/brandon/code/eslint/markdown-test/README.md
  5:7  error  Parsing error: Unexpected token !

✖ 1 problem (1 error, 0 warnings)

I don't get any errors in a file that shouldn't have any:

screenshot 2019-01-02 14 56 18

Does this match what you're seeing?

Actually now that you mention it yes, that's what I'm seeing but it's not just syntax errors, it's any eslint error.

Here the only error is a style error, spaces after foo

screen shot 2019-01-03 at 10 52 02

with the space removed

screen shot 2019-01-03 at 10 52 11

I finally figured out what was causing this! Most ESLint rules pass both start and end locations, but parse errors only specify start locations. A bug was causing the processor to add endLine: NaN to those messages, which was understandably confusing VSCode. I opened #154 to fix this.