From 6ccbb79cd0ddff9e337d5a5fc97bdb4810656f4b Mon Sep 17 00:00:00 2001 From: Bilie Date: Tue, 23 Oct 2018 22:45:31 +0200 Subject: [PATCH] Fix SyntaxError when an empty string is used for a rule's custom message --- .../__tests__/stringFormatter.test.js | 26 +++++++++++++++++++ lib/formatters/stringFormatter.js | 2 +- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/lib/formatters/__tests__/stringFormatter.test.js b/lib/formatters/__tests__/stringFormatter.test.js index 37f73df3fa..ee258b2e23 100644 --- a/lib/formatters/__tests__/stringFormatter.test.js +++ b/lib/formatters/__tests__/stringFormatter.test.js @@ -182,4 +182,30 @@ describe("stringFormatter", () => { expect(output).toBe(""); }); + + it("handles empty messages", () => { + const results = [ + { + source: "path/to/file.css", + errored: true, + warnings: [ + { + line: 1, + column: 1, + rule: "bar", + severity: "error", + text: "" + } + ], + deprecations: [], + invalidOptionWarnings: [] + } + ]; + + const output = prepareFormatterOutput(results, stringFormatter); + + expect(output).toBe(stripIndent` + path/to/file.css + 1:1 × bar`); + }); }); diff --git a/lib/formatters/stringFormatter.js b/lib/formatters/stringFormatter.js index 57bcf9e9c4..0e9632234f 100644 --- a/lib/formatters/stringFormatter.js +++ b/lib/formatters/stringFormatter.js @@ -145,7 +145,7 @@ function formatter(messages, source) { 3: { alignment: "left", width: getMessageWidth(columnWidths), - wrapWord: true + wrapWord: getMessageWidth(columnWidths) > 1 }, 4: { alignment: "left", width: columnWidths[4], paddingRight: 0 } },