Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: check upper bounds of message line numbers for code blocks #247

Merged
merged 2 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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