From 3995c09d52c190edfdb2ecb78f9ee0b18439de2e Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Sat, 28 Mar 2020 17:49:28 +0100 Subject: [PATCH 1/3] Only report warnings via the reporter --- .../com/sksamuel/scapegoat/Feedback.scala | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/main/scala/com/sksamuel/scapegoat/Feedback.scala b/src/main/scala/com/sksamuel/scapegoat/Feedback.scala index cee3e343..87d82d2a 100644 --- a/src/main/scala/com/sksamuel/scapegoat/Feedback.scala +++ b/src/main/scala/com/sksamuel/scapegoat/Feedback.scala @@ -56,17 +56,17 @@ class Feedback( inspection = inspection.getClass.getCanonicalName ) warningsBuffer.append(warning) + if (shouldPrint(warning)) { - println(s"[${warning.level.toString.toLowerCase}] $sourceFileNormalized:${warning.line}: $text") - println(s" $explanation") - snippet.foreach(s => println(s" $s")) - println() - } + val snippetText = snippet.fold("")("\n " + _ + "\n") + val report = s"""|[scapegoat] $text + | $explanation$snippetText""".stripMargin - adjustedLevel match { - case Levels.Error => reporter.error(pos, text) - case Levels.Warning => reporter.warning(pos, text) - case Levels.Info => reporter.info(pos, text, force = false) + adjustedLevel match { + case Levels.Error => reporter.error(pos, report) + case Levels.Warning => reporter.warning(pos, report) + case Levels.Info => reporter.info(pos, report, force = false) + } } } From 0f2aa4eb38817cd83cb132218f3cb347952ea94c Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Sat, 28 Mar 2020 23:03:06 +0100 Subject: [PATCH 2/3] Fix tests --- .../com/sksamuel/scapegoat/FeedbackTest.scala | 21 ++++++++++++------- .../collections/MapGetAndGetOrElseTest.scala | 3 ++- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/test/scala/com/sksamuel/scapegoat/FeedbackTest.scala b/src/test/scala/com/sksamuel/scapegoat/FeedbackTest.scala index a05198a1..af7390ac 100644 --- a/src/test/scala/com/sksamuel/scapegoat/FeedbackTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/FeedbackTest.scala @@ -32,9 +32,11 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit "This is explanation." ) val reporter = new StoreReporter - val feedback = new Feedback(false, reporter, defaultSourcePrefix) + val feedback = new Feedback(true, reporter, defaultSourcePrefix) feedback.warn(position, inspection) - reporter.infos should contain(reporter.Info(position, "My default is Error", reporter.ERROR)) + reporter.infos should contain( + reporter.Info(position, "[scapegoat] My default is Error\n This is explanation.", reporter.ERROR) + ) } "for warning" in { val inspection = new DummyInspection( @@ -44,9 +46,12 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit "This is explanation." ) val reporter = new StoreReporter - val feedback = new Feedback(false, reporter, defaultSourcePrefix) + val feedback = new Feedback(true, reporter, defaultSourcePrefix) feedback.warn(position, inspection) - reporter.infos should contain(reporter.Info(position, "My default is Warning", reporter.WARNING)) + reporter.infos should contain( + reporter + .Info(position, "[scapegoat] My default is Warning\n This is explanation.", reporter.WARNING) + ) } "for info" in { val inspection = new DummyInspection( @@ -56,9 +61,11 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit "This is explanation." ) val reporter = new StoreReporter - val feedback = new Feedback(false, reporter, defaultSourcePrefix) + val feedback = new Feedback(true, reporter, defaultSourcePrefix) feedback.warn(position, inspection) - reporter.infos should contain(reporter.Info(position, "My default is Info", reporter.INFO)) + reporter.infos should contain( + reporter.Info(position, "[scapegoat] My default is Info\n This is explanation.", reporter.INFO) + ) } } "should use proper paths" - { @@ -111,7 +118,7 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit ) val inspections = Seq(inspectionError, inspectionWarning, inspectionInfo) val reporter = new StoreReporter - val feedback = new Feedback(false, reporter, defaultSourcePrefix, Levels.Info) + val feedback = new Feedback(true, reporter, defaultSourcePrefix, Levels.Info) inspections.foreach(inspection => feedback.warn(position, inspection)) feedback.warningsWithMinimalLevel.length should be(3) } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/MapGetAndGetOrElseTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/MapGetAndGetOrElseTest.scala index a1a9582b..8b163ab5 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/MapGetAndGetOrElseTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/MapGetAndGetOrElseTest.scala @@ -1,10 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections import com.sksamuel.scapegoat.PluginRunner +import org.scalatest.OneInstancePerTest import org.scalatest.freespec.AnyFreeSpec import org.scalatest.matchers.should.Matchers -class MapGetAndGetOrElseTest extends AnyFreeSpec with Matchers with PluginRunner { +class MapGetAndGetOrElseTest extends AnyFreeSpec with Matchers with PluginRunner with OneInstancePerTest { override val inspections = Seq(new MapGetAndGetOrElse) From 27b722509fd9c2f832b4c65da9603153d6ed93d9 Mon Sep 17 00:00:00 2001 From: Claudio Bley Date: Sun, 29 Mar 2020 09:15:07 +0200 Subject: [PATCH 3/3] Enable reports during compilation by default --- src/main/scala/com/sksamuel/scapegoat/plugin.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/com/sksamuel/scapegoat/plugin.scala b/src/main/scala/com/sksamuel/scapegoat/plugin.scala index b9c36b9e..5092a162 100644 --- a/src/main/scala/com/sksamuel/scapegoat/plugin.scala +++ b/src/main/scala/com/sksamuel/scapegoat/plugin.scala @@ -160,7 +160,7 @@ class ScapegoatComponent(val global: Global, inspections: Seq[Inspection]) var disabledInspections: List[String] = Nil var enabledInspections: List[String] = Nil var ignoredFiles: List[String] = Nil - var consoleOutput: Boolean = false + var consoleOutput: Boolean = true var verbose: Boolean = false val debug: Boolean = false var summary: Boolean = true