From 318fe103dbf2548eee293ff456ef0b829dbe3db3 Mon Sep 17 00:00:00 2001 From: haya14busa Date: Sat, 1 Aug 2020 07:37:52 +0900 Subject: [PATCH] Fix: Do not output `undefined` as line and column when it's unavailable (#13519) --- 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, ""); + }); + }); });