From e1a495a4ff4f47e3e5a4603c620502ea9115feab Mon Sep 17 00:00:00 2001 From: haya14busa Date: Wed, 22 Jul 2020 04:30:16 +0000 Subject: [PATCH] Fix: Do not output `undefined` as line and column when it's unavailable --- lib/cli-engine/formatters/checkstyle.js | 4 ++-- tests/lib/cli-engine/formatters/checkstyle.js | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/lib/cli-engine/formatters/checkstyle.js b/lib/cli-engine/formatters/checkstyle.js index ba4d1b5b3ec..f19b6fc0957 100644 --- a/lib/cli-engine/formatters/checkstyle.js +++ b/lib/cli-engine/formatters/checkstyle.js @@ -42,8 +42,8 @@ module.exports = function(results) { messages.forEach(message => { output += [ - `` diff --git a/tests/lib/cli-engine/formatters/checkstyle.js b/tests/lib/cli-engine/formatters/checkstyle.js index 2a72da15ece..218b15310ab 100644 --- a/tests/lib/cli-engine/formatters/checkstyle.js +++ b/tests/lib/cli-engine/formatters/checkstyle.js @@ -151,4 +151,21 @@ describe("formatter:checkstyle", () => { assert.strictEqual(result, ""); }); }); + + describe("when passing single message without line and column", () => { + const code = [{ + filePath: "foo.js", + messages: [{ + message: "Unexpected foo.", + severity: 2, + ruleId: "foo" + }] + }]; + + it("should return line and column as 0 instead of undefined", () => { + const result = formatter(code); + + assert.strictEqual(result, ""); + }); + }); });