Skip to content

Commit

Permalink
ignore level
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene-sy committed Sep 9, 2023
1 parent 756847b commit ad10ca5
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 10 deletions.
7 changes: 4 additions & 3 deletions src/main/scala/com/sksamuel/scapegoat/Feedback.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ final case class Warning(
) {
def hasMinimalLevelOf(minimalLevel: Level): Boolean = {
minimalLevel match {
case Levels.Info => true
case Levels.Warning => this.level == Levels.Warning || this.level == Levels.Error
case Levels.Error => this.level == Levels.Error
case Levels.Ignore => throw new IllegalArgumentException("Ignore cannot be minimal level")
case Levels.Info => this.level.higherOrEqualTo(Levels.Info)
case Levels.Warning => this.level.higherOrEqualTo(Levels.Warning)
case Levels.Error => this.level.higherOrEqualTo(Levels.Error)
}
}
}
23 changes: 19 additions & 4 deletions src/main/scala/com/sksamuel/scapegoat/Level.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ package com.sksamuel.scapegoat
* @author
* Stephen Samuel
*/
sealed trait Level
sealed trait Level {
protected def weight: Short

def higherOrEqualTo(other: Level): Boolean = this.weight >= other.weight
}

object Levels {

Expand All @@ -13,7 +17,9 @@ object Levels {
*
* An example is use of nulls. Use of nulls can lead to NullPointerExceptions and should be avoided.
*/
case object Error extends Level
case object Error extends Level {
override protected def weight: Short = 30
}

/**
* Warnings are reserved for code that has bad semantics. This by itself does not necessarily mean the code
Expand All @@ -26,7 +32,9 @@ object Levels {
* Another example is a constant if. You can do things like if (true) { } if you want, but since the block
* will always evaluate, the if statement perhaps indicates a mistake.
*/
case object Warning extends Level
case object Warning extends Level {
override protected def weight: Short = 20
}

/**
* Infos are used for code which is semantically fine, but there exists a more idomatic way of writing it.
Expand All @@ -43,13 +51,20 @@ object Levels {
*
* def foo = a
*/
case object Info extends Level
case object Info extends Level {
override protected def weight: Short = 10
}

case object Ignore extends Level {
override protected def weight: Short = 0
}

def fromName(name: String): Level =
name.toLowerCase() match {
case "error" => Error
case "warning" => Warning
case "info" => Info
case "ignore" => Ignore
case _ => throw new IllegalArgumentException(s"Unrecognised level '$name'")
}
}
24 changes: 21 additions & 3 deletions src/test/scala/com/sksamuel/scapegoat/FeedbackTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,13 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit
"This is description.",
"This is explanation."
)
val inspections = Seq(inspectionError, inspectionWarning, inspectionInfo)
val inspectionIgnored = new DummyInspection(
"My default is Ignore",
Levels.Ignore,
"This is description.",
"This is explanation."
)
val inspections = Seq(inspectionError, inspectionWarning, inspectionInfo, inspectionIgnored)
val reporter = new StoreReporter(new Settings())
val feedback =
new Feedback(reporter, testConfiguration(consoleOutput = true, defaultSourcePrefix, Levels.Info))
Expand All @@ -159,7 +165,13 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit
"This is description.",
"This is explanation."
)
val inspections = Seq(inspectionError, inspectionWarning, inspectionInfo)
val inspectionIgnored = new DummyInspection(
"My default is Ignore",
Levels.Ignore,
"This is description.",
"This is explanation."
)
val inspections = Seq(inspectionError, inspectionWarning, inspectionInfo, inspectionIgnored)
val reporter = new StoreReporter(new Settings())
val feedback =
new Feedback(
Expand Down Expand Up @@ -191,7 +203,13 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit
"This is description.",
"This is explanation."
)
val inspections = Seq(inspectionError, inspectionWarning, inspectionInfo)
val inspectionIgnored = new DummyInspection(
"My default is Ignore",
Levels.Ignore,
"This is description.",
"This is explanation."
)
val inspections = Seq(inspectionError, inspectionWarning, inspectionInfo, inspectionIgnored)
val reporter = new StoreReporter(new Settings())
val feedback =
new Feedback(reporter, testConfiguration(consoleOutput = false, defaultSourcePrefix, Levels.Error))
Expand Down

0 comments on commit ad10ca5

Please sign in to comment.