Skip to content

Commit

Permalink
fix: check upper bounds of message line numbers for code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
DMartens committed Mar 27, 2024
1 parent bb5c3d4 commit 6abc764
Show file tree
Hide file tree
Showing 2 changed files with 12 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
11 changes: 11 additions & 0 deletions tests/lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,17 @@ describe("processor", () => {
});
});

it("should ignore messages after the code block", () => {
const empty = [
'```javascript',

Check failure on line 760 in tests/lib/processor.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use doublequote
'```',

Check failure on line 761 in tests/lib/processor.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use doublequote

Check failure on line 761 in tests/lib/processor.js

View workflow job for this annotation

GitHub Actions / Lint

Unexpected trailing comma
].join('\n');

Check failure on line 762 in tests/lib/processor.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use doublequote
processor.preprocess(empty, 'empty.md');

Check failure on line 763 in tests/lib/processor.js

View workflow job for this annotation

GitHub Actions / Lint

Expected blank line before this statement

Check failure on line 763 in tests/lib/processor.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use doublequote
const message = { message: 'Empty file', ruleId: null, line: 2 };

Check failure on line 764 in tests/lib/processor.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use doublequote
const result = processor.postprocess([[message]], 'empty.md');

Check failure on line 765 in tests/lib/processor.js

View workflow job for this annotation

GitHub Actions / Lint

Strings must use doublequote

assert.deepStrictEqual(result, []);
});
});

describe("supportsAutofix", () => {
Expand Down

0 comments on commit 6abc764

Please sign in to comment.