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

Only report warnings via the reporter #326

Merged
merged 3 commits into from
Mar 29, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/main/scala/com/sksamuel/scapegoat/Feedback.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/com/sksamuel/scapegoat/plugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 14 additions & 7 deletions src/test/scala/com/sksamuel/scapegoat/FeedbackTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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" - {
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it mean we need with OneInstancePerTest everywhere now?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all the other ones are run in their own instances due to the shared state from PluginRunner, so this brings this in line with all the other inspection tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly, only I don't understand why this did not fail before... ?!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I'm also not sure

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not the only one which misses that trait, let me unify that in a separate PR


override val inspections = Seq(new MapGetAndGetOrElse)

Expand Down