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: Don't require message end locations (fixes #112) #154

Merged
merged 1 commit into from
Aug 2, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,18 +279,20 @@ function adjustBlock(block) {
return function adjustMessage(message) {

const lineInCode = message.line - leadingCommentLines;
const endLine = message.endLine - leadingCommentLines;

if (lineInCode < 1) {
return null;
}

const out = {
line: lineInCode + blockStart,
endLine: endLine ? endLine + blockStart : endLine,
column: message.column + block.position.indent[lineInCode - 1] - 1
};

if (Number.isInteger(message.endLine)) {
out.endLine = message.endLine - leadingCommentLines + blockStart;
}

const adjustedFix = {};

if (message.fix) {
Expand Down
14 changes: 14 additions & 0 deletions tests/lib/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ describe("plugin", () => {
assert.strictEqual(report.results[0].messages[1].endLine, 8);
});

it("doesn't add end locations to messages without them", () => {
const code = [
"```js",
"!@#$%^&*()",
"```"
].join("\n");
const report = cli.executeOnText(code, "test.md");

assert.strictEqual(report.results.length, 1);
assert.strictEqual(report.results[0].messages.length, 1);
assert.notProperty(report.results[0].messages[0], "endLine");
assert.notProperty(report.results[0].messages[0], "endColumn");
});

it("should emit correct line numbers with leading comments", () => {
const code = [
"# Hello, world!",
Expand Down