Skip to content

Commit

Permalink
Fix: Don't require message end locations (fixes #112) (#154)
Browse files Browse the repository at this point in the history
Issue #112 reported VSCode drawing squigglies all the way from the top
of a file to a line in a code block with a syntax error rather than just
squigglying the line with the syntax error. For messages that only
specified start locations, the processor was adding `endLine: NaN`.
  • Loading branch information
btmills authored Aug 2, 2020
1 parent 2bc9352 commit 0311640
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
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

0 comments on commit 0311640

Please sign in to comment.