eslint / markdown

Lint JavaScript code blocks in Markdown documents
MIT License
406 stars 63 forks source link

Bug: Uncaught undefined for reporting after a code block #244

Closed DMartens closed 7 months ago

DMartens commented 7 months ago

Issue

Currently there is a guard for messages which report before the code block, but not if the message reports for a line after the code block. This leads to an error in the block.rangeMap[lineInCode].indent access, as block.rangeMap[lineInCode] evaluates to undefined. I am willing to create an PR for this.

Minimal Reproduction

Markdown (I had to create an invalid document as the markdown renderer does not support nested code blocks):

Empty code block:
`` `js
`` `

Rule:

export default {
    create(context) {
        return {
            Program() {
                context.report({ message: 'message', loc: { start: { line: 2, column: 1 } } })
            }
        };
    }
}
nzakas commented 7 months ago

Thanks for reporting this. It's definitely a bug we should get fixed. Please feel free to submit a PR.