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 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/processor.js
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
Expand Up @@ -755,6 +755,17 @@
});
});

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