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

Decorate code in html report #779

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions src/main/scala/com/sksamuel/scapegoat/io/HtmlReportWriter.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.sksamuel.scapegoat.io

import scala.xml.{Elem, Unparsed}
import scala.xml.{Elem, Unparsed, XML}

import com.sksamuel.scapegoat.{Feedback, Levels}

Expand Down Expand Up @@ -38,13 +38,13 @@ object HtmlReportWriter extends ReportWriter {
| }
|
| .title {
| color: #616161;
| font-size: 16px;
| color: #616161;
| font-size: 16px;
| }
|
| .source {
| float: right;
| font-style: italic;
| font-style: italic;
| color: #868686;
| }
|
Expand All @@ -55,6 +55,12 @@ object HtmlReportWriter extends ReportWriter {
| font-size: 12px;
| }
|
| code {
| color: #0C0C0C;
| font-weight: 300;
| font-size: 12px;
| }
|
| .inspection {
| padding-left: 10px;
| font-style:italic;
Expand Down Expand Up @@ -111,12 +117,12 @@ object HtmlReportWriter extends ReportWriter {
case Levels.Warning => <span class="label label-warning">Warning</span>
case Levels.Error => <span class="label label-danger">Error</span>
}
}&nbsp;{warning.text}&nbsp; <span class="inspection">
}&nbsp;{decorateCode(warning.text)}&nbsp; <span class="inspection">
{warning.inspection}
</span>
</div>
<div>
{warning.explanation}
{decorateCode(warning.explanation)}
</div>{
warning.snippet match {
case None =>
Expand All @@ -135,5 +141,8 @@ object HtmlReportWriter extends ReportWriter {
{header}{body(reporter)}
</html>

private def decorateCode(text: String): Elem =
XML.loadString(s"<span>${text.replaceAll("`([^`]*)`", "<code>$1</code>")}</span>")

override protected def generate(feedback: Feedback): String = toHTML(feedback).toString()
}