From b441e0a0708fc8e1fe87d5b829c6cb95314e250d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bendix=20S=C3=A4ltz?= Date: Tue, 10 May 2022 08:43:35 +0200 Subject: [PATCH] Fix: Inform about Boolean Parameters not for case class initializer (#649) --- build.sbt | 2 +- .../sksamuel/scapegoat/inspections/BooleanParameter.scala | 3 ++- .../scapegoat/inspections/BooleanParameterTest.scala | 7 +++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index aebd0733..f4c54f3a 100644 --- a/build.sbt +++ b/build.sbt @@ -22,7 +22,7 @@ developers := List( ) ) -scalaVersion := "2.13.7" +scalaVersion := "2.13.8" crossScalaVersions := Seq("2.11.12", "2.12.14", "2.12.15", "2.13.7", "2.13.8") autoScalaLibrary := false crossVersion := CrossVersion.full diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/BooleanParameter.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/BooleanParameter.scala index 3329ff5f..aee73563 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/BooleanParameter.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/BooleanParameter.scala @@ -34,7 +34,8 @@ class BooleanParameter case DefDef(mods, _, _, _, _, _) if mods.hasFlag(Flags.ACCESSOR) => // ignore overridden methods as the parent will receive the warning case DefDef(mods, _, _, _, _, _) if mods.isOverride => - case DefDef(_, _, _, vparamss, _, _) if hasBooleanParameter(vparamss) => + case DefDef(_, name, _, vparamss, _, _) + if hasBooleanParameter(vparamss) && name != TermName("") => context.warn(tree.pos, self, tree.toString.take(300)) case _ => continue(tree) } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/BooleanParameterTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/BooleanParameterTest.scala index 81dcfb18..59d78803 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/BooleanParameterTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/BooleanParameterTest.scala @@ -16,6 +16,13 @@ class BooleanParameterTest extends InspectionTest { compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } + + "not for case classes using Boolean parameter" in { + val code = """final case class Test(bool: Boolean)""".stripMargin + + compileCodeSnippet(code) + compiler.scapegoat.feedback.warnings.size shouldBe 0 + } } } }