-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved reports, markdown report (#376)
* draft interface * refactor reporters * markdown reporter * clean up report execution * readme and accidental changes * scalafix
- Loading branch information
Showing
12 changed files
with
123 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,22 @@ | ||
package com.sksamuel.scapegoat.io | ||
|
||
import java.io.{BufferedWriter, File, FileWriter} | ||
import java.io.File | ||
|
||
import com.sksamuel.scapegoat.Feedback | ||
|
||
/** | ||
* @author Stephen Samuel | ||
* @author Eugene Sypachev (Axblade) | ||
*/ | ||
object IOUtils { | ||
def writeHTMLReport(targetDir: File, reporter: Feedback): File = | ||
HtmlReportWriter.write(targetDir, reporter) | ||
|
||
private val XmlFile = "scapegoat.xml" | ||
private val ScalastyleXmlFile = "scapegoat-scalastyle.xml" | ||
private val HtmlFile = "scapegoat.html" | ||
def writeXMLReport(targetDir: File, reporter: Feedback): File = | ||
XmlReportWriter.write(targetDir, reporter) | ||
|
||
def serialize(file: File, str: String) = { | ||
val out = new BufferedWriter(new FileWriter(file)) | ||
out.write(str) | ||
out.close() | ||
} | ||
|
||
def writeHTMLReport(targetDir: File, reporter: Feedback): File = { | ||
val html = HtmlReportWriter.generate(reporter).toString() | ||
writeFile(targetDir, html, HtmlFile) | ||
} | ||
|
||
def writeXMLReport(targetDir: File, reporter: Feedback): File = { | ||
val xml = XmlReportWriter.toXML(reporter).toString() | ||
writeFile(targetDir, xml, XmlFile) | ||
} | ||
|
||
def writeScalastyleReport(targetDir: File, reporter: Feedback): File = { | ||
val xml = ScalastyleReportWriter.toXML(reporter).toString() | ||
writeFile(targetDir, xml, ScalastyleXmlFile) | ||
} | ||
|
||
private def writeFile(targetDir: File, data: String, fileName: String) = { | ||
targetDir.mkdirs() | ||
val file = new File(targetDir.getAbsolutePath + "/" + fileName) | ||
serialize(file, data) | ||
file | ||
} | ||
def writeScalastyleReport(targetDir: File, reporter: Feedback): File = | ||
ScalastyleReportWriter.write(targetDir, reporter) | ||
|
||
def writeMarkdownReport(targetDir: File, reporter: Feedback): File = | ||
MarkdownReportWriter.write(targetDir, reporter) | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/scala/com/sksamuel/scapegoat/io/MarkdownReportWriter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.sksamuel.scapegoat.io | ||
|
||
import com.sksamuel.scapegoat.{Feedback, Levels, Warning} | ||
|
||
object MarkdownReportWriter extends ReportWriter { | ||
override protected def fileName: String = "scapegoat.md" | ||
|
||
override protected def generate(reporter: Feedback): String = { | ||
s"""# Scapegoat Inspections | ||
| | ||
|**Errors**: ${reporter.warnings(Levels.Error).size.toString} | ||
| | ||
|**Warnings**: ${reporter.warnings(Levels.Warning).size.toString} | ||
| | ||
|**Infos**: ${reporter.warnings(Levels.Info).size.toString} | ||
| | ||
|## Report | ||
| | ||
|${renderAll(reporter)} | ||
|""".stripMargin | ||
} | ||
|
||
private def renderAll(reporter: Feedback): String = | ||
reporter.warningsWithMinimalLevel.map(renderWarning).mkString("\n") | ||
|
||
private def renderWarning(warning: Warning): String = { | ||
val source = warning.sourceFileNormalized + ":" + warning.line | ||
val md = | ||
s"""### $source | ||
| | ||
|**Level**: ${warning.level.toString} | ||
| | ||
|**Inspection**: ${warning.inspection} | ||
| | ||
|${warning.text} | ||
| | ||
|${warning.explanation} | ||
| | ||
|${warning.snippet.map(snippet => s"\n```scala\n$snippet\n```").getOrElse("")} | ||
|""".stripMargin | ||
md | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/scala/com/sksamuel/scapegoat/io/ReportWriter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.sksamuel.scapegoat.io | ||
|
||
import java.io.{BufferedWriter, File, FileWriter} | ||
|
||
import com.sksamuel.scapegoat.Feedback | ||
|
||
trait ReportWriter { | ||
|
||
protected def fileName: String | ||
|
||
protected def generate(feedback: Feedback): String | ||
|
||
private def serialize(file: File, str: String): Unit = { | ||
val out = new BufferedWriter(new FileWriter(file)) | ||
out.write(str) | ||
out.close() | ||
} | ||
|
||
def write(targetDir: File, feedback: Feedback): File = { | ||
targetDir.mkdirs() | ||
val file = new File(s"${targetDir.getAbsolutePath}/$fileName") | ||
serialize(file, generate(feedback)) | ||
file | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters