Skip to content

Commit

Permalink
fix: check upper bounds of message line numbers for code blocks (#247)
Browse files Browse the repository at this point in the history
* fix: check upper bounds of message line numbers for code blocks

* chore: run lint
  • Loading branch information
DMartens committed Apr 1, 2024
1 parent bb5c3d4 commit 00adccb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function adjustBlock(block) {

const lineInCode = message.line - leadingCommentLines;

if (lineInCode < 1) {
if (lineInCode < 1 || lineInCode >= block.rangeMap.length) {
return null;
}

Expand Down
12 changes: 12 additions & 0 deletions tests/lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,18 @@ 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", () => {
Expand Down

0 comments on commit 00adccb

Please sign in to comment.