diff --git a/lib/formatters/html.js b/lib/formatters/html.js
index 71b46cf5cfc..091eab1c4ad 100644
--- a/lib/formatters/html.js
+++ b/lib/formatters/html.js
@@ -119,6 +119,8 @@ module.exports = function(results, data) {
let totalErrors,
totalWarnings;
+ const metaData = data ? data.rulesMeta : {};
+
totalErrors = 0;
totalWarnings = 0;
@@ -132,6 +134,6 @@ module.exports = function(results, data) {
date: new Date(),
reportColor: renderColor(totalErrors, totalWarnings),
reportSummary: renderSummary(totalErrors, totalWarnings),
- results: renderResults(results, data.rulesMeta)
+ results: renderResults(results, metaData)
});
};
diff --git a/tests/lib/formatters/html.js b/tests/lib/formatters/html.js
index ab829234e99..c9f97a2cf05 100644
--- a/tests/lib/formatters/html.js
+++ b/tests/lib/formatters/html.js
@@ -115,6 +115,21 @@ describe("formatter:html", () => {
checkHeaderRow($, $("tr")[0], { bgColor: "bg-2", group: "f-0", file: "foo.js", problems: "1 problem (1 error, 0 warnings)" });
checkContentRow($, $("tr")[1], { group: "f-0", lineCol: "5:10", color: "clr-2", message: "Unexpected foo.", ruleId: "foo" });
});
+
+ it("should not fail if metadata is not available", () => {
+ const result = formatter(code.results);
+
+ const $ = cheerio.load(result);
+
+ // Check overview
+ checkOverview($, { bgColor: "bg-2", problems: "1 problem (1 error, 0 warnings)" });
+
+ // Check rows
+ assert.strictEqual($("tr").length, 2, "Check that there are two (1 header, 1 content)");
+ assert.strictEqual($("tr[data-group|=\"f\"]").length, 1, "Check that is 1 header row (implying 1 content row)");
+ checkHeaderRow($, $("tr")[0], { bgColor: "bg-2", group: "f-0", file: "foo.js", problems: "1 problem (1 error, 0 warnings)" });
+ checkContentRow($, $("tr")[1], { group: "f-0", lineCol: "5:10", color: "clr-2", message: "Unexpected foo.", ruleId: "foo" });
+ });
});
describe("when passed a single warning message", () => {