leo-buneev / eslint-plugin-md

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

[Bug] Doesn't parse indented code blocks #7

Open scinos opened 3 years ago

scinos commented 3 years ago

When the codeblock is indented followed by a codeblock that is not, the parser has a really bad time trying to parse it.

I created a repo with a reproduction case: https://github.com/scinos/eslint-md-parsing-error

Input:

- list

  ```js
  foo()
  ```

---

```js
bar()
```

Lint errors (./node_modules/.bin/eslint .):

   3:3  error  Insert `··`                              prettier/prettier
   4:1  error  Insert `··`                              prettier/prettier
   5:1  error  Insert `··`                              prettier/prettier
   6:1  error  Insert `··`                              prettier/prettier
   7:1  error  Insert `··`                              prettier/prettier
   8:1  error  Insert `··`                              prettier/prettier
   9:1  error  Insert `··`                              prettier/prettier
  10:1  error  Insert `··`                              prettier/prettier
  11:1  error  Insert `··`                              prettier/prettier
   5:3  error  Parsing error: Unexpected character '`'

Output when using autofix (./node_modules/.bin/eslint . --fix):

          -   list

    ```js
    foo()
  ```

---

```js
bar()
```

I found two workarounds:

1) Removing the language tag from the first codeblock 2) Un-indenting the first codeblock

scinos commented 3 years ago

Looks like the problem is in the regular expression in https://github.com/leo-buneev/eslint-plugin-md/blob/master/lib/processors/mdProcessor.js#L12, as it doesn't account for indented blocks. In the above example, it thinks there is a single code block from the 3rd line to the end of the file.