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

Log the name of the Inspection #443

Merged
merged 1 commit into from
Oct 26, 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
3 changes: 2 additions & 1 deletion src/main/scala/com/sksamuel/scapegoat/Feedback.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Feedback(
): Unit = {
val level = inspection.defaultLevel
val text = inspection.text
val name = inspection.name
val explanation = adhocExplanation.getOrElse(inspection.explanation)
val adjustedLevel = (
levelOverridesByInspectionSimpleName.get("all"),
Expand All @@ -61,7 +62,7 @@ class Feedback(

if (shouldPrint(warning)) {
val snippetText = snippet.fold("")("\n " + _ + "\n")
val report = s"""[scapegoat] $text
val report = s"""[scapegoat] [$name] $text
| $explanation$snippetText""".stripMargin

adjustedLevel match {
Expand Down
2 changes: 2 additions & 0 deletions src/main/scala/com/sksamuel/scapegoat/Inspection.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ abstract class Inspection(
def inspector(context: InspectionContext): Inspector

def isEnabled: Boolean = true

def name: String = getClass.getSimpleName
}

abstract class Inspector(val context: InspectionContext) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/scala/com/sksamuel/scapegoat/plugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ class ScapegoatComponent(val global: Global, inspections: Seq[Inspection])
def activeInspections: Seq[Inspection] = {
if (enabledInspections.isEmpty)
(inspections ++ customInpections)
.filterNot(inspection => disabledInspections.contains(inspection.getClass.getSimpleName))
.filterNot(inspection => disabledInspections.contains(inspection.name))
else
(inspections ++ customInpections)
.filter(inspection => enabledInspections.contains(inspection.getClass.getSimpleName))
.filter(inspection => enabledInspections.contains(inspection.name))
}
lazy val feedback = new Feedback(consoleOutput, global.reporter, sourcePrefix, minimalLevel)

Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/com/sksamuel/scapegoat/FeedbackTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit
val feedback = new Feedback(true, reporter, defaultSourcePrefix)
feedback.warn(position, inspection)
reporter.infos should contain(
reporter.Info(position, "[scapegoat] My default is Error\n This is explanation.", reporter.ERROR)
reporter.Info(position, "[scapegoat] [DummyInspection] My default is Error\n This is explanation.", reporter.ERROR)
)
}
"for warning" in {
Expand All @@ -50,7 +50,7 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit
feedback.warn(position, inspection)
reporter.infos should contain(
reporter
.Info(position, "[scapegoat] My default is Warning\n This is explanation.", reporter.WARNING)
.Info(position, "[scapegoat] [DummyInspection] My default is Warning\n This is explanation.", reporter.WARNING)
)
}
"for info" in {
Expand All @@ -64,7 +64,7 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit
val feedback = new Feedback(true, reporter, defaultSourcePrefix)
feedback.warn(position, inspection)
reporter.infos should contain(
reporter.Info(position, "[scapegoat] My default is Info\n This is explanation.", reporter.INFO)
reporter.Info(position, "[scapegoat] [DummyInspection] My default is Info\n This is explanation.", reporter.INFO)
)
}
}
Expand Down