Skip to content

Commit 00adccb

Browse files
authoredApr 1, 2024··
fix: check upper bounds of message line numbers for code blocks (#247)
* fix: check upper bounds of message line numbers for code blocks * chore: run lint
1 parent bb5c3d4 commit 00adccb

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed
 

‎lib/processor.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ function adjustBlock(block) {
331331

332332
const lineInCode = message.line - leadingCommentLines;
333333

334-
if (lineInCode < 1) {
334+
if (lineInCode < 1 || lineInCode >= block.rangeMap.length) {
335335
return null;
336336
}
337337

‎tests/lib/processor.js

+12
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,18 @@ describe("processor", () => {
755755
});
756756
});
757757

758+
it("should ignore messages after the code block", () => {
759+
const empty = [
760+
"```javascript",
761+
"```"
762+
].join("\n");
763+
764+
processor.preprocess(empty, "empty.md");
765+
const message = { message: "Empty file", ruleId: null, line: 2 };
766+
const result = processor.postprocess([[message]], "empty.md");
767+
768+
assert.deepStrictEqual(result, []);
769+
});
758770
});
759771

760772
describe("supportsAutofix", () => {

0 commit comments

Comments
 (0)
Please sign in to comment.