diff --git a/lib/processor.js b/lib/processor.js index 4cf6a71f..788ded3a 100644 --- a/lib/processor.js +++ b/lib/processor.js @@ -331,7 +331,7 @@ function adjustBlock(block) { const lineInCode = message.line - leadingCommentLines; - if (lineInCode < 1) { + if (lineInCode < 1 || lineInCode >= block.rangeMap.length) { return null; } diff --git a/tests/lib/processor.js b/tests/lib/processor.js index 629c448e..be66c9f6 100644 --- a/tests/lib/processor.js +++ b/tests/lib/processor.js @@ -755,6 +755,17 @@ describe("processor", () => { }); }); + it("should ignore messages after the code block", () => { + const empty = [ + '```javascript', + '```', + ].join('\n'); + processor.preprocess(empty, 'empty.md'); + const message = { message: 'Empty file', ruleId: null, line: 2 }; + const result = processor.postprocess([[message]], 'empty.md'); + + assert.deepStrictEqual(result, []); + }); }); describe("supportsAutofix", () => {