Skip to content

Commit

Permalink
Fix: message.line could be undefined (#191)
Browse files Browse the repository at this point in the history
* Fix: `message.line` could be `undefined`

* Chore: change line/column for better experience

* Update tests/lib/processor.js

Co-authored-by: Brandon Mills <[email protected]>

Co-authored-by: Brandon Mills <[email protected]>
  • Loading branch information
JounQin and btmills authored Sep 12, 2021
1 parent 89ea838 commit 3a40160
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
7 changes: 7 additions & 0 deletions lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,13 @@ function adjustBlock(block) {
* @returns {Message} The same message, but adjusted to the correct location.
*/
return function adjustMessage(message) {
if (!Number.isInteger(message.line)) {
return {
...message,
line: blockStart,
column: block.position.start.column
};
}

const lineInCode = message.line - leadingCommentLines;

Expand Down
1 change: 0 additions & 1 deletion tests/examples/all.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"use strict";

const assert = require("chai").assert;
const execSync = require("child_process").execSync;
const fs = require("fs");
const path = require("path");
const semver = require("semver");
Expand Down
22 changes: 22 additions & 0 deletions tests/lib/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,28 @@ describe("processor", () => {

});

it("should attach messages without `line` to opening code fence", () => {
const message = { message: "Parsing error: \"parserOptions.project\" has been set for @typescript-eslint/parser.", ruleId: null };
const result = processor.postprocess([[message], [message], [message]]);

assert.strictEqual(result.length, 3);
assert.deepStrictEqual(result[0], {
...message,
line: 3,
column: 1
});
assert.deepStrictEqual(result[1], {
...message,
line: 14,
column: 4
});
assert.deepStrictEqual(result[2], {
...message,
line: 23,
column: 3
});
});

});

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

0 comments on commit 3a40160

Please sign in to comment.