Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Allow HTML formatter to handle no meta data #11566

Merged
merged 1 commit into from Mar 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/formatters/html.js
Expand Up @@ -119,6 +119,8 @@ module.exports = function(results, data) {
let totalErrors,
totalWarnings;

const metaData = data ? data.rulesMeta : {};

totalErrors = 0;
totalWarnings = 0;

Expand All @@ -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)
});
};
15 changes: 15 additions & 0 deletions tests/lib/formatters/html.js
Expand Up @@ -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", () => {
Expand Down