From ca80c290d129a0099dd628c959f7be60371ae327 Mon Sep 17 00:00:00 2001 From: Hannes Kaeufler Date: Tue, 27 Nov 2018 21:31:08 +0100 Subject: [PATCH 1/5] Extract function for compound conditional --- source/runner/templates/githubIssueTemplate.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/runner/templates/githubIssueTemplate.ts b/source/runner/templates/githubIssueTemplate.ts index cfd6c8fdd..4c36fc1e6 100644 --- a/source/runner/templates/githubIssueTemplate.ts +++ b/source/runner/templates/githubIssueTemplate.ts @@ -12,7 +12,7 @@ import { Violation, isInline } from "../../dsl/Violation" * @returns {string} HTML */ function table(name: string, emoji: string, violations: Violation[]): string { - if (violations.length === 0 || violations.every(violation => !violation.message)) { + if (noViolationsOrAllOfThemEmpty(violations)) { return "" } return ` @@ -37,6 +37,10 @@ function table(name: string, emoji: string, violations: Violation[]): string { ` } +function noViolationsOrAllOfThemEmpty(violations: Violation[]) { + return violations.length === 0 || violations.every(violation => !violation.message) +} + function getSummary(label: string, violations: Violation[]): string { return violations .map(x => v.truncate(x.message, 20)) From c4fec1939df0f482da5ed95266778ccd732ab082 Mon Sep 17 00:00:00 2001 From: Hannes Kaeufler Date: Tue, 27 Nov 2018 22:30:36 +0100 Subject: [PATCH 2/5] Add back space for messages containing markdown. For github to render markdown in tables there has to be some space around the message. This will add a

and render the markdown. However, it also leads to some funky vertical spacing due to the nature of some browser styling for the

tag. This commit looks at the message to determine if it contains markdown, if yes, then add the space for proper rendering. If not, render the compacter table to get nice vertical alignment. --- .../_githubIssueTemplates.test.ts.snap | 57 +++++++++++++++++-- .../_tests/_githubIssueTemplates.test.ts | 13 ++++- .../runner/templates/githubIssueTemplate.ts | 30 +++++++--- 3 files changed, 85 insertions(+), 15 deletions(-) diff --git a/source/runner/templates/_tests/__snapshots__/_githubIssueTemplates.test.ts.snap b/source/runner/templates/_tests/__snapshots__/_githubIssueTemplates.test.ts.snap index 5325a21e6..9748f75eb 100644 --- a/source/runner/templates/_tests/__snapshots__/_githubIssueTemplates.test.ts.snap +++ b/source/runner/templates/_tests/__snapshots__/_githubIssueTemplates.test.ts.snap @@ -43,7 +43,10 @@ exports[`generating inline messages Shows correct messages for inline/regular vi :warning: - **File.swift#L10** - Test message + + + **File.swift#L10** - Test message + @@ -61,7 +64,40 @@ exports[`generating inline messages Shows correct messages for inline/regular vi " `; -exports[`generating messages leaves space between s to allow GitHub to render message content as markdown 1`] = ` +exports[`generating messages avoids adding space inside the for proper vertical alignment if the message does not contain any markdown 1`] = ` +" + + + + + + + + + + + + + + + + +
Messages
:book:no markdown here
+ + +

+ Generated by :no_entry_sign: dangerJS +

+" +`; + +exports[`generating messages leaves space between s to allow GitHub to render message content as markdown if the message contains any 1`] = ` "