From 0703cd5e92cb0a015859192f7f5e8fc1d3decbef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bendix=20S=C3=A4ltz?= Date: Mon, 18 Sep 2023 10:08:47 +0200 Subject: [PATCH] Support Scala 2.13.12 (#789) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Scala 2.13.12 * Renaming context to ctx to remove ambiguity * Explicit type declaration for postTyperTraverser * Declaring explicitly type of Seq[Inspection] in tests * Fix FeedbackTest * Exclude UnnecessaryConversion from Scala 2.13.12 --------- Co-authored-by: Grzegorz Olędzki --- .github/workflows/pr-checks.yml | 2 +- README.md | 2 +- build.sbt | 4 +- .../com/sksamuel/scapegoat/Inspection.scala | 2 +- .../scapegoat/inspections/AnyUse.scala | 4 +- .../inspections/AvoidToMinusOne.scala | 4 +- .../inspections/BooleanParameter.scala | 4 +- .../inspections/DoubleNegation.scala | 4 +- .../inspections/EmptyCaseClass.scala | 4 +- .../FinalModifierOnCaseClass.scala | 6 +- .../inspections/LonelySealedTrait.scala | 4 +- .../scapegoat/inspections/MaxParameters.scala | 4 +- .../scapegoat/inspections/NoOpOverride.scala | 4 +- .../inspections/PublicFinalizer.scala | 4 +- .../RedundantFinalModifierOnMethod.scala | 6 +- .../RedundantFinalModifierOnVar.scala | 6 +- .../scapegoat/inspections/TypeShadowing.scala | 4 +- .../scapegoat/inspections/VarClosure.scala | 4 +- .../scapegoat/inspections/VarUse.scala | 6 +- .../inspections/VariableShadowing.scala | 4 +- .../inspections/collections/ArrayEquals.scala | 4 +- .../collections/AvoidSizeEqualsZero.scala | 4 +- .../collections/AvoidSizeNotEqualsZero.scala | 4 +- .../CollectionIndexOnNonIndexedSeq.scala | 4 +- .../CollectionNamingConfusion.scala | 4 +- .../collections/CollectionNegativeIndex.scala | 4 +- .../CollectionPromotionToAny.scala | 4 +- .../collections/ComparisonToEmptyList.scala | 4 +- .../collections/ComparisonToEmptySet.scala | 4 +- .../collections/DuplicateMapKey.scala | 4 +- .../collections/DuplicateSetValue.scala | 4 +- .../ExistsSimplifiableToContains.scala | 4 +- .../collections/FilterDotHead.scala | 4 +- .../collections/FilterDotHeadOption.scala | 4 +- .../collections/FilterDotIsEmpty.scala | 4 +- .../collections/FilterDotSize.scala | 4 +- .../collections/FilterOptionAndGet.scala | 4 +- ...indAndNotEqualsNoneReplaceWithExists.scala | 6 +- .../collections/FindDotIsDefined.scala | 4 +- .../collections/JavaConversionsUse.scala | 4 +- .../inspections/collections/ListAppend.scala | 4 +- .../inspections/collections/ListSize.scala | 4 +- .../collections/MapGetAndGetOrElse.scala | 4 +- .../collections/NegationIsEmpty.scala | 4 +- .../collections/NegationNonEmpty.scala | 4 +- .../collections/NegativeSeqPad.scala | 4 +- .../collections/PredefIterableIsMutable.scala | 4 +- .../collections/PredefSeqIsMutable.scala | 4 +- .../PredefTraversableIsMutable.scala | 4 +- .../collections/PreferMapEmpty.scala | 6 +- .../collections/PreferSeqEmpty.scala | 4 +- .../collections/PreferSetEmpty.scala | 4 +- .../inspections/collections/ReverseFunc.scala | 4 +- .../collections/ReverseTailReverse.scala | 4 +- .../collections/ReverseTakeReverse.scala | 4 +- .../collections/SwapSortFilter.scala | 4 +- .../collections/UnsafeContains.scala | 4 +- .../UnsafeTraversableMethods.scala | 4 +- .../controlflow/RepeatedIfElseBody.scala | 6 +- .../inspections/controlflow/WhileTrue.scala | 4 +- .../inspections/empty/EmptyFor.scala | 4 +- .../inspections/empty/EmptyIfBlock.scala | 4 +- .../inspections/empty/EmptyMethod.scala | 4 +- .../empty/EmptySynchronizedBlock.scala | 4 +- .../inspections/empty/EmptyTryBlock.scala | 4 +- .../inspections/empty/EmptyWhileBlock.scala | 4 +- .../ComparingFloatingPointTypes.scala | 4 +- .../equality/ComparingUnrelatedTypes.scala | 4 +- .../equality/ComparisonWithSelf.scala | 4 +- .../exception/CatchException.scala | 4 +- .../CatchExceptionImmediatelyRethrown.scala | 4 +- .../inspections/exception/CatchFatal.scala | 4 +- .../inspections/exception/CatchNpe.scala | 4 +- .../exception/CatchThrowable.scala | 4 +- .../IncorrectlyNamedExceptions.scala | 4 +- .../exception/SwallowedException.scala | 4 +- .../exception/UnreachableCatch.scala | 4 +- .../inspections/imports/DuplicateImport.scala | 4 +- .../inspections/imports/WildcardImport.scala | 4 +- .../inference/BoundedByFinalType.scala | 4 +- .../inference/MethodReturningAny.scala | 4 +- .../inference/PointlessTypeBounds.scala | 4 +- .../ProductWithSerializableInferred.scala | 4 +- .../PartialFunctionInsteadOfMatch.scala | 4 +- .../matching/RepeatedCaseBody.scala | 4 +- .../SuspiciousMatchOnClassObject.scala | 4 +- .../math/BigDecimalDoubleConstructor.scala | 4 +- .../BigDecimalScaleWithoutRoundingMode.scala | 4 +- .../inspections/math/BrokenOddness.scala | 4 +- .../inspections/math/DivideByOne.scala | 4 +- .../scapegoat/inspections/math/ModOne.scala | 4 +- .../inspections/math/NanComparison.scala | 4 +- .../scapegoat/inspections/math/UseCbrt.scala | 4 +- .../scapegoat/inspections/math/UseExpM1.scala | 4 +- .../scapegoat/inspections/math/UseLog10.scala | 4 +- .../scapegoat/inspections/math/UseLog1P.scala | 4 +- .../scapegoat/inspections/math/UseSqrt.scala | 4 +- .../inspections/math/ZeroNumerator.scala | 4 +- .../inspections/naming/ClassNames.scala | 4 +- .../inspections/naming/MethodNames.scala | 4 +- .../inspections/naming/ObjectNames.scala | 4 +- .../inspections/nulls/NullAssignment.scala | 4 +- .../inspections/nulls/NullParameter.scala | 4 +- .../inspections/option/EitherGet.scala | 4 +- .../ImpossibleOptionSizeCondition.scala | 4 +- .../inspections/option/OptionGet.scala | 4 +- .../inspections/option/OptionSize.scala | 4 +- .../inspections/string/ArraysInFormat.scala | 4 +- .../inspections/string/ArraysToString.scala | 4 +- .../string/EmptyInterpolatedString.scala | 4 +- .../string/IllegalFormatString.scala | 4 +- .../IncorrectNumberOfArgsToFormat.scala | 4 +- .../inspections/string/InvalidRegex.scala | 4 +- .../string/LooksLikeInterpolatedString.scala | 6 +- .../string/StripMarginOnRegex.scala | 4 +- .../inspections/string/SubstringZero.scala | 4 +- .../string/UnsafeStringContains.scala | 4 +- .../style/AvoidOperatorOverload.scala | 4 +- .../ParameterlessMethodReturnsUnit.scala | 4 +- .../style/SimplifyBooleanExpression.scala | 4 +- .../inspections/unneccesary/ConstantIf.scala | 4 +- .../unneccesary/RedundantFinalizer.scala | 4 +- .../unneccesary/StoreBeforeReturn.scala | 4 +- .../unneccesary/UnnecessaryConversion.scala | 74 +++-- .../unneccesary/UnnecessaryIf.scala | 4 +- .../unneccesary/UnnecessaryReturnUse.scala | 4 +- .../unneccesary/UnusedMethodParameter.scala | 4 +- .../unneccesary/VarCouldBeVal.scala | 4 +- .../inspections/unsafe/AsInstanceOf.scala | 6 +- .../unsafe/FinalizerWithoutSuper.scala | 4 +- .../inspections/unsafe/IsInstanceOf.scala | 4 +- .../scapegoat/inspections/unsafe/TryGet.scala | 4 +- .../com/sksamuel/scapegoat/package.scala | 7 +- .../UnusedMethodParameterTest213.scala | 17 +- .../com/sksamuel/scapegoat/FeedbackTest.scala | 58 ++-- .../scapegoat/inspections/AnyUseTest.scala | 4 +- .../inspections/AsInstanceOfTest.scala | 89 +++--- .../inspections/AvoidToMinusOneTest.scala | 4 +- .../inspections/ConstantIfTest.scala | 48 ++-- .../inspections/DoubleNegationTest.scala | 4 +- .../scapegoat/inspections/EitherGetTest.scala | 14 +- .../FinalModifierOnCaseClassTest.scala | 4 +- .../FinalizerWithoutSuperTest.scala | 69 +++-- .../inspections/IsInstanceOfTest.scala | 60 ++-- .../inspections/LonelySealedTraitTest.scala | 4 +- .../inspections/MaxParameterTest.scala | 4 +- .../inspections/MethodReturningAnyTest.scala | 38 ++- .../inspections/PublicFinalizerTest.scala | 4 +- .../RedundantFinalModifierOnMethodTest.scala | 4 +- .../RedundantFinalModifierOnVarTest.scala | 4 +- .../scapegoat/inspections/TryGetTest.scala | 15 +- .../inspections/TypeShadowingTest.scala | 4 +- .../inspections/VarClosureTest.scala | 4 +- .../inspections/VarCouldBeValTest.scala | 259 +++++++++--------- .../scapegoat/inspections/VarUseTest.scala | 4 +- .../inspections/VariableShadowingTest.scala | 4 +- .../scapegoat/inspections/WhileTrueTest.scala | 54 ++-- .../collections/ArrayEqualsTest.scala | 4 +- .../collections/AvoidSizeEqualsZeroTest.scala | 4 +- .../AvoidSizeNotEqualsZeroTest.scala | 4 +- .../CollectionIndexOnNonIndexedSeqTest.scala | 4 +- .../CollectionNamingConfusionTest.scala | 4 +- .../CollectionNegativeIndexTest.scala | 4 +- .../CollectionPromotionToAnyTest.scala | 4 +- .../ComparisonToEmptyListTest.scala | 4 +- .../ComparisonToEmptySetTest.scala | 4 +- .../collections/DuplicateMapKeyTest.scala | 4 +- .../collections/DuplicateSetValueTest.scala | 4 +- .../collections/FilterDotHeadOptionTest.scala | 4 +- .../collections/FilterDotHeadTest.scala | 4 +- .../collections/FilterDotIsEmptyTest.scala | 4 +- .../collections/FilterDotSizeTest.scala | 4 +- .../collections/FilterOptionAndGetTest.scala | 4 +- ...ndNotEqualsNoneReplaceWithExistsTest.scala | 4 +- .../collections/FindDotIsDefinedTest.scala | 4 +- .../collections/JavaConversionsUseTest.scala | 4 +- .../collections/ListAppendTest.scala | 4 +- .../collections/ListSizeTest.scala | 4 +- .../collections/MapGetAndGetOrElseTest.scala | 4 +- .../collections/NegationIsEmptyTest.scala | 4 +- .../collections/NegationNonEmptyTest.scala | 4 +- .../collections/NegativeSeqPadTest.scala | 4 +- .../collections/PredefSeqIsMutableTest.scala | 4 +- .../PredefTraversableIsMutableTest.scala | 4 +- .../collections/PreferMapEmptyTest.scala | 4 +- .../collections/PreferSeqEmptyTest.scala | 4 +- .../collections/PreferSetEmptyTest.scala | 4 +- .../collections/ReverseFuncTest.scala | 4 +- .../collections/ReverseTailReverseTest.scala | 4 +- .../collections/ReverseTakeReverseTest.scala | 4 +- .../collections/SwapSortFilterTest.scala | 4 +- .../collections/UnsafeContainsTest.scala | 4 +- .../UnsafeTraversableMethodsTest.scala | 4 +- .../controlflow/RepeatedIfElseBodyTest.scala | 4 +- .../empty/EmptyCaseClassTest.scala | 44 ++- .../inspections/empty/EmptyForTest.scala | 4 +- .../inspections/empty/EmptyIfBlockTest.scala | 4 +- .../inspections/empty/EmptyMethodTest.scala | 4 +- .../empty/EmptySynchronizedBlockTest.scala | 4 +- .../inspections/empty/EmptyTryBlockTest.scala | 4 +- .../empty/EmptyWhileBlockTest.scala | 4 +- .../empty/RedundantFinalizerTest.scala | 13 +- .../ComparingFloatingPointTypesTest.scala | 4 +- .../ComparisonWithSelfInspectionTest.scala | 4 +- ...atchExceptionImmediatelyRethrownTest.scala | 4 +- .../exception/CatchExceptionTest.scala | 4 +- .../exception/CatchFatalTest.scala | 4 +- .../inspections/exception/CatchNpeTest.scala | 4 +- .../exception/CatchThrowableTest.scala | 4 +- .../IncorrectlyNamedExceptionsTest.scala | 4 +- .../exception/SwallowedExceptionTest.scala | 4 +- .../exception/UnreachableCatchTest.scala | 4 +- .../imports/DuplicateImportTest.scala | 4 +- .../imports/WildcardImportTest.scala | 4 +- .../inferrence/BoundedByFinalTypeTest.scala | 54 ++-- .../inferrence/PointlessTypeBoundsTest.scala | 145 +++++----- .../ProductWithSerializableInferredTest.scala | 20 +- .../matching/RepeatedCaseBodyTest.scala | 4 +- .../SuspiciousMatchOnClassObjectTest.scala | 4 +- .../BigDecimalDoubleConstructorTest.scala | 4 +- ...gDecimalScaleWithoutRoundingModeTest.scala | 4 +- .../inspections/math/BrokenOddnessTest.scala | 4 +- .../inspections/math/DivideByOneTest.scala | 4 +- .../inspections/math/ModOneTest.scala | 4 +- .../inspections/math/NanComparisonTest.scala | 4 +- .../inspections/math/UseCbrtTest.scala | 4 +- .../inspections/math/UseExpM1Test.scala | 4 +- .../inspections/math/UseLog10Test.scala | 4 +- .../inspections/math/UseLog1PTest.scala | 4 +- .../inspections/math/UseSqrtTest.scala | 4 +- .../inspections/math/ZeroNumeratorTest.scala | 4 +- .../inspections/names/ClassNamesTest.scala | 51 ++-- .../inspections/names/MethodNamesTest.scala | 120 ++++---- .../inspections/names/ObjectNamesTest.scala | 10 +- .../nulls/NullAssignmentTest.scala | 4 +- .../inspections/nulls/NullParameterTest.scala | 4 +- .../ImpossibleOptionSizeConditionTest.scala | 4 +- .../inspections/option/OptionGetTest.scala | 4 +- .../inspections/option/OptionSizeTest.scala | 4 +- .../string/ArraysInFormatTest.scala | 4 +- .../string/ArraysToStringTest.scala | 4 +- .../string/EmptyInterpolatedStringTest.scala | 4 +- .../string/IllegalFormatStringTest.scala | 4 +- .../IncorrectNumberOfArgsToFormatTest.scala | 4 +- .../inspections/string/InvalidRegexTest.scala | 4 +- .../LooksLikeInterpolatedStringTest.scala | 4 +- .../string/StripMarginOnRegexTest.scala | 4 +- .../string/SubstringZeroTest.scala | 4 +- .../string/UnsafeStringContainsTest.scala | 4 +- .../style/AvoidOperatorOverloadTest.scala | 4 +- .../ParameterlessMethodReturnsUnitTest.scala | 4 +- .../style/SimplifyBooleanExpressionTest.scala | 4 +- .../unnecessary/NoOpOverrideTest.scala | 51 ++-- .../unnecessary/StoreBeforeReturnTest.scala | 117 ++++---- .../UnnecessaryConversionTest.scala | 173 ++++++------ .../unnecessary/UnnecessaryIfTest.scala | 22 +- .../UnnecessaryReturnUseTest.scala | 30 +- .../UnusedMethodParameterTest.scala | 128 +++++---- 258 files changed, 1313 insertions(+), 1403 deletions(-) diff --git a/.github/workflows/pr-checks.yml b/.github/workflows/pr-checks.yml index 6e2d6afd..cc1bb3b1 100644 --- a/.github/workflows/pr-checks.yml +++ b/.github/workflows/pr-checks.yml @@ -12,8 +12,8 @@ jobs: scala: - 2.12.17 - 2.12.18 - - 2.13.10 - 2.13.11 + - 2.13.12 steps: - uses: actions/checkout@v2 - uses: olafurpg/setup-scala@v10 diff --git a/README.md b/README.md index 64a830aa..5052323e 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Scapegoat [![Codecov](https://img.shields.io/codecov/c/github/sksamuel/scapegoat)](https://codecov.io/gh/sksamuel/scapegoat) [](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22scalac-scapegoat-plugin_2.11.12%22) [](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22scalac-scapegoat-plugin_2.12.16%22) -[](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22scalac-scapegoat-plugin_2.13.10%22) +[](http://search.maven.org/#search%7Cga%7C1%7Ca%3A%22scalac-scapegoat-plugin_2.13.12%22) [![Scala Steward badge](https://img.shields.io/badge/Scala_Steward-helping-blue.svg?style=flat&logo=data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAQCAMAAAARSr4IAAAAVFBMVEUAAACHjojlOy5NWlrKzcYRKjGFjIbp293YycuLa3pYY2LSqql4f3pCUFTgSjNodYRmcXUsPD/NTTbjRS+2jomhgnzNc223cGvZS0HaSD0XLjbaSjElhIr+AAAAAXRSTlMAQObYZgAAAHlJREFUCNdNyosOwyAIhWHAQS1Vt7a77/3fcxxdmv0xwmckutAR1nkm4ggbyEcg/wWmlGLDAA3oL50xi6fk5ffZ3E2E3QfZDCcCN2YtbEWZt+Drc6u6rlqv7Uk0LdKqqr5rk2UCRXOk0vmQKGfc94nOJyQjouF9H/wCc9gECEYfONoAAAAASUVORK5CYII=)](https://scala-steward.org) Scapegoat is a Scala static code analyzer, which is more colloquially known as a code lint tool or linter. Scapegoat works in a similar vein to Java's [FindBugs](http://findbugs.sourceforge.net/) or [checkstyle](http://checkstyle.sourceforge.net/), or Scala's [Scalastyle](https://github.com/scalastyle/scalastyle). diff --git a/build.sbt b/build.sbt index ec09917b..8dfee429 100644 --- a/build.sbt +++ b/build.sbt @@ -22,8 +22,8 @@ developers := List( ) ) -scalaVersion := "2.13.11" -crossScalaVersions := Seq("2.12.17", "2.12.18", "2.13.10", "2.13.11") +scalaVersion := "2.13.12" +crossScalaVersions := Seq("2.12.17", "2.12.18", "2.13.11", "2.13.12") autoScalaLibrary := false crossVersion := CrossVersion.full crossTarget := { diff --git a/src/main/scala/com/sksamuel/scapegoat/Inspection.scala b/src/main/scala/com/sksamuel/scapegoat/Inspection.scala index 30481d32..aff3d585 100644 --- a/src/main/scala/com/sksamuel/scapegoat/Inspection.scala +++ b/src/main/scala/com/sksamuel/scapegoat/Inspection.scala @@ -16,7 +16,7 @@ abstract class Inspection( val self: Inspection = this - def inspector(context: InspectionContext): Inspector + def inspector(ctx: InspectionContext): Inspector def isEnabled: Boolean = true diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/AnyUse.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/AnyUse.scala index 0dfacc9c..7ca2010b 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/AnyUse.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/AnyUse.scala @@ -16,8 +16,8 @@ class AnyUse explanation = "Code returning Any is most likely an indication of a programming error." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/AvoidToMinusOne.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/AvoidToMinusOne.scala index 2d9bb3c6..1581a22d 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/AvoidToMinusOne.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/AvoidToMinusOne.scala @@ -16,8 +16,8 @@ class AvoidToMinusOne explanation = "A range in the following format (j to k - 1) can be simplified to (j until k)." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/BooleanParameter.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/BooleanParameter.scala index aee73563..be765d83 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/BooleanParameter.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/BooleanParameter.scala @@ -16,8 +16,8 @@ class BooleanParameter explanation = "Method has Boolean parameter. Consider splitting into two methods or using a case class." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { import context.global._ diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/DoubleNegation.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/DoubleNegation.scala index d624d36b..f5d87f6f 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/DoubleNegation.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/DoubleNegation.scala @@ -14,8 +14,8 @@ class DoubleNegation explanation = "Double negation can be removed, e.g. !(!b) it equal to just b." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/EmptyCaseClass.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/EmptyCaseClass.scala index f9efaa72..835842bc 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/EmptyCaseClass.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/EmptyCaseClass.scala @@ -14,8 +14,8 @@ class EmptyCaseClass explanation = "An empty case class can be rewritten as a case object." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/FinalModifierOnCaseClass.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/FinalModifierOnCaseClass.scala index 72c28c0d..d544dca4 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/FinalModifierOnCaseClass.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/FinalModifierOnCaseClass.scala @@ -10,12 +10,12 @@ class FinalModifierOnCaseClass explanation = "Using case classes without final modifier can lead to surprising breakage." ) { - override def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + override def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { import context.global._ - override def postTyperTraverser = + override def postTyperTraverser: context.Traverser = new context.Traverser { override def inspect(tree: Tree): Unit = { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/LonelySealedTrait.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/LonelySealedTrait.scala index 0f53ac2b..1a4fd537 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/LonelySealedTrait.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/LonelySealedTrait.scala @@ -16,8 +16,8 @@ class LonelySealedTrait explanation = "A sealed trait that is not extended is considered dead code." ) { - override def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + override def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { import context.global._ diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/MaxParameters.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/MaxParameters.scala index d22e514a..44c1e219 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/MaxParameters.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/MaxParameters.scala @@ -15,8 +15,8 @@ class MaxParameters "Methods having a large number of parameters are more difficult to reason about, consider refactoring this code." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/NoOpOverride.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/NoOpOverride.scala index 37b39945..e02249e4 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/NoOpOverride.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/NoOpOverride.scala @@ -14,8 +14,8 @@ class NoOpOverride explanation = "This method is overridden yet only calls super." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/PublicFinalizer.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/PublicFinalizer.scala index 7dfc4245..9b94298e 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/PublicFinalizer.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/PublicFinalizer.scala @@ -14,8 +14,8 @@ class PublicFinalizer explanation = "Public finalizer should be avoided as finalizers should not be programmatically invoked." ) { - override def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + override def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { import context.global._ diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnMethod.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnMethod.scala index 66f16ef7..6d88435c 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnMethod.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnMethod.scala @@ -12,13 +12,13 @@ class RedundantFinalModifierOnMethod explanation = "A final modifier on methods that cannot be overridden is redundant." ) { - override def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + override def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { import context.global._ import definitions._ - override def postTyperTraverser = + override def postTyperTraverser: context.Traverser = new context.Traverser { override def inspect(tree: Tree): Unit = { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnVar.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnVar.scala index e99afc0b..7cbc7f96 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnVar.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnVar.scala @@ -10,12 +10,12 @@ class RedundantFinalModifierOnVar explanation = "A final modifier on a var that cannot be overridden is redundant." ) { - override def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + override def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { import context.global._ - override def postTyperTraverser = + override def postTyperTraverser: context.Traverser = new context.Traverser { override def inspect(tree: Tree): Unit = { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/TypeShadowing.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/TypeShadowing.scala index e047dd16..a25e633b 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/TypeShadowing.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/TypeShadowing.scala @@ -16,8 +16,8 @@ class TypeShadowing explanation = "Shadowing type parameters is considered a bad practice and should be avoided." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/VarClosure.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/VarClosure.scala index 5af0b456..14677c5b 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/VarClosure.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/VarClosure.scala @@ -14,8 +14,8 @@ class VarClosure explanation = "Closing over a var can lead to subtle bugs." ) { - override def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + override def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { import context.global._ diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/VarUse.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/VarUse.scala index e4e7c500..c5ba010f 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/VarUse.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/VarUse.scala @@ -11,9 +11,9 @@ class VarUse "Use of variables is generally discouraged, especially in the context of a shared mutable state. Consider using an immutable state or other referentially transparent alternatives." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { - override def postTyperTraverser = + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { + override def postTyperTraverser: context.Traverser = new context.Traverser { import context.global._ diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/VariableShadowing.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/VariableShadowing.scala index ba0274f4..3e4db375 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/VariableShadowing.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/VariableShadowing.scala @@ -13,8 +13,8 @@ class VariableShadowing "Variable shadowing is very useful, but can easily lead to nasty bugs in your code. Shadowed variables can be potentially confusing to other maintainers when the same name is adopted to have a new meaning in a nested scope." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ArrayEquals.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ArrayEquals.scala index 7d397275..4cf87d57 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ArrayEquals.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ArrayEquals.scala @@ -15,8 +15,8 @@ class ArrayEquals "Array equals is not an equality check. Use a.deep == b.deep or convert to another collection type." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeEqualsZero.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeEqualsZero.scala index 49bb1197..9d3d0728 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeEqualsZero.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeEqualsZero.scala @@ -15,8 +15,8 @@ class AvoidSizeEqualsZero "Traversable.size can be slow for some data structures, prefer Traversable.isEmpty, which is O(1)." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZero.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZero.scala index d45f2962..7ffe0a5d 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZero.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZero.scala @@ -14,8 +14,8 @@ class AvoidSizeNotEqualsZero explanation = ".size can be slow for some data structures, prefer .nonEmpty, which is O(1)." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionIndexOnNonIndexedSeq.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionIndexOnNonIndexedSeq.scala index 0d8aacf9..828cefee 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionIndexOnNonIndexedSeq.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionIndexOnNonIndexedSeq.scala @@ -14,8 +14,8 @@ class CollectionIndexOnNonIndexedSeq explanation = "Using an index to access elements of an IndexedSeq may cause performance problems." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNamingConfusion.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNamingConfusion.scala index 1eeccf3f..4c9f3fc2 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNamingConfusion.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNamingConfusion.scala @@ -15,8 +15,8 @@ class CollectionNamingConfusion "E.g. an instance of a Set is confusingly referred to by a variable called/containing list, or the other way around." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNegativeIndex.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNegativeIndex.scala index 9b61f372..cc36433d 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNegativeIndex.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNegativeIndex.scala @@ -15,8 +15,8 @@ class CollectionNegativeIndex "Trying to access Seq elements using a negative index will result in an IndexOutOfBoundsException." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionPromotionToAny.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionPromotionToAny.scala index 1f71a90d..b75bdcf8 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionPromotionToAny.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/CollectionPromotionToAny.scala @@ -15,8 +15,8 @@ class CollectionPromotionToAny "The `:+` (append) operator on collections accepts any argument you give it, which means that you can end up with e.g. `Seq[Any]` if your types don't match." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptyList.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptyList.scala index c70aa3cf..dc40fdd8 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptyList.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptyList.scala @@ -14,8 +14,8 @@ class ComparisonToEmptyList explanation = "Prefer use of `isEmpty` instead of comparison to an empty List." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptySet.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptySet.scala index d2130215..f81b67dd 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptySet.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptySet.scala @@ -14,8 +14,8 @@ class ComparisonToEmptySet explanation = "Prefer use of `isEmpty` instead of comparison to an empty Set." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateMapKey.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateMapKey.scala index da8f5fc3..cd7a3015 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateMapKey.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateMapKey.scala @@ -14,8 +14,8 @@ class DuplicateMapKey explanation = "A map key is overwritten by a later entry." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateSetValue.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateSetValue.scala index de8944a2..c52560bb 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateSetValue.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateSetValue.scala @@ -14,8 +14,8 @@ class DuplicateSetValue explanation = "A set value is overwritten by a later entry." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ExistsSimplifiableToContains.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ExistsSimplifiableToContains.scala index cd2dd7ed..79f37976 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ExistsSimplifiableToContains.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ExistsSimplifiableToContains.scala @@ -16,8 +16,8 @@ class ExistsSimplifiableToContains explanation = "`exists(x => x == y)` can be replaced with `contains(y)`." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHead.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHead.scala index 3f046f8e..9aea9637 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHead.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHead.scala @@ -15,8 +15,8 @@ class FilterDotHead "`filter().head` can throw an exception if the collection is empty - it can be replaced with `find() match {...}`." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHeadOption.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHeadOption.scala index ffce2ccf..dc8429fc 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHeadOption.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHeadOption.scala @@ -15,8 +15,8 @@ class FilterDotHeadOption "`filter()` scans the entire collection, which is unnecessary if you only want to get the first element that satisfies the predicate - `filter().headOption` can be replaced with `find()` to potentially avoid scanning the entire collection." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotIsEmpty.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotIsEmpty.scala index acd7a45c..b9d4dfaf 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotIsEmpty.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotIsEmpty.scala @@ -15,8 +15,8 @@ class FilterDotIsEmpty "`filter()` scans the entire collection, which can potentially be avoided if the element exists in the collection - `filter().isEmpty` can be replaced with `!exists()`." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotSize.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotSize.scala index 4c102471..d0596679 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotSize.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotSize.scala @@ -16,8 +16,8 @@ class FilterDotSize explanation = "`filter().size` can be replaced with `count()`, which is more concise." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterOptionAndGet.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterOptionAndGet.scala index b3d2870b..1ccdc8df 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterOptionAndGet.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FilterOptionAndGet.scala @@ -14,8 +14,8 @@ class FilterOptionAndGet explanation = "`filter(_.isDefined).map(_.get)` can be replaced with `flatten`." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FindAndNotEqualsNoneReplaceWithExists.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FindAndNotEqualsNoneReplaceWithExists.scala index 7d3f3cd7..a6e67e4e 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FindAndNotEqualsNoneReplaceWithExists.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FindAndNotEqualsNoneReplaceWithExists.scala @@ -10,9 +10,9 @@ class FindAndNotEqualsNoneReplaceWithExists explanation = "`find() != None` can be replaced with `exists()`, which is more concise." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { - override def postTyperTraverser = + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { + override def postTyperTraverser: context.Traverser = new context.Traverser { import context.global._ diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FindDotIsDefined.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FindDotIsDefined.scala index 0e37bf1a..a81220da 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FindDotIsDefined.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/FindDotIsDefined.scala @@ -14,8 +14,8 @@ class FindDotIsDefined explanation = "`find().isDefined` can be replaced with `exists()`, which is more concise." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/JavaConversionsUse.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/JavaConversionsUse.scala index 577a72ff..1cd5a059 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/JavaConversionsUse.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/JavaConversionsUse.scala @@ -15,8 +15,8 @@ class JavaConversionsUse "Use of Java conversions can lead to unusual behaviour. It is recommended to use JavaConverters." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ListAppend.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ListAppend.scala index 3ea7a5bb..125beb9e 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ListAppend.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ListAppend.scala @@ -15,8 +15,8 @@ class ListAppend "List append is O(n). For large lists, consider using cons (::) or another data structure such as ListBuffer, Vector or a cats.data.Chain (which has constant prepend and append)." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ListSize.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ListSize.scala index 8f60ca6e..28f05387 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ListSize.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ListSize.scala @@ -15,8 +15,8 @@ class ListSize "List.size is O(n). Consider using a different data type with O(1) size lookup such as Vector or an Array." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/MapGetAndGetOrElse.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/MapGetAndGetOrElse.scala index 114716d2..cdd5c82e 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/MapGetAndGetOrElse.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/MapGetAndGetOrElse.scala @@ -18,8 +18,8 @@ class MapGetAndGetOrElse "Map.get(key).getOrElse(value) can be replaced with Map.getOrElse(key, value), which is more concise." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/NegationIsEmpty.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/NegationIsEmpty.scala index 4c12f8d3..4f804725 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/NegationIsEmpty.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/NegationIsEmpty.scala @@ -14,8 +14,8 @@ class NegationIsEmpty explanation = "!.isEmpty can be replaced with.nonEmpty to make it easier to reason about." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/NegationNonEmpty.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/NegationNonEmpty.scala index fb42d954..135a9f71 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/NegationNonEmpty.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/NegationNonEmpty.scala @@ -14,8 +14,8 @@ class NegationNonEmpty explanation = "!.nonEmpty can be replaced with.isEmpty to make it easier to reason about." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/NegativeSeqPad.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/NegativeSeqPad.scala index 30867cd0..42321693 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/NegativeSeqPad.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/NegativeSeqPad.scala @@ -14,8 +14,8 @@ class NegativeSeqPad explanation = "Seq.padTo with a negative length will not have any effect." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PredefIterableIsMutable.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PredefIterableIsMutable.scala index cee77833..0af2a08a 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PredefIterableIsMutable.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PredefIterableIsMutable.scala @@ -17,8 +17,8 @@ class PredefIterableIsMutable override def isEnabled: Boolean = !isScala213 - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PredefSeqIsMutable.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PredefSeqIsMutable.scala index 9425f0de..b357685f 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PredefSeqIsMutable.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PredefSeqIsMutable.scala @@ -16,8 +16,8 @@ class PredefSeqIsMutable override def isEnabled: Boolean = !isScala213 - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { import context.global._ diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PredefTraversableIsMutable.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PredefTraversableIsMutable.scala index 390ebb81..6bbd4f69 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PredefTraversableIsMutable.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PredefTraversableIsMutable.scala @@ -17,8 +17,8 @@ class PredefTraversableIsMutable override def isEnabled: Boolean = !isScala213 - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PreferMapEmpty.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PreferMapEmpty.scala index 4955b606..7c734b01 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PreferMapEmpty.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PreferMapEmpty.scala @@ -11,9 +11,9 @@ class PreferMapEmpty "`Map[K,V]()` allocates an intermediate object. Consider `Map.empty` which returns a singleton instance without creating a new object." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { - override def postTyperTraverser = + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { + override def postTyperTraverser: context.Traverser = new context.Traverser { import context.global._ diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PreferSeqEmpty.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PreferSeqEmpty.scala index bf9c3be2..fd1303bf 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PreferSeqEmpty.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PreferSeqEmpty.scala @@ -15,8 +15,8 @@ class PreferSeqEmpty "`Seq[T]()` allocates an intermediate object. Consider `Seq.empty` which returns a singleton instance without creating a new object." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PreferSetEmpty.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PreferSetEmpty.scala index 1de0ee17..c5e4c8b0 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PreferSetEmpty.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/PreferSetEmpty.scala @@ -15,8 +15,8 @@ class PreferSetEmpty "`Set[T]()` allocates an intermediate object. Consider `Set.empty` which returns a singleton instance without creating a new object." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ReverseFunc.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ReverseFunc.scala index a1e27f77..52acb6d6 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ReverseFunc.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ReverseFunc.scala @@ -24,8 +24,8 @@ class ReverseFunc funcReplace.find(_._1 == func) } - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTailReverse.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTailReverse.scala index 07e2157a..87f5e34c 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTailReverse.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTailReverse.scala @@ -10,8 +10,8 @@ class ReverseTailReverse explanation = "`reverse.tail.reverse` can be replaced with `init`, which is more concise." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTakeReverse.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTakeReverse.scala index d9a224eb..16dced4b 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTakeReverse.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTakeReverse.scala @@ -10,8 +10,8 @@ class ReverseTakeReverse explanation = "`reverse.take().reverse` can be replaced with `takeRight`, which is more concise." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/SwapSortFilter.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/SwapSortFilter.scala index 01f9e86b..c49f97cc 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/SwapSortFilter.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/SwapSortFilter.scala @@ -15,8 +15,8 @@ class SwapSortFilter "Filter first and then sort the remaining collection. Swap sort.filter for filter.sort for better performance." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeContains.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeContains.scala index 2f8a8136..c516e751 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeContains.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeContains.scala @@ -15,8 +15,8 @@ class UnsafeContains "`contains()` accepts arguments af any type, which means you might be checking if your collection contains an element of an unrelated type." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { import context.global._ diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeTraversableMethods.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeTraversableMethods.scala index 8749785d..2f14c91c 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeTraversableMethods.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeTraversableMethods.scala @@ -25,8 +25,8 @@ class UnsafeTraversableMethods "minBy" ) - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/controlflow/RepeatedIfElseBody.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/controlflow/RepeatedIfElseBody.scala index 2ea44f63..d331a79d 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/controlflow/RepeatedIfElseBody.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/controlflow/RepeatedIfElseBody.scala @@ -11,9 +11,9 @@ class RepeatedIfElseBody "The if statement could be refactored if both branches are the same or start with the same." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { - override def postTyperTraverser = + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { + override def postTyperTraverser: context.Traverser = new context.Traverser { import context.global._ diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/controlflow/WhileTrue.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/controlflow/WhileTrue.scala index 20229820..81ffe0ab 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/controlflow/WhileTrue.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/controlflow/WhileTrue.scala @@ -14,8 +14,8 @@ class WhileTrue explanation = "A (do) while true loop is unlikely to be meant for production." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyFor.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyFor.scala index c88feba7..c9b60c7b 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyFor.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyFor.scala @@ -14,8 +14,8 @@ class EmptyFor explanation = "An empty for loop isn't a common practice and in most cases is considered as dead code." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyIfBlock.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyIfBlock.scala index 8f259454..289dad0c 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyIfBlock.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyIfBlock.scala @@ -14,8 +14,8 @@ class EmptyIfBlock explanation = "An empty if block is considered as dead code." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyMethod.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyMethod.scala index 071f70c1..3bea64e5 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyMethod.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyMethod.scala @@ -14,8 +14,8 @@ class EmptyMethod explanation = "An empty method is considered as dead code." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptySynchronizedBlock.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptySynchronizedBlock.scala index 29d964f7..a9be8a0c 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptySynchronizedBlock.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptySynchronizedBlock.scala @@ -14,8 +14,8 @@ class EmptySynchronizedBlock explanation = "An empty synchronized block is considered as dead code." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyTryBlock.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyTryBlock.scala index c115b7ea..87337a3c 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyTryBlock.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyTryBlock.scala @@ -14,8 +14,8 @@ class EmptyTryBlock explanation = "An empty try block is considered as dead code." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyWhileBlock.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyWhileBlock.scala index baeb23cd..906cbdcd 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyWhileBlock.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/empty/EmptyWhileBlock.scala @@ -14,8 +14,8 @@ class EmptyWhileBlock explanation = "An empty while block is considered as dead code." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/equality/ComparingFloatingPointTypes.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/equality/ComparingFloatingPointTypes.scala index 84c64395..718754db 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/equality/ComparingFloatingPointTypes.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/equality/ComparingFloatingPointTypes.scala @@ -15,8 +15,8 @@ class ComparingFloatingPointTypes "Due to minor rounding errors, it is not advisable to compare floating-point numbers using the == operator. Either use a threshold based comparison, or switch to a BigDecimal." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/equality/ComparingUnrelatedTypes.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/equality/ComparingUnrelatedTypes.scala index b4f3e601..c794e68b 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/equality/ComparingUnrelatedTypes.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/equality/ComparingUnrelatedTypes.scala @@ -15,8 +15,8 @@ class ComparingUnrelatedTypes "In most case comparing unrelated types cannot succeed and it's usually an indication of a bug." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/equality/ComparisonWithSelf.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/equality/ComparisonWithSelf.scala index 3d28f810..d0f49fed 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/equality/ComparisonWithSelf.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/equality/ComparisonWithSelf.scala @@ -14,8 +14,8 @@ class ComparisonWithSelf explanation = "Comparison with self will always yield true." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchException.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchException.scala index a36911b3..e19391ec 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchException.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchException.scala @@ -16,8 +16,8 @@ class CatchException "Did you intend to catch all exceptions? Consider catching a more specific exception class." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchExceptionImmediatelyRethrown.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchExceptionImmediatelyRethrown.scala index 8f571dd2..1be3070f 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchExceptionImmediatelyRethrown.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchExceptionImmediatelyRethrown.scala @@ -10,8 +10,8 @@ class CatchExceptionImmediatelyRethrown explanation = "Immediately re-throwing a caught exception is equivalent to not catching it at all." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchFatal.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchFatal.scala index ccef12cb..cb36c91c 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchFatal.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchFatal.scala @@ -18,8 +18,8 @@ class CatchFatal "Did you intend to catch a fatal exception? Consider using scala.util.control.NonFatal instead." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchNpe.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchNpe.scala index db760e38..d8932be2 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchNpe.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchNpe.scala @@ -14,8 +14,8 @@ class CatchNpe explanation = "Avoid using null at all cost and you shouldn't need to catch NullPointerExceptions. Prefer Option to indicate potentially missing values and use Try to materialize exceptions thrown by any external libraries." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchThrowable.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchThrowable.scala index f42ef419..14eec9ba 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchThrowable.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/CatchThrowable.scala @@ -15,8 +15,8 @@ class CatchThrowable "Did you intend to catch all throwables? Consider catching a more specific exception class." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/IncorrectlyNamedExceptions.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/IncorrectlyNamedExceptions.scala index 13eabf2e..16f27b45 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/IncorrectlyNamedExceptions.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/IncorrectlyNamedExceptions.scala @@ -17,8 +17,8 @@ class IncorrectlyNamedExceptions "Class named exception does not derive from Exception / class derived from Exception is not named *Exception." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/SwallowedException.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/SwallowedException.scala index f1d9c1a8..f286fa32 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/SwallowedException.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/SwallowedException.scala @@ -16,8 +16,8 @@ class SwallowedException "If you use a try/catch block to deal with an exception, you should handle all of the caught exceptions and if for some reason you're throwing another exception in the result, you should include the original exception as the cause." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/UnreachableCatch.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/UnreachableCatch.scala index 805ed40c..48adc00f 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/exception/UnreachableCatch.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/exception/UnreachableCatch.scala @@ -16,8 +16,8 @@ class UnreachableCatch explanation = "One or more cases are unreachable." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/imports/DuplicateImport.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/imports/DuplicateImport.scala index 7861fe5e..938d98e5 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/imports/DuplicateImport.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/imports/DuplicateImport.scala @@ -16,8 +16,8 @@ class DuplicateImport explanation = "Duplicate imports should be removed." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { private val imports = mutable.HashSet[String]() diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/imports/WildcardImport.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/imports/WildcardImport.scala index 95359316..e371a353 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/imports/WildcardImport.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/imports/WildcardImport.scala @@ -15,8 +15,8 @@ class WildcardImport "Avoid using wildcard imports, unless you are importing more than a few entities. Wildcard imports make the code more difficult to maintain." ) { - override def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + override def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { import context.global._ diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/inference/BoundedByFinalType.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/inference/BoundedByFinalType.scala index f878f31b..1def36d6 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/inference/BoundedByFinalType.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/inference/BoundedByFinalType.scala @@ -14,8 +14,8 @@ class BoundedByFinalType explanation = "Pointless type bound. Type parameter can only be a single value." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/inference/MethodReturningAny.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/inference/MethodReturningAny.scala index ffdf23dd..2637f645 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/inference/MethodReturningAny.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/inference/MethodReturningAny.scala @@ -16,8 +16,8 @@ class MethodReturningAny explanation = "Method returns Any. Consider using a more specialized type." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/inference/PointlessTypeBounds.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/inference/PointlessTypeBounds.scala index 029ee16e..41368144 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/inference/PointlessTypeBounds.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/inference/PointlessTypeBounds.scala @@ -14,8 +14,8 @@ class PointlessTypeBounds explanation = "Type bound resolves to `Nothing <: T <: Any`. Did you mean to put in other bounds?" ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/inference/ProductWithSerializableInferred.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/inference/ProductWithSerializableInferred.scala index 45c8b882..1f28acac 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/inference/ProductWithSerializableInferred.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/inference/ProductWithSerializableInferred.scala @@ -17,8 +17,8 @@ class ProductWithSerializableInferred "It is unlikely that Product with Serializable was your target type. This is often an indication of mixing up incompatible types." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/matching/PartialFunctionInsteadOfMatch.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/matching/PartialFunctionInsteadOfMatch.scala index 4dd9994c..e34e063c 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/matching/PartialFunctionInsteadOfMatch.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/matching/PartialFunctionInsteadOfMatch.scala @@ -14,8 +14,8 @@ class PartialFunctionInsteadOfMatch explanation = "A map match can be replaced with a partial function for greater readability." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/matching/RepeatedCaseBody.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/matching/RepeatedCaseBody.scala index 5a34627e..66eb363b 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/matching/RepeatedCaseBody.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/matching/RepeatedCaseBody.scala @@ -16,8 +16,8 @@ class RepeatedCaseBody explanation = "Case body is repeated. Consider merging pattern clauses together." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/matching/SuspiciousMatchOnClassObject.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/matching/SuspiciousMatchOnClassObject.scala index df1eed45..90fb03f8 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/matching/SuspiciousMatchOnClassObject.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/matching/SuspiciousMatchOnClassObject.scala @@ -14,8 +14,8 @@ class SuspiciousMatchOnClassObject explanation = "Matching on an companion object of a case class is probably not what you intended." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalDoubleConstructor.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalDoubleConstructor.scala index 10ba8b33..873d21a1 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalDoubleConstructor.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalDoubleConstructor.scala @@ -15,8 +15,8 @@ class BigDecimalDoubleConstructor "The results of this constructor can be somewhat unpredictable. E.g. writing new BigDecimal(0.1) in Java creates a BigDecimal which is actually equal to 0.1000000000000000055511151231257827021181583404541015625. This is because 0.1 cannot be represented exactly as a double." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalScaleWithoutRoundingMode.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalScaleWithoutRoundingMode.scala index c09d97fa..ba93dc96 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalScaleWithoutRoundingMode.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalScaleWithoutRoundingMode.scala @@ -16,8 +16,8 @@ class BigDecimalScaleWithoutRoundingMode "When using `setScale()` on a BigDecimal without setting the rounding mode, this can throw an exception if rounding is required. Did you mean to call `setScale(s, RoundingMode.XYZ)`?" ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/math/BrokenOddness.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/math/BrokenOddness.scala index 2931294a..bc1d0763 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/math/BrokenOddness.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/math/BrokenOddness.scala @@ -17,8 +17,8 @@ class BrokenOddness "Code that attempts to check for oddness using `x % 2 == 1` will fail on negative numbers. Consider using `x % 2 != 0`." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/math/DivideByOne.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/math/DivideByOne.scala index c630bb77..3bc5ced2 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/math/DivideByOne.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/math/DivideByOne.scala @@ -14,8 +14,8 @@ class DivideByOne explanation = "Divide by one will always return the original value." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/math/ModOne.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/math/ModOne.scala index 0b105958..c4fac137 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/math/ModOne.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/math/ModOne.scala @@ -16,8 +16,8 @@ class ModOne explanation = "Any expression x % 1 will always return 0." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/math/NanComparison.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/math/NanComparison.scala index dfe24f3b..949fc49b 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/math/NanComparison.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/math/NanComparison.scala @@ -14,8 +14,8 @@ class NanComparison explanation = "NaN comparison will always fail. Use value.isNan instead." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseCbrt.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseCbrt.scala index 0a6585a6..e1e184fa 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseCbrt.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseCbrt.scala @@ -14,8 +14,8 @@ class UseCbrt explanation = "Use math.cbrt, which is clearer and more performant than math.pow(x, 1/3)." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseExpM1.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseExpM1.scala index 32c11389..c644e890 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseExpM1.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseExpM1.scala @@ -14,8 +14,8 @@ class UseExpM1 explanation = "Use math.expm1(x), which is clearer and more performant than math.exp(x) - 1." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseLog10.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseLog10.scala index 1951e328..c56326d2 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseLog10.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseLog10.scala @@ -10,8 +10,8 @@ class UseLog10 explanation = "Use math.log10(x), which is clearer and more performant than $math.log(x)/$math.log(10)." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseLog1P.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseLog1P.scala index 64ffcc0f..73ad5156 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseLog1P.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseLog1P.scala @@ -10,8 +10,8 @@ class UseLog1P explanation = "Use math.log1p(x) is clearer and more performant than $math.log(1 + x)." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseSqrt.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseSqrt.scala index d2c54158..19d84db7 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseSqrt.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/math/UseSqrt.scala @@ -10,8 +10,8 @@ class UseSqrt explanation = "Use math.sqrt, which is clearer and more performant than $math.pow(x, 0.5)." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/math/ZeroNumerator.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/math/ZeroNumerator.scala index e173c0ad..98648250 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/math/ZeroNumerator.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/math/ZeroNumerator.scala @@ -14,8 +14,8 @@ class ZeroNumerator explanation = "Dividing zero by any number will always return zero, e.g. 0 / x == 0." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/naming/ClassNames.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/naming/ClassNames.scala index 2c8533bc..576a29af 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/naming/ClassNames.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/naming/ClassNames.scala @@ -14,8 +14,8 @@ class ClassNames explanation = "Class names should begin with uppercase letter." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/naming/MethodNames.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/naming/MethodNames.scala index f327dcad..3f55d8a2 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/naming/MethodNames.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/naming/MethodNames.scala @@ -17,8 +17,8 @@ class MethodNames "Methods should be in camelCase style with the first letter lower-case. See http://docs.scala-lang.org/style/naming-conventions.html#methods." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/naming/ObjectNames.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/naming/ObjectNames.scala index 75bd3333..0137f812 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/naming/ObjectNames.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/naming/ObjectNames.scala @@ -14,8 +14,8 @@ class ObjectNames explanation = "Object names should only contain alphanumeric characters." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/nulls/NullAssignment.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/nulls/NullAssignment.scala index 6b909201..c84cbbc3 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/nulls/NullAssignment.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/nulls/NullAssignment.scala @@ -14,8 +14,8 @@ class NullAssignment explanation = "Use an Option instead when the value can be empty." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/nulls/NullParameter.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/nulls/NullParameter.scala index 7d5b4e43..4f8a0af7 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/nulls/NullParameter.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/nulls/NullParameter.scala @@ -14,8 +14,8 @@ class NullParameter explanation = "Use an Option instead when the value can be empty and pass down a None instead." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/option/EitherGet.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/option/EitherGet.scala index 97353760..8bdcd00a 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/option/EitherGet.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/option/EitherGet.scala @@ -15,8 +15,8 @@ class EitherGet "Method .get on a Left and a Right projection is deprecated since 2.13, use Either.getOrElse or Either.swap.getOrElse instead." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/option/ImpossibleOptionSizeCondition.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/option/ImpossibleOptionSizeCondition.scala index 2eed6cc3..fdcbcd58 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/option/ImpossibleOptionSizeCondition.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/option/ImpossibleOptionSizeCondition.scala @@ -14,8 +14,8 @@ class ImpossibleOptionSizeCondition explanation = "Option.size > 1 can never be true, did you mean to use Option.nonEmpty instead?" ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/option/OptionGet.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/option/OptionGet.scala index d2096d98..dc67e97d 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/option/OptionGet.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/option/OptionGet.scala @@ -15,8 +15,8 @@ class OptionGet "Using Option.get defeats the purpose of using Option in the first place. Use the following instead: Option.getOrElse, Option.fold, pattern matching or don't take the value out of the container and map over it to transform it." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/option/OptionSize.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/option/OptionSize.scala index f10bfea6..8406f7c5 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/option/OptionSize.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/option/OptionSize.scala @@ -15,8 +15,8 @@ class OptionSize "Prefer to use Option.isDefined, Option.isEmpty or Option.nonEmpty instead of Option.size." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/string/ArraysInFormat.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/string/ArraysInFormat.scala index 94140b11..ac3748a7 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/string/ArraysInFormat.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/string/ArraysInFormat.scala @@ -14,8 +14,8 @@ class ArraysInFormat explanation = "An Array passed to String.format might result in an incorrect formatting." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/string/ArraysToString.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/string/ArraysToString.scala index 7f31b86b..d72783fe 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/string/ArraysToString.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/string/ArraysToString.scala @@ -14,8 +14,8 @@ class ArraysToString explanation = "Calling toString on an array does not perform a deep toString." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/string/EmptyInterpolatedString.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/string/EmptyInterpolatedString.scala index 47b3d737..6ace82e4 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/string/EmptyInterpolatedString.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/string/EmptyInterpolatedString.scala @@ -15,8 +15,8 @@ class EmptyInterpolatedString "String declared as interpolated but has no parameters can be turned into a regular string." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/string/IllegalFormatString.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/string/IllegalFormatString.scala index 83d27096..376fc56a 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/string/IllegalFormatString.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/string/IllegalFormatString.scala @@ -20,8 +20,8 @@ class IllegalFormatString // format is: %[argument_index$][flags][width][.precision][t]conversion final val argRegex = "%(\\d+\\$)?[-#+ 0,(\\<]*?\\d*(\\.\\d+)?[tT]?[a-zA-Z]".r - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/string/IncorrectNumberOfArgsToFormat.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/string/IncorrectNumberOfArgsToFormat.scala index 7794688d..e6570f9b 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/string/IncorrectNumberOfArgsToFormat.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/string/IncorrectNumberOfArgsToFormat.scala @@ -19,8 +19,8 @@ class IncorrectNumberOfArgsToFormat // OR: %% final val argRegex = "%((\\d+\\$)?[-#+ 0,(\\<]*?\\d?(\\.\\d+)?[tT]?[a-zA-Z]|%)".r - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/string/InvalidRegex.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/string/InvalidRegex.scala index ca201fd6..18f6ca27 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/string/InvalidRegex.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/string/InvalidRegex.scala @@ -17,8 +17,8 @@ class InvalidRegex "Invalid regex literals can fail at compile time with a PatternSyntaxException. This could be caused by e.g. dangling meta characters, or unclosed escape characters, etc." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/string/LooksLikeInterpolatedString.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/string/LooksLikeInterpolatedString.scala index 04ff0f33..0f726f20 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/string/LooksLikeInterpolatedString.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/string/LooksLikeInterpolatedString.scala @@ -13,9 +13,9 @@ class LooksLikeInterpolatedString final val regex1 = "\\$\\{[a-z][.a-zA-Z0-9_]*\\}".r final val regex2 = "\\$[a-z][.a-zA-Z0-9_]*".r - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { - override def postTyperTraverser = + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { + override def postTyperTraverser: context.Traverser = new context.Traverser { import context.global._ diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/string/StripMarginOnRegex.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/string/StripMarginOnRegex.scala index 6b488512..b0761faf 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/string/StripMarginOnRegex.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/string/StripMarginOnRegex.scala @@ -14,8 +14,8 @@ class StripMarginOnRegex explanation = "Strip margin will strip | from regex - possible corrupted regex." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/string/SubstringZero.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/string/SubstringZero.scala index be0a0b32..e6e6b21d 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/string/SubstringZero.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/string/SubstringZero.scala @@ -14,8 +14,8 @@ class SubstringZero explanation = "Use of String.substring(0) will always return the same string." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/string/UnsafeStringContains.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/string/UnsafeStringContains.scala index 34593eca..80013504 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/string/UnsafeStringContains.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/string/UnsafeStringContains.scala @@ -15,8 +15,8 @@ class UnsafeStringContains "String.contains() accepts arguments af any type, which means you might be checking if your string contains an element of an unrelated type." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/style/AvoidOperatorOverload.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/style/AvoidOperatorOverload.scala index 3faba616..076db1db 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/style/AvoidOperatorOverload.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/style/AvoidOperatorOverload.scala @@ -19,8 +19,8 @@ class AvoidOperatorOverload "Scala style guide advocates against routinely using operators as method names, see http://docs.scala-lang.org/style/naming-conventions.html#symbolic-method-names." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/style/ParameterlessMethodReturnsUnit.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/style/ParameterlessMethodReturnsUnit.scala index 0c6b558e..888d0498 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/style/ParameterlessMethodReturnsUnit.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/style/ParameterlessMethodReturnsUnit.scala @@ -15,8 +15,8 @@ class ParameterlessMethodReturnsUnit "Methods should be defined with empty parentheses if they have side effects. A method returning Unit must have side effects, therefore you should declare it with ()." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/style/SimplifyBooleanExpression.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/style/SimplifyBooleanExpression.scala index 3ace2b60..abded32a 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/style/SimplifyBooleanExpression.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/style/SimplifyBooleanExpression.scala @@ -13,8 +13,8 @@ class SimplifyBooleanExpression description = "Checks for boolean expressions that can be simplified.", explanation = "Boolean expressions such as x == false can be re-written as !x." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/ConstantIf.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/ConstantIf.scala index 4c389ea8..01417a69 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/ConstantIf.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/ConstantIf.scala @@ -17,8 +17,8 @@ class ConstantIf "An if condition which gets compiled to a constant, like e.g. if (1 < 2) or if (false) doesn't add any value and should be avoided." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/RedundantFinalizer.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/RedundantFinalizer.scala index 452ac48c..71d24450 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/RedundantFinalizer.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/RedundantFinalizer.scala @@ -17,8 +17,8 @@ class RedundantFinalizer "An empty finalizer, e.g. override def finalize: Unit = {} is redundant and should be removed." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/StoreBeforeReturn.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/StoreBeforeReturn.scala index 53185b4e..f08bd94b 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/StoreBeforeReturn.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/StoreBeforeReturn.scala @@ -11,8 +11,8 @@ class StoreBeforeReturn "Storing a value and then immediately returning it is equivalent to returning the raw value itself." ) { - override def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + override def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { import context.global._ diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnnecessaryConversion.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnnecessaryConversion.scala index 5109df2f..abd7bee5 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnnecessaryConversion.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnnecessaryConversion.scala @@ -1,6 +1,6 @@ package com.sksamuel.scapegoat.inspections.unneccesary -import com.sksamuel.scapegoat.{Inspection, InspectionContext, Inspector, Levels} +import com.sksamuel.scapegoat.{isScala21312, Inspection, InspectionContext, Inspector, Levels} /** * @author @@ -15,45 +15,43 @@ class UnnecessaryConversion "Calling e.g. toString on a String or toList on a List is completely unnecessary and it's an equivalent to identity." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { - override def postTyperTraverser: context.Traverser = - new context.Traverser { + override def isEnabled: Boolean = !isScala21312 - import context.global._ - import definitions._ + def inspector(ctx: InspectionContext): Inspector = new Inspector(ctx) { + override def postTyperTraverser: context.Traverser = new context.Traverser { + import context.global._ + import definitions._ - override def inspect(tree: Tree): Unit = { - tree match { - case Select(lhs, TermName("toString")) if lhs.tpe <:< StringClass.tpe => - context - .warn( - tree.pos, - self, - tree.toString.take(200), - "Unnecessary toString on instance of String." - ) - case Select(lhs, TermName("toInt")) - if lhs.tpe <:< IntClass.tpe && Option(lhs.symbol) - .fold(ifEmpty = true)(_.baseClasses.nonEmpty) => - context.warn(tree.pos, self, tree.toString.take(200), "Unnecessary toInt on instance of Int.") - case Select(lhs, TermName("toLong")) if lhs.tpe <:< LongClass.tpe => - context.warn( - tree.pos, - self, - tree.toString.take(200), - "Unnecessary toLong on instance of Long." - ) - case Select(lhs, TermName("toSet")) if isSet(lhs, allowMutableSet = false) => - context.warn(tree.pos, self, tree.toString.take(200), "Unnecessary toSet on a Set.") - case Select(lhs, TermName("toList")) if isList(lhs) => - context.warn(tree.pos, self, tree.toString.take(200), "Unnecessary toList on a List.") - case Select(lhs, TermName("toSeq")) if isSeq(lhs) => - context.warn(tree.pos, self, tree.toString.take(200), "Unnecessary toSeq on a Seq.") - case _ => - } - continue(tree) - } + override def inspect(tree: Tree): Unit = { + tree match { + case Select(lhs, TermName("toString")) if lhs.tpe <:< StringClass.tpe => + context.warn( + tree.pos, + self, + tree.toString.take(200), + "Unnecessary toString on instance of String." + ) + case Select(lhs, TermName("toInt")) + if lhs.tpe <:< IntClass.tpe && Option(lhs.symbol) + .fold(ifEmpty = true)(_.baseClasses.nonEmpty) => + context.warn(tree.pos, self, tree.toString.take(200), "Unnecessary toInt on instance of Int.") + case Select(lhs, TermName("toLong")) if lhs.tpe <:< LongClass.tpe => + context.warn( + tree.pos, + self, + tree.toString.take(200), + "Unnecessary toLong on instance of Long." + ) + case Select(lhs, TermName("toSet")) if isSet(lhs, allowMutableSet = false) => + context.warn(tree.pos, self, tree.toString.take(200), "Unnecessary toSet on a Set.") + case Select(lhs, TermName("toList")) if isList(lhs) => + context.warn(tree.pos, self, tree.toString.take(200), "Unnecessary toList on a List.") + case Select(lhs, TermName("toSeq")) if isSeq(lhs) => + context.warn(tree.pos, self, tree.toString.take(200), "Unnecessary toSeq on a Seq.") + case _ => } + continue(tree) + } } + } } diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnnecessaryIf.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnnecessaryIf.scala index 1e95bdfb..bb140a11 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnnecessaryIf.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnnecessaryIf.scala @@ -15,8 +15,8 @@ class UnnecessaryIf "If comparison is not needed. Use the condition, e.g. instead of if (a == b) true else false, use a == b or instead of if (a == b) false else true, use !(a == b)." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnnecessaryReturnUse.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnnecessaryReturnUse.scala index 7f107334..30e0f202 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnnecessaryReturnUse.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnnecessaryReturnUse.scala @@ -15,8 +15,8 @@ class UnnecessaryReturnUse "Scala returns the value of the last expression in a block. Use of return here is not an idiomatic Scala." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnusedMethodParameter.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnusedMethodParameter.scala index 4300a715..4ec1719a 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnusedMethodParameter.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/UnusedMethodParameter.scala @@ -16,8 +16,8 @@ class UnusedMethodParameter explanation = "Unused constructor or method parameters should be removed." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/VarCouldBeVal.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/VarCouldBeVal.scala index 4ac3c1f9..23672a2b 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/VarCouldBeVal.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/unneccesary/VarCouldBeVal.scala @@ -16,8 +16,8 @@ class VarCouldBeVal explanation = "A variable (var) that is never written to could be turned into a value (val)." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/AsInstanceOf.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/AsInstanceOf.scala index 5b1226bc..a4b2e3ea 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/AsInstanceOf.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/AsInstanceOf.scala @@ -11,9 +11,9 @@ class AsInstanceOf "Use of asInstanceOf is considered a bad practice - consider using pattern matching instead." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { - override def postTyperTraverser = + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { + override def postTyperTraverser: context.Traverser = new context.Traverser { import context.global._ diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/FinalizerWithoutSuper.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/FinalizerWithoutSuper.scala index 09c7fa6f..a47d6b9c 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/FinalizerWithoutSuper.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/FinalizerWithoutSuper.scala @@ -15,8 +15,8 @@ class FinalizerWithoutSuper "Finalizers should call `super.finalize()` to ensure superclasses are able to run their finalization logic." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/IsInstanceOf.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/IsInstanceOf.scala index 02052c9c..ee3c741b 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/IsInstanceOf.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/IsInstanceOf.scala @@ -15,8 +15,8 @@ class IsInstanceOf "Use of isInstanceOf is considered a bad practice - consider using pattern matching instead." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/TryGet.scala b/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/TryGet.scala index 73df66d7..9aeac5b3 100644 --- a/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/TryGet.scala +++ b/src/main/scala/com/sksamuel/scapegoat/inspections/unsafe/TryGet.scala @@ -15,8 +15,8 @@ class TryGet "Using Try.get is unsafe because it will throw the underlying exception in case of a Failure. Use the following instead: Try.getOrElse, Try.fold, pattern matching or don't take the value out of the container and map over it to transform it." ) { - def inspector(context: InspectionContext): Inspector = - new Inspector(context) { + def inspector(ctx: InspectionContext): Inspector = + new Inspector(ctx) { override def postTyperTraverser: context.Traverser = new context.Traverser { diff --git a/src/main/scala/com/sksamuel/scapegoat/package.scala b/src/main/scala/com/sksamuel/scapegoat/package.scala index eb4db2e5..19ac8849 100644 --- a/src/main/scala/com/sksamuel/scapegoat/package.scala +++ b/src/main/scala/com/sksamuel/scapegoat/package.scala @@ -1,8 +1,9 @@ package com.sksamuel package object scapegoat { - val scalaVersion = util.Properties.versionNumberString - val shortScalaVersion = scalaVersion.split('.').dropRight(1).mkString(".") + val scalaVersion: String = util.Properties.versionNumberString + private val shortScalaVersion = scalaVersion.split('.').dropRight(1).mkString(".") - val isScala213 = shortScalaVersion == "2.13" + val isScala213: Boolean = shortScalaVersion == "2.13" + val isScala21312: Boolean = scalaVersion == "2.13.12" } diff --git a/src/test/scala-2.13/com/sksamuel/scapegoat/inspections/unnecessary/UnusedMethodParameterTest213.scala b/src/test/scala-2.13/com/sksamuel/scapegoat/inspections/unnecessary/UnusedMethodParameterTest213.scala index cf4da348..4a59ef47 100644 --- a/src/test/scala-2.13/com/sksamuel/scapegoat/inspections/unnecessary/UnusedMethodParameterTest213.scala +++ b/src/test/scala-2.13/com/sksamuel/scapegoat/inspections/unnecessary/UnusedMethodParameterTest213.scala @@ -1,22 +1,21 @@ package com.sksamuel.scapegoat.inspections.unnecessary -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.unneccesary.UnusedMethodParameter +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class UnusedMethodParameterTest213 extends InspectionTest { - override val inspections = Seq(new UnusedMethodParameter) + override val inspections: Seq[Inspection] = Seq(new UnusedMethodParameter) "UnusedMethodParameter in Scala 2.13" - { "should not report warning" - { "for unused parameters if they are annotated with @unused (#340)" in { - val code = - """| import scala.annotation.unused - | class Test { - | def foo(@unused a:String, b: Int): Unit = { - | println(b) - | } - | } """.stripMargin + val code = """import scala.annotation.unused + |class Test { + | def foo(@unused a:String, b: Int): Unit = { + | println(b) + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 diff --git a/src/test/scala/com/sksamuel/scapegoat/FeedbackTest.scala b/src/test/scala/com/sksamuel/scapegoat/FeedbackTest.scala index 7661c66a..ab85b132 100644 --- a/src/test/scala/com/sksamuel/scapegoat/FeedbackTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/FeedbackTest.scala @@ -20,7 +20,7 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit description: String, explanation: String ) extends Inspection(text, defaultLevel, description, explanation) { - override def inspector(context: InspectionContext): Inspector = ??? + override def inspector(ctx: InspectionContext): Inspector = ??? } "Feedback" - { @@ -35,13 +35,11 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit val reporter = new StoreReporter(new Settings()) val feedback = new Feedback(reporter, testConfiguration(consoleOutput = true, defaultSourcePrefix)) feedback.warn(position, inspection) - reporter.infos should contain( - StoreReporter.Info( - position, - "[scapegoat] [DummyInspection] My default is Error\n This is explanation.", - reporter.ERROR - ) - ) + reporter.infos should have size 1 + val info = reporter.infos.head + info.pos === position + info.msg === "[scapegoat] [DummyInspection] My default is Error\n This is explanation." + info.severity === reporter.ERROR } "for warning" in { @@ -54,13 +52,11 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit val reporter = new StoreReporter(new Settings()) val feedback = new Feedback(reporter, testConfiguration(consoleOutput = true, defaultSourcePrefix)) feedback.warn(position, inspection) - reporter.infos should contain( - StoreReporter.Info( - position, - "[scapegoat] [DummyInspection] My default is Warning\n This is explanation.", - reporter.WARNING - ) - ) + reporter.infos should have size 1 + val info = reporter.infos.head + info.pos === position + info.msg === "[scapegoat] [DummyInspection] My default is Warning\n This is explanation." + info.severity === reporter.WARNING } "for info" in { @@ -73,13 +69,11 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit val reporter = new StoreReporter(new Settings()) val feedback = new Feedback(reporter, testConfiguration(consoleOutput = true, defaultSourcePrefix)) feedback.warn(position, inspection) - reporter.infos should contain( - StoreReporter.Info( - position, - "[scapegoat] [DummyInspection] My default is Info\n This is explanation.", - reporter.INFO - ) - ) + reporter.infos should have size 1 + val info = reporter.infos.head + info.pos === position + info.msg === "[scapegoat] [DummyInspection] My default is Info\n This is explanation." + info.severity === reporter.INFO } } @@ -161,11 +155,10 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit ) val inspections = Seq(inspectionError, inspectionWarning, inspectionInfo) val reporter = new StoreReporter(new Settings()) - val feedback = - new Feedback( - reporter, - testConfiguration(consoleOutput = false, defaultSourcePrefix, Levels.Warning) - ) + val feedback = new Feedback( + reporter, + testConfiguration(consoleOutput = false, defaultSourcePrefix, Levels.Warning) + ) inspections.foreach(inspection => feedback.warn(position, inspection)) feedback.warningsWithMinimalLevel.length should be(2) feedback.warningsWithMinimalLevel @@ -206,10 +199,9 @@ class FeedbackTest extends AnyFreeSpec with Matchers with OneInstancePerTest wit consoleOutput: Boolean, sourcePrefix: String, minimalLevel: Level = Levels.Info - ) = - TestConfiguration.configuration.copy( - consoleOutput = consoleOutput, - sourcePrefix = sourcePrefix, - minimalLevel = minimalLevel - ) + ) = TestConfiguration.configuration.copy( + consoleOutput = consoleOutput, + sourcePrefix = sourcePrefix, + minimalLevel = minimalLevel + ) } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/AnyUseTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/AnyUseTest.scala index 4c77c5aa..da467370 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/AnyUseTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/AnyUseTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class AnyUseTest extends InspectionTest { - override val inspections = Seq(new AnyUse) + override val inspections = Seq[Inspection](new AnyUse) "AnyUse" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/AsInstanceOfTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/AsInstanceOfTest.scala index 6307d545..6421a892 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/AsInstanceOfTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/AsInstanceOfTest.scala @@ -1,89 +1,90 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.unsafe.AsInstanceOf +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class AsInstanceOfTest extends InspectionTest { - override val inspections = Seq(new AsInstanceOf) + override val inspections: Seq[Inspection] = Seq(new AsInstanceOf) "AsInstanceOf" - { "should report warning" in { val code = """class Test { - def hello : Unit = { - val s : Any = "sammy" - println(s.asInstanceOf[String]) - } - } """.stripMargin + | def hello: Unit = { + | val s: Any = "sammy" + | println(s.asInstanceOf[String]) + | } + |} """.stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } + "should ignore case classes synthetic methods" in { val code = """case class MappingCharFilter(name: String, mappings: (String, String)*)""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "should ignore partial functions" in { - val code = - """object Test { - |val pf :PartialFunction[Any,Unit] = { - | case s : String => println(s) - | case i : Int if i == 4 => println(i) - | case _ => println("no match :(") - |} - |} - """.stripMargin + val code = """object Test { + | val pf: PartialFunction[Any,Unit] = { + | case s: String => println(s) + | case i: Int if i == 4 => println(i) + | case _ => println("no match :(") + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "should ignore @SuppressWarnings when all is set" in { val code = """class Test { - @SuppressWarnings(Array("all")) - def hello : Unit = { - val s : Any = "sammy" - println(s.asInstanceOf[String]) - } - } """.stripMargin + | @SuppressWarnings(Array("all")) + | def hello: Unit = { + | val s: Any = "sammy" + | println(s.asInstanceOf[String]) + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "should ignore @SuppressWarnings when this inspection is set" in { val code = """class Test { - @SuppressWarnings(Array("asinstanceof")) - def hello : Unit = { - val s : Any = "sammy" - println(s.asInstanceOf[String]) - } - } """.stripMargin + | @SuppressWarnings(Array("asinstanceof")) + | def hello: Unit = { + | val s: Any = "sammy" + | println(s.asInstanceOf[String]) + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "should not warn on manifest of class" in { val code = """object Test { - @SuppressWarnings(Array("asinstanceof")) - val mf = manifest[Class[_]] - } """.stripMargin + | @SuppressWarnings(Array("asinstanceof")) + | val mf = manifest[Class[_]] + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "should not warn on GADT pattern matching (#378)" in { - val code = - """ - |sealed trait MyGADT[T] - |final case class VariantInt(value: Int) extends MyGADT[Int] - |final case class VariantString(value: String) extends MyGADT[String] - | - |def doStuff[T](gadt: MyGADT[T]): T = { - | gadt match { - | case VariantInt(value) => value - | case VariantString(value) => value - | } - |} - |""".stripMargin + val code = """sealed trait MyGADT[T] + |final case class VariantInt(value: Int) extends MyGADT[Int] + |final case class VariantString(value: String) extends MyGADT[String] + | + |def doStuff[T](gadt: MyGADT[T]): T = { + | gadt match { + | case VariantInt(value) => value + | case VariantString(value) => value + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/AvoidToMinusOneTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/AvoidToMinusOneTest.scala index 564f326a..8afa3389 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/AvoidToMinusOneTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/AvoidToMinusOneTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class AvoidToMinusOneTest extends InspectionTest { - override val inspections = Seq(new AvoidToMinusOne) + override val inspections = Seq[Inspection](new AvoidToMinusOne) "AvoidToMinusOne" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/ConstantIfTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/ConstantIfTest.scala index 14312116..993e26ed 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/ConstantIfTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/ConstantIfTest.scala @@ -1,49 +1,49 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.unneccesary.ConstantIf +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ConstantIfTest extends InspectionTest { - override val inspections = Seq(new ConstantIf) + override val inspections: Seq[Inspection] = Seq(new ConstantIf) "ConstantIf" - { "should report warning" in { val code = """object Test { - if (1 < 2) { - println("sammy") - } - if (2 < 1) { - println("sammy") - } - if ("sam" == "sam".substring(0)) println("sammy") - if (true) println("sammy") - if (false) println("sammy") - if (1 < System.currentTimeMillis()) println("sammy") - } """.stripMargin + | if (1 < 2) { + | println("sammy") + | } + | if (2 < 1) { + | println("sammy") + | } + | if ("sam" == "sam".substring(0)) println("sammy") + | if (true) println("sammy") + | if (false) println("sammy") + | if (1 < System.currentTimeMillis()) println("sammy") + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 4 } + "should not report warning" - { "for while loops" in { val code = """object Test { while ( true ) { println("sam") } } """ compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for subclasses of TypeCreator" in { - val code = - """import scala.reflect.api.{Mirror, Universe, TypeCreator} - |class Test extends TypeCreator { - | override def apply[U <: Universe with Singleton](m: Mirror[U]): U#Type = { - | if (1 < 2) - | throw new RuntimeException - | else - | null - | } - |} - """.stripMargin + val code = """import scala.reflect.api.{Mirror, Universe, TypeCreator} + |class Test extends TypeCreator { + | override def apply[U <: Universe with Singleton](m: Mirror[U]): U#Type = { + | if (1 < 2) + | throw new RuntimeException + | else + | null + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/DoubleNegationTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/DoubleNegationTest.scala index 33a13392..f3e51d3d 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/DoubleNegationTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/DoubleNegationTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class DoubleNegationTest extends InspectionTest { - override val inspections = Seq(new DoubleNegation) + override val inspections = Seq[Inspection](new DoubleNegation) "DoubleNegation" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/EitherGetTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/EitherGetTest.scala index 0bbdbb69..a014f0ff 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/EitherGetTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/EitherGetTest.scala @@ -1,20 +1,20 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.option.EitherGet +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class EitherGetTest extends InspectionTest { - override val inspections = Seq(new EitherGet) + override val inspections: Seq[Inspection] = Seq(new EitherGet) "either right / left projection get use" - { "should report warning" in { val code = """class Test { - | val l = Left("l") - | l.left.get - | val r = Right("r") - | r.right.get - } """.stripMargin + | val l = Left("l") + | l.left.get + | val r = Right("r") + | r.right.get + }""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 2 diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/FinalModifierOnCaseClassTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/FinalModifierOnCaseClassTest.scala index bfd52e2b..27085fc7 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/FinalModifierOnCaseClassTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/FinalModifierOnCaseClassTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class FinalModifierOnCaseClassTest extends InspectionTest { - override val inspections = Seq(new FinalModifierOnCaseClass) + override val inspections = Seq[Inspection](new FinalModifierOnCaseClass) private def assertFinalModOnCaseClass(code: String): Unit = { compileCodeSnippet(code) diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/FinalizerWithoutSuperTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/FinalizerWithoutSuperTest.scala index 1cf7a8c7..0a7ffb05 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/FinalizerWithoutSuperTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/FinalizerWithoutSuperTest.scala @@ -1,73 +1,72 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.unsafe.FinalizerWithoutSuper +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class FinalizerWithoutSuperTest extends InspectionTest { - override val inspections = Seq(new FinalizerWithoutSuper) + override val inspections: Seq[Inspection] = Seq(new FinalizerWithoutSuper) "FinalizerWithoutSuper" - { "should report warning" - { "when empty finalizer" in { - val code = - """class Test { - | override def finalize { - | } - |} """.stripMargin + val code = """class Test { + | override def finalize { + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } + "when non finalizer" in { - val code = - """class Test { - | override def finalize { - | println("sam") - | } - |} """.stripMargin + val code = """class Test { + | override def finalize { + | println("sam") + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } } } + "FinalizerWithoutSuper" - { "should not report warning" - { "when def contains super.finalize() as first call" in { - val code = - """class Test { - | override def finalize { - | super.finalize() - | println("sam") - | } - |} """.stripMargin + val code = """class Test { + | override def finalize { + | super.finalize() + | println("sam") + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "when def contains super.finalize() as intermediate call" in { - val code = - """class Test { - | override def finalize { - | println("sam") - | super.finalize() - | println("sam") - | } - |} """.stripMargin + val code = """class Test { + | override def finalize { + | println("sam") + | super.finalize() + | println("sam") + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "when def contains super.finalize() as final call" in { - val code = - """class Test { - | override def finalize { - | println("sam") - | super.finalize() - | } - |} """.stripMargin + val code = """class Test { + | override def finalize { + | println("sam") + | super.finalize() + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/IsInstanceOfTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/IsInstanceOfTest.scala index 7b026d13..beaae079 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/IsInstanceOfTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/IsInstanceOfTest.scala @@ -1,65 +1,65 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.unsafe.IsInstanceOf +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class IsInstanceOfTest extends InspectionTest { - override val inspections = Seq(new IsInstanceOf) - - List(1).size + override val inspections: Seq[Inspection] = Seq[Inspection](new IsInstanceOf) "isInstanceOf" - { "should report warning" in { val code = """class Test { - def hello : Unit = { - val s : Any = "sammy" - println(s.isInstanceOf[String]) - } - } """.stripMargin + | def hello: Unit = { + | val s: Any = "sammy" + | println(s.isInstanceOf[String]) + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } + "should ignore case classes synthetic methods" in { val code = """case class MappingCharFilter(name: String, mappings: (String, String)*)""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "should ignore partial functions" in { - val code = - """object Test { - |val pf :PartialFunction[Any,Unit] = { - | case s : String => println(s) - | case i : Int if i == 4 => println(i) - | case _ => println("no match :(") - |} - |} - """.stripMargin + val code = """object Test { + | val pf: PartialFunction[Any,Unit] = { + | case s: String => println(s) + | case i: Int if i == 4 => println(i) + | case _ => println("no match :(") + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "should ignore @SuppressWarnings when all is set" in { val code = """class Test { - @SuppressWarnings(Array("all")) - def hello : Unit = { - val s : Any = "sammy" - println(s.asInstanceOf[String]) - } - } """.stripMargin + | @SuppressWarnings(Array("all")) + | def hello: Unit = { + | val s: Any = "sammy" + | println(s.asInstanceOf[String]) + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "should ignore @SuppressWarnings when this inspection is set" in { val code = """class Test { - @SuppressWarnings(Array("asinstanceof")) - def hello : Unit = { - val s : Any = "sammy" - println(s.asInstanceOf[String]) - } - } """.stripMargin + | @SuppressWarnings(Array("asinstanceof")) + | def hello: Unit = { + | val s: Any = "sammy" + | println(s.asInstanceOf[String]) + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/LonelySealedTraitTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/LonelySealedTraitTest.scala index c99e3181..3a6272e8 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/LonelySealedTraitTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/LonelySealedTraitTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class LonelySealedTraitTest extends InspectionTest { - override val inspections = Seq(new LonelySealedTrait) + override val inspections = Seq[Inspection](new LonelySealedTrait) "LonelySealedTrait" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/MaxParameterTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/MaxParameterTest.scala index c3910d75..f9c4202b 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/MaxParameterTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/MaxParameterTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class MaxParameterTest extends InspectionTest { - override val inspections = Seq(new MaxParameters) + override val inspections = Seq[Inspection](new MaxParameters) "MaxParameters" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/MethodReturningAnyTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/MethodReturningAnyTest.scala index 21d9b7bb..4a7b5d63 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/MethodReturningAnyTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/MethodReturningAnyTest.scala @@ -1,47 +1,45 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.inference.MethodReturningAny +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class MethodReturningAnyTest extends InspectionTest { - override val inspections = Seq(new MethodReturningAny) + override val inspections: Seq[Inspection] = Seq(new MethodReturningAny) "MethodReturningAny" - { "should report warning" - { "for methods returning any" in { - val code = """class Test { - def foo : Any = 1 - } """.stripMargin + | def foo: Any = 1 + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } } + "should not report warning" - { "for methods returning <:< Any" in { - - val code = - """class Test { - | def foo : Int = 4 - | def boo : String = "sam" - |} """.stripMargin + val code = """class Test { + | def foo: Int = 4 + | def boo: String = "sam" + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for overridden methods returning any" in { - val code = - """object T { - trait A { - def foo : AnyRef = "foo" - } - class B extends A { - override def foo : AnyRef = "overridden foo" - } - |} """.stripMargin + val code = """object T { + | trait A { + | def foo: AnyRef = "foo" + | } + | class B extends A { + | override def foo: AnyRef = "overridden foo" + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/PublicFinalizerTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/PublicFinalizerTest.scala index 9f0b264f..904366a3 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/PublicFinalizerTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/PublicFinalizerTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class PublicFinalizerTest extends InspectionTest { - override val inspections = Seq(new PublicFinalizer) + override val inspections = Seq[Inspection](new PublicFinalizer) "public finalizer" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnMethodTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnMethodTest.scala index 1891a1f3..c885ae78 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnMethodTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnMethodTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class RedundantFinalModifierOnMethodTest extends InspectionTest { - override val inspections = Seq(new RedundantFinalModifierOnMethod) + override val inspections = Seq[Inspection](new RedundantFinalModifierOnMethod) "RedundantFinalModifierOnMethod" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnVarTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnVarTest.scala index 4c23a930..319c9c5c 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnVarTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/RedundantFinalModifierOnVarTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class RedundantFinalModifierOnVarTest extends InspectionTest { - override val inspections = Seq(new RedundantFinalModifierOnVar) + override val inspections = Seq[Inspection](new RedundantFinalModifierOnVar) "RedundantFinalModifierOnVar" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/TryGetTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/TryGetTest.scala index ff9a9e56..6b735658 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/TryGetTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/TryGetTest.scala @@ -1,22 +1,21 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.unsafe.TryGet +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class TryGetTest extends InspectionTest { - override val inspections = Seq(new TryGet) + override val inspections: Seq[Inspection] = Seq(new TryGet) "try.get use" - { "should report warning" in { - val code = """class Test { - import scala.util.Try - Try { - println("sam") - }.get - } """.stripMargin + | import scala.util.Try + | Try { + | println("sam") + | }.get + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/TypeShadowingTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/TypeShadowingTest.scala index 72c9c852..3721b1d6 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/TypeShadowingTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/TypeShadowingTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class TypeShadowingTest extends InspectionTest { - override val inspections = Seq(new TypeShadowing) + override val inspections = Seq[Inspection](new TypeShadowing) "TypeShadowing" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/VarClosureTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/VarClosureTest.scala index 262a7a9e..db06b91e 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/VarClosureTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/VarClosureTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class VarClosureTest extends InspectionTest { - override val inspections = Seq(new VarClosure) + override val inspections = Seq[Inspection](new VarClosure) "VarClosure" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/VarCouldBeValTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/VarCouldBeValTest.scala index 37b0a221..c87a0434 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/VarCouldBeValTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/VarCouldBeValTest.scala @@ -1,59 +1,55 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.unneccesary.VarCouldBeVal +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class VarCouldBeValTest extends InspectionTest { - override val inspections = Seq(new VarCouldBeVal) + override val inspections: Seq[Inspection] = Seq(new VarCouldBeVal) "Var could be Val" - { "should report warning" - { "when a local var is not written to in the method" in { - - val code = - """object Test { - | def foo { - | var count = 1 - | println(count) - | for (k <- 1 until 10) { - | println(k + count) - | } - | } - |}""".stripMargin + val code = """object Test { + | def foo { + | var count = 1 + | println(count) + | for (k <- 1 until 10) { + | println(k + count) + | } + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } - "when a local var is not written to in the method or nested methods" in { - val code = - """object Test { - | def foo { - | var count = 1 - | println(count) - | def boo(n : Int) : Unit = { - | println(n + count) - | } - | for (k <- 1 until 10) { - | println(k + count) - | } - | } - |}""".stripMargin + "when a local var is not written to in the method or nested methods" in { + val code = """object Test { + | def foo { + | var count = 1 + | println(count) + | def boo(n: Int): Unit = { + | println(n + count) + | } + | for (k <- 1 until 10) { + | println(k + count) + | } + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } "with correct line numbers" in { - val code = - """object Test { - | def foo { - | var bar = 1 - | val myValue = 2 - | var baz = 3 - | } - |}""".stripMargin + val code = """object Test { + | def foo { + | var bar = 1 + | val myValue = 2 + | var baz = 3 + | } + |}""".stripMargin compileCodeSnippet(code) val warningsInOrder = compiler.scapegoat.feedback.warnings.sortBy(_.line) @@ -68,144 +64,137 @@ class VarCouldBeValTest extends InspectionTest { } } } + "should not report warning" - { "when var is written to in the method" in { - - val code = - """object Test { - | def foo { - | var count = 1 - | println(count) - | for (k <- 1 until 10) { - | count = count + 1 - | println(k + count) - | } - | } - |}""".stripMargin + val code = """object Test { + | def foo { + | var count = 1 + | println(count) + | for (k <- 1 until 10) { + | count = count + 1 + | println(k + count) + | } + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "when var is written to in a nested method" in { - val code = - """object Test { - | def foo { - | var count = 1 - | println(count) - | def boo(n : Int) : Unit = { - | count = n - | println( count) - | } - | for (k <- 1 until 10) { - | println(k + count) - | } - | } - |}""".stripMargin + "when var is written to in a nested method" in { + val code = """object Test { + | def foo { + | var count = 1 + | println(count) + | def boo(n: Int): Unit = { + | count = n + | println( count) + | } + | for (k <- 1 until 10) { + | println(k + count) + | } + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "when var is written to inside a finally block" in { - val code = - """object Test { - | def foo { - | var count = 1 - | try { - | println("sam") - | } finally { - | count = 2 - | } - | } - |}""".stripMargin + val code = """object Test { + | def foo { + | var count = 1 + | try { + | println("sam") + | } finally { + | count = 2 + | } + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "when var is written to inside an if else branch" in { - val code = - """object Test { - | def foo { - | var count = 1 - | if (count == 10) { - | println("sam") - | } else { - | count = count + 1 - | } - | } - |}""".stripMargin + val code = """object Test { + | def foo { + | var count = 1 + | if (count == 10) { + | println("sam") + | } else { + | count = count + 1 + | } + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "when var is written to inside a match" in { - val code = - """object Test { - | def foo { - | var count = 1 - | count match { - | case 10 => println("sam") - | case _ => count = count + 1 - | } - | } - |}""".stripMargin + val code = """object Test { + | def foo { + | var count = 1 + | count match { + | case 10 => println("sam") + | case _ => count = count + 1 + | } + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "when var is written to inside an if " in { - val code = - """package com.sammy - |object Test { - |def test(b: Boolean): Int = { - | var count = 0 - | if (b) count += 1 - | count - |} - |}""".stripMargin + "when var is written to inside an if " in { + val code = """package com.sammy + |object Test { + | def test(b: Boolean): Int = { + | var count = 0 + | if (b) count += 1 + | count + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "when var is written to inside a while condition " in { - val code = - """package com.sammy - |object Test { - |def something(): List[String] = List("a") - |def test(): Unit = { - | var items = List.empty[String] - | while ({ - | items = something() - | items.size - | } < 10) { - | println(items) - | } - |} - |}""".stripMargin + "when var is written to inside a while condition " in { + val code = """package com.sammy + |object Test { + | def something(): List[String] = List("a") + | def test(): Unit = { + | var items = List.empty[String] + | while ({ + | items = something() + | items.size + | } < 10) { + | println(items) + | } + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } "when var is written to for nested defs" in { - val code = - """ - |package com.sam - |trait Iterator { - | def next : Int - |} - |object Test { - | val iterator = new Iterator { - | var last = -1 - | def next: Int = { - | last = last + 1 - | last - | } - | } - |} - """.stripMargin + val code = """package com.sam + |trait Iterator { + | def next: Int + |} + |object Test { + | val iterator = new Iterator { + | var last = -1 + | def next: Int = { + | last = last + 1 + | last + | } + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/VarUseTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/VarUseTest.scala index a8330dcf..40f881cc 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/VarUseTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/VarUseTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class VarUseTest extends InspectionTest { - override val inspections = Seq(new VarUse) + override val inspections = Seq[Inspection](new VarUse) "var keyword use" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/VariableShadowingTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/VariableShadowingTest.scala index f175b137..ff88a40e 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/VariableShadowingTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/VariableShadowingTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class VariableShadowingTest extends InspectionTest { - override val inspections = Seq(new VariableShadowing) + override val inspections = Seq[Inspection](new VariableShadowing) "VariableShadowing" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/WhileTrueTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/WhileTrueTest.scala index 044c6c22..4ce4544f 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/WhileTrueTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/WhileTrueTest.scala @@ -1,37 +1,34 @@ package com.sksamuel.scapegoat.inspections -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.controlflow.WhileTrue +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class WhileTrueTest extends InspectionTest { - override val inspections = Seq(new WhileTrue) + override val inspections: Seq[Inspection] = Seq(new WhileTrue) "while loop" - { "when constant" - { "should report warning" in { - - val code = """ - object Test { - while (true) { - println("sam") - } - } """.stripMargin + val code = """object Test { + | while (true) { + | println("sam") + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } } + "when not constant" - { "should not report warning" in { - - val code = """ - object Test { - while (System.currentTimeMillis > 0) { - println("sam") - } - } """.stripMargin + val code = """object Test { + | while (System.currentTimeMillis > 0) { + | println("sam") + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 @@ -42,27 +39,24 @@ class WhileTrueTest extends InspectionTest { "do while loop" - { "when constant" - { "should report warning" in { - - val code = """ - object Test { - do { - println("sam") - } while (true) - } """.stripMargin + val code = """object Test { + | do { + | println("sam") + | } while (true) + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } } + "when not constant" - { "should not report warning" in { - - val code = """ - object Test { - do { - println("sam") - } while (System.currentTimeMillis > 0) - } """.stripMargin + val code = """object Test { + | do { + | println("sam") + | } while (System.currentTimeMillis > 0) + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ArrayEqualsTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ArrayEqualsTest.scala index 1aa28aa2..e1dddc46 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ArrayEqualsTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ArrayEqualsTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ArrayEqualsTest extends InspectionTest { - override val inspections = Seq(new ArrayEquals) + override val inspections = Seq[Inspection](new ArrayEquals) "ArrayEquals" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeEqualsZeroTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeEqualsZeroTest.scala index eb040a37..3e3de708 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeEqualsZeroTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeEqualsZeroTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class AvoidSizeEqualsZeroTest extends InspectionTest { - override val inspections = Seq(new AvoidSizeEqualsZero) + override val inspections = Seq[Inspection](new AvoidSizeEqualsZero) "collection.size == 0" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZeroTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZeroTest.scala index 704f3792..3319cd01 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZeroTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/AvoidSizeNotEqualsZeroTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class AvoidSizeNotEqualsZeroTest extends InspectionTest { - override val inspections = Seq(new AvoidSizeNotEqualsZero) + override val inspections = Seq[Inspection](new AvoidSizeNotEqualsZero) "collection.size != 0" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionIndexOnNonIndexedSeqTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionIndexOnNonIndexedSeqTest.scala index 91c66592..3258acf6 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionIndexOnNonIndexedSeqTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionIndexOnNonIndexedSeqTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Josh Rosen */ class CollectionIndexOnNonIndexedSeqTest extends InspectionTest { - override val inspections = Seq(new CollectionIndexOnNonIndexedSeq) + override val inspections = Seq[Inspection](new CollectionIndexOnNonIndexedSeq) "collection index on non indexed seq" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNamingConfusionTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNamingConfusionTest.scala index 50671a28..92f61c0c 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNamingConfusionTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNamingConfusionTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class CollectionNamingConfusionTest extends InspectionTest { - override val inspections = Seq(new CollectionNamingConfusion) + override val inspections = Seq[Inspection](new CollectionNamingConfusion) "collection confusing names" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNegativeIndexTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNegativeIndexTest.scala index beedeec1..c0c72ee7 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNegativeIndexTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionNegativeIndexTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class CollectionNegativeIndexTest extends InspectionTest { - override val inspections = Seq(new CollectionNegativeIndex) + override val inspections = Seq[Inspection](new CollectionNegativeIndex) "collection negative index" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionPromotionToAnyTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionPromotionToAnyTest.scala index 64d5f2d2..e2c721dd 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionPromotionToAnyTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/CollectionPromotionToAnyTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class CollectionPromotionToAnyTest extends InspectionTest { - override val inspections = Seq(new CollectionPromotionToAny) + override val inspections = Seq[Inspection](new CollectionPromotionToAny) "CollectionPromotionToAny" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptyListTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptyListTest.scala index 204e68c8..83d1d5c7 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptyListTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptyListTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ComparisonToEmptyListTest extends InspectionTest { - override val inspections = Seq(new ComparisonToEmptyList) + override val inspections = Seq[Inspection](new ComparisonToEmptyList) "ComparisonToEmptyList" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptySetTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptySetTest.scala index af4143d2..9a6ff69b 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptySetTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ComparisonToEmptySetTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ComparisonToEmptySetTest extends InspectionTest { - override val inspections = Seq(new ComparisonToEmptySet) + override val inspections = Seq[Inspection](new ComparisonToEmptySet) "ComparisonToEmptySet" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateMapKeyTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateMapKeyTest.scala index 3fbbaca0..dec0d75e 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateMapKeyTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateMapKeyTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class DuplicateMapKeyTest extends InspectionTest { - override val inspections = Seq(new DuplicateMapKey) + override val inspections = Seq[Inspection](new DuplicateMapKey) "DuplicateMapKey" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateSetValueTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateSetValueTest.scala index 9d7460db..e168f27c 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateSetValueTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/DuplicateSetValueTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class DuplicateSetValueTest extends InspectionTest { - override val inspections = Seq(new DuplicateSetValue) + override val inspections = Seq[Inspection](new DuplicateSetValue) "duplicate set literals" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHeadOptionTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHeadOptionTest.scala index f743be2a..fefa46e5 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHeadOptionTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHeadOptionTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class FilterDotHeadOptionTest extends InspectionTest { - override val inspections = Seq(new FilterDotHeadOption) + override val inspections = Seq[Inspection](new FilterDotHeadOption) "self assignment" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHeadTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHeadTest.scala index 279bb8fc..7fac016a 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHeadTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotHeadTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class FilterDotHeadTest extends InspectionTest { - override val inspections = Seq(new FilterDotHead) + override val inspections = Seq[Inspection](new FilterDotHead) "self assignment" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotIsEmptyTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotIsEmptyTest.scala index 460abeac..6f73d254 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotIsEmptyTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotIsEmptyTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class FilterDotIsEmptyTest extends InspectionTest { - override val inspections = Seq(new FilterDotIsEmpty) + override val inspections = Seq[Inspection](new FilterDotIsEmpty) "self assignment" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotSizeTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotSizeTest.scala index 8646f7db..79d3463c 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotSizeTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterDotSizeTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class FilterDotSizeTest extends InspectionTest { - override val inspections = Seq(new FilterDotSize) + override val inspections = Seq[Inspection](new FilterDotSize) "filter then size" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterOptionAndGetTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterOptionAndGetTest.scala index d5d2112f..d8988990 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterOptionAndGetTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FilterOptionAndGetTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class FilterOptionAndGetTest extends InspectionTest { - override val inspections = Seq(new FilterOptionAndGet) + override val inspections = Seq[Inspection](new FilterOptionAndGet) "filter then size" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FindAndNotEqualsNoneReplaceWithExistsTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FindAndNotEqualsNoneReplaceWithExistsTest.scala index c031e2da..1284e1b0 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FindAndNotEqualsNoneReplaceWithExistsTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FindAndNotEqualsNoneReplaceWithExistsTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class FindAndNotEqualsNoneReplaceWithExistsTest extends InspectionTest { - override val inspections = Seq(new FindAndNotEqualsNoneReplaceWithExists) + override val inspections = Seq[Inspection](new FindAndNotEqualsNoneReplaceWithExists) "FindAndNotEqualsNoneReplaceWithExists" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FindDotIsDefinedTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FindDotIsDefinedTest.scala index 127aa058..febbc1a9 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FindDotIsDefinedTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/FindDotIsDefinedTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class FindDotIsDefinedTest extends InspectionTest { - override val inspections = Seq(new FindDotIsDefined) + override val inspections = Seq[Inspection](new FindDotIsDefined) "filter then size" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/JavaConversionsUseTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/JavaConversionsUseTest.scala index 8397fd44..668350b9 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/JavaConversionsUseTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/JavaConversionsUseTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.{isScala213, InspectionTest} +import com.sksamuel.scapegoat.{isScala213, Inspection, InspectionTest} /** @author Stephen Samuel */ class JavaConversionsUseTest extends InspectionTest { - override val inspections = Seq(new JavaConversionsUse) + override val inspections = Seq[Inspection](new JavaConversionsUse) "JavaConversionsUse" - { "should report warning (for Scala < 2.13)" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ListAppendTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ListAppendTest.scala index edad5658..388ccf3d 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ListAppendTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ListAppendTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ListAppendTest extends InspectionTest { - override val inspections = Seq(new ListAppend) + override val inspections = Seq[Inspection](new ListAppend) "list.append use" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ListSizeTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ListSizeTest.scala index ef35b787..0872955a 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ListSizeTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ListSizeTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ListSizeTest extends InspectionTest { - override val inspections = Seq(new ListSize) + override val inspections = Seq[Inspection](new ListSize) "list.size use" - { "should report warning" - { 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 61eb54e1..d19f0c45 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/MapGetAndGetOrElseTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/MapGetAndGetOrElseTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class MapGetAndGetOrElseTest extends InspectionTest { - override val inspections = Seq(new MapGetAndGetOrElse) + override val inspections = Seq[Inspection](new MapGetAndGetOrElse) private def getOrElseAssertion(code: String): Unit = { compileCodeSnippet(code) diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/NegationIsEmptyTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/NegationIsEmptyTest.scala index 22378f2d..7ffbdf00 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/NegationIsEmptyTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/NegationIsEmptyTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class NegationIsEmptyTest extends InspectionTest { - override val inspections = Seq(new NegationIsEmpty) + override val inspections = Seq[Inspection](new NegationIsEmpty) "!isEmpty" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/NegationNonEmptyTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/NegationNonEmptyTest.scala index 4c23fefa..0288f2ab 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/NegationNonEmptyTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/NegationNonEmptyTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class NegationNonEmptyTest extends InspectionTest { - override val inspections = Seq(new NegationNonEmpty) + override val inspections = Seq[Inspection](new NegationNonEmpty) "!nonEmpty" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/NegativeSeqPadTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/NegativeSeqPadTest.scala index 243c924b..eecc6ab3 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/NegativeSeqPadTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/NegativeSeqPadTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class NegativeSeqPadTest extends InspectionTest { - override val inspections = Seq(new NegativeSeqPad) + override val inspections = Seq[Inspection](new NegativeSeqPad) "self assignment" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PredefSeqIsMutableTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PredefSeqIsMutableTest.scala index a10b1cbd..291d7eea 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PredefSeqIsMutableTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PredefSeqIsMutableTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.{isScala213, InspectionTest} +import com.sksamuel.scapegoat.{isScala213, Inspection, InspectionTest} /** @author Stephen Samuel */ class PredefSeqIsMutableTest extends InspectionTest { - override val inspections = Seq(new PredefSeqIsMutable) + override val inspections = Seq[Inspection](new PredefSeqIsMutable) "PredefSeqUse" - { "should report warning (for Scala < 2.13)" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PredefTraversableIsMutableTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PredefTraversableIsMutableTest.scala index 4a98ef68..e41e6061 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PredefTraversableIsMutableTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PredefTraversableIsMutableTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.{isScala213, InspectionTest} +import com.sksamuel.scapegoat.{isScala213, Inspection, InspectionTest} /** @author Stephen Samuel */ class PredefTraversableIsMutableTest extends InspectionTest { - override val inspections = Seq(new PredefTraversableIsMutable) + override val inspections = Seq[Inspection](new PredefTraversableIsMutable) "PredefTraversableIsMutable" - { "should report warning (for Scala < 2.13)" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PreferMapEmptyTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PreferMapEmptyTest.scala index fae219dc..79259b8b 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PreferMapEmptyTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PreferMapEmptyTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class PreferMapEmptyTest extends InspectionTest { - override val inspections = Seq(new PreferMapEmpty) + override val inspections = Seq[Inspection](new PreferMapEmpty) "should report warning" - { "with map apply" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PreferSeqEmptyTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PreferSeqEmptyTest.scala index e6d9e033..65712f7a 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PreferSeqEmptyTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PreferSeqEmptyTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class PreferSeqEmptyTest extends InspectionTest { - override val inspections = Seq(new PreferSeqEmpty) + override val inspections = Seq[Inspection](new PreferSeqEmpty) "should report warning" - { "with empty seq apply" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PreferSetEmptyTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PreferSetEmptyTest.scala index c2aad784..c7d28f34 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PreferSetEmptyTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/PreferSetEmptyTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class PreferSetEmptyTest extends InspectionTest { - override val inspections = Seq(new PreferSetEmpty) + override val inspections = Seq[Inspection](new PreferSetEmpty) "set apply" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ReverseFuncTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ReverseFuncTest.scala index 8c4f1b5b..9a8d66b1 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ReverseFuncTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ReverseFuncTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class ReverseFuncTest extends InspectionTest { - override val inspections = Seq(new ReverseFunc) + override val inspections = Seq[Inspection](new ReverseFunc) "ReverseFunc" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTailReverseTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTailReverseTest.scala index 44719561..984f5bf1 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTailReverseTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTailReverseTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class ReverseTailReverseTest extends InspectionTest { - override val inspections = Seq(new ReverseTailReverse) + override val inspections = Seq[Inspection](new ReverseTailReverse) "ReverseTailReverse" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTakeReverseTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTakeReverseTest.scala index 772877c1..bdbe2948 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTakeReverseTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/ReverseTakeReverseTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class ReverseTakeReverseTest extends InspectionTest { - override val inspections = Seq(new ReverseTakeReverse) + override val inspections = Seq[Inspection](new ReverseTakeReverse) "ReverseTakeReverse" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/SwapSortFilterTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/SwapSortFilterTest.scala index 86411292..33d6441e 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/SwapSortFilterTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/SwapSortFilterTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class SwapSortFilterTest extends InspectionTest { - override val inspections = Seq(new SwapSortFilter) + override val inspections = Seq[Inspection](new SwapSortFilter) "sort then filter" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeContainsTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeContainsTest.scala index 4235a4ba..66bc5e3f 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeContainsTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeContainsTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class UnsafeContainsTest extends InspectionTest { - override val inspections = Seq(new UnsafeContains) + override val inspections = Seq[Inspection](new UnsafeContains) "unsafe contains" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeTraversableMethodsTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeTraversableMethodsTest.scala index 08268197..a4fd275b 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeTraversableMethodsTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/collections/UnsafeTraversableMethodsTest.scala @@ -1,10 +1,10 @@ package com.sksamuel.scapegoat.inspections.collections -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class UnsafeTraversableMethodsTest extends InspectionTest { - override val inspections = Seq(new UnsafeTraversableMethods) + override val inspections = Seq[Inspection](new UnsafeTraversableMethods) val unsafeMethodUsages = Set( "head", diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/controlflow/RepeatedIfElseBodyTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/controlflow/RepeatedIfElseBodyTest.scala index 8e1133c7..da284f26 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/controlflow/RepeatedIfElseBodyTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/controlflow/RepeatedIfElseBodyTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections.controlflow -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class RepeatedIfElseBodyTest extends InspectionTest { - override val inspections = Seq(new RepeatedIfElseBody) + override val inspections = Seq[Inspection](new RepeatedIfElseBody) "repeated if else body" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyCaseClassTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyCaseClassTest.scala index 706334a5..5d7da93e 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyCaseClassTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyCaseClassTest.scala @@ -1,12 +1,12 @@ package com.sksamuel.scapegoat.inspections.empty -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.EmptyCaseClass +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class EmptyCaseClassTest extends InspectionTest { - override val inspections = Seq(new EmptyCaseClass) + override val inspections: Seq[Inspection] = Seq(new EmptyCaseClass) "empty class classes" - { "should report warning" - { @@ -15,55 +15,53 @@ class EmptyCaseClassTest extends InspectionTest { compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } + "for empty case classes with methods" in { val code = """case class Empty() { - def foo = "boo" - }""".stripMargin + | def foo = "boo" + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } } + "should not report warning" - { "for empty classes" in { val code = """object Test { - class Empty() - } - """.stripMargin + | class Empty() + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for none empty case classes" in { val code = """object Test { - case class Empty(name:String) - } - """.stripMargin + | case class Empty(name:String) + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for case objects" in { val code = """object Test { - case object Empty - } - """.stripMargin + | case object Empty + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for extended classes" in { - val code = - """ - | abstract class Attr(val name: String) { - | override def toString: String = name - | override def hashCode: Int = name.hashCode - | override def equals(obj: Any): Boolean = false - | } - | case class TestClass(bool: Boolean) extends Attr("test") - """.stripMargin + val code = """abstract class Attr(val name: String) { + | override def toString: String = name + | override def hashCode: Int = name.hashCode + | override def equals(obj: Any): Boolean = false + |} + |case class TestClass(bool: Boolean) extends Attr("test")""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 - } } } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyForTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyForTest.scala index 5b40983d..b9ac0f9a 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyForTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyForTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.empty -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class EmptyForTest extends InspectionTest { - override val inspections = Seq(new EmptyFor) + override val inspections = Seq[Inspection](new EmptyFor) "EmptyFor" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyIfBlockTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyIfBlockTest.scala index e3757b71..bcb37d9a 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyIfBlockTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyIfBlockTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.empty -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class EmptyIfBlockTest extends InspectionTest { - override val inspections = Seq(new EmptyIfBlock) + override val inspections = Seq[Inspection](new EmptyIfBlock) "empty if block" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyMethodTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyMethodTest.scala index 64bc9dc8..5fea6eea 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyMethodTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyMethodTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.empty -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class EmptyMethodTest extends InspectionTest { - override val inspections = Seq(new EmptyMethod) + override val inspections = Seq[Inspection](new EmptyMethod) "empty method" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptySynchronizedBlockTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptySynchronizedBlockTest.scala index c54d287f..74c03297 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptySynchronizedBlockTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptySynchronizedBlockTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.empty -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class EmptySynchronizedBlockTest extends InspectionTest { - override val inspections = Seq(new EmptySynchronizedBlock) + override val inspections = Seq[Inspection](new EmptySynchronizedBlock) "empty empty" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyTryBlockTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyTryBlockTest.scala index ec0c9251..faa1b560 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyTryBlockTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyTryBlockTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.empty -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class EmptyTryBlockTest extends InspectionTest { - override val inspections = Seq(new EmptyTryBlock) + override val inspections = Seq[Inspection](new EmptyTryBlock) "empty try block" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyWhileBlockTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyWhileBlockTest.scala index e5a56190..98b3c9e4 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyWhileBlockTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/EmptyWhileBlockTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.empty -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class EmptyWhileBlockTest extends InspectionTest { - override val inspections = Seq(new EmptyWhileBlock) + override val inspections = Seq[Inspection](new EmptyWhileBlock) "empty while block" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/RedundantFinalizerTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/RedundantFinalizerTest.scala index a9c9ef68..33a169fe 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/empty/RedundantFinalizerTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/empty/RedundantFinalizerTest.scala @@ -1,21 +1,20 @@ package com.sksamuel.scapegoat.inspections.empty -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.unneccesary.RedundantFinalizer +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class RedundantFinalizerTest extends InspectionTest { - override val inspections = Seq(new RedundantFinalizer) + override val inspections: Seq[Inspection] = Seq(new RedundantFinalizer) "redundant finalizer" - { "should report warning" in { - val code = """class Test { - override def finalize : Unit = {} - override def hashCode : Int = 3 - def empty = {} - } """.stripMargin + | override def finalize: Unit = {} + | override def hashCode: Int = 3 + | def empty = {} + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/equality/ComparingFloatingPointTypesTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/equality/ComparingFloatingPointTypesTest.scala index 9ce35073..5bedec2a 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/equality/ComparingFloatingPointTypesTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/equality/ComparingFloatingPointTypesTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.equality -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ComparingFloatingPointTypesTest extends InspectionTest { - override val inspections = Seq(new ComparingFloatingPointTypes) + override val inspections = Seq[Inspection](new ComparingFloatingPointTypes) "comparing floating type inspection" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/equality/ComparisonWithSelfInspectionTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/equality/ComparisonWithSelfInspectionTest.scala index cb202fe3..af78c441 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/equality/ComparisonWithSelfInspectionTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/equality/ComparisonWithSelfInspectionTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.equality -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ComparisonWithSelfInspectionTest extends InspectionTest { - override val inspections = Seq(new ComparisonWithSelf) + override val inspections = Seq[Inspection](new ComparisonWithSelf) "ComparisonWithSelf" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchExceptionImmediatelyRethrownTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchExceptionImmediatelyRethrownTest.scala index 9a753a2b..54e088ff 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchExceptionImmediatelyRethrownTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchExceptionImmediatelyRethrownTest.scala @@ -1,10 +1,10 @@ package com.sksamuel.scapegoat.inspections.exception -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class CatchExceptionImmediatelyRethrownTest extends InspectionTest { - override val inspections = Seq(new CatchExceptionImmediatelyRethrown) + override val inspections = Seq[Inspection](new CatchExceptionImmediatelyRethrown) "catch exception immediately throw" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchExceptionTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchExceptionTest.scala index 1d1aba3e..7dc08704 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchExceptionTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchExceptionTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.exception -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Marconi Lanna */ class CatchExceptionTest extends InspectionTest { - override val inspections = Seq(new CatchException) + override val inspections = Seq[Inspection](new CatchException) "catch _ exception" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchFatalTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchFatalTest.scala index 2cc80878..3629f56c 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchFatalTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchFatalTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.exception -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Marconi Lanna */ class CatchFatalTest extends InspectionTest { - override val inspections = Seq(new CatchFatal) + override val inspections = Seq[Inspection](new CatchFatal) "catch _ fatal exception" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchNpeTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchNpeTest.scala index 090b6874..575f5c4c 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchNpeTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchNpeTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.exception -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class CatchNpeTest extends InspectionTest { - override val inspections = Seq(new CatchNpe) + override val inspections = Seq[Inspection](new CatchNpe) "catching null pointer exception" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchThrowableTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchThrowableTest.scala index 90c8fbd0..7891e36f 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchThrowableTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/CatchThrowableTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.exception -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class CatchThrowableTest extends InspectionTest { - override val inspections = Seq(new CatchThrowable) + override val inspections = Seq[Inspection](new CatchThrowable) "catch _ throwable" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/IncorrectlyNamedExceptionsTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/IncorrectlyNamedExceptionsTest.scala index 46983e13..42cabc94 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/IncorrectlyNamedExceptionsTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/IncorrectlyNamedExceptionsTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.exception -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class IncorrectlyNamedExceptionsTest extends InspectionTest { - override val inspections = Seq(new IncorrectlyNamedExceptions) + override val inspections = Seq[Inspection](new IncorrectlyNamedExceptions) "incorrectly named exceptions" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/SwallowedExceptionTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/SwallowedExceptionTest.scala index 2d057816..38908cc4 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/SwallowedExceptionTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/SwallowedExceptionTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.exception -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class SwallowedExceptionTest extends InspectionTest { - override val inspections = Seq(new SwallowedException) + override val inspections = Seq[Inspection](new SwallowedException) "SwallowedException" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/UnreachableCatchTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/UnreachableCatchTest.scala index 63a08d6b..977c035f 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/exception/UnreachableCatchTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/exception/UnreachableCatchTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.exception -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class UnreachableCatchTest extends InspectionTest { - override val inspections = Seq(new UnreachableCatch) + override val inspections = Seq[Inspection](new UnreachableCatch) "unreachable catch" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/imports/DuplicateImportTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/imports/DuplicateImportTest.scala index 86094e80..72b39de2 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/imports/DuplicateImportTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/imports/DuplicateImportTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.imports -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class DuplicateImportTest extends InspectionTest { - override val inspections = Seq(new DuplicateImport) + override val inspections = Seq[Inspection](new DuplicateImport) "DuplicatedImport" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/imports/WildcardImportTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/imports/WildcardImportTest.scala index 6178bd59..2405f6bf 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/imports/WildcardImportTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/imports/WildcardImportTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.imports -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class WildcardImportTest extends InspectionTest { - override val inspections = Seq(new WildcardImport) + override val inspections = Seq[Inspection](new WildcardImport) "WildcardImport" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/inferrence/BoundedByFinalTypeTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/inferrence/BoundedByFinalTypeTest.scala index 172b9acb..b5ef9862 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/inferrence/BoundedByFinalTypeTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/inferrence/BoundedByFinalTypeTest.scala @@ -1,12 +1,12 @@ package com.sksamuel.scapegoat.inspections.inferrence -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.inference.BoundedByFinalType +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class BoundedByFinalTypeTest extends InspectionTest { - override val inspections = Seq(new BoundedByFinalType) + override val inspections: Seq[Inspection] = Seq(new BoundedByFinalType) "BoundedByFinalType" - { "should report warning" - { @@ -15,51 +15,53 @@ class BoundedByFinalTypeTest extends InspectionTest { compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } + "for method with pointless type bound" in { - val code = - """object Test { - def foo[B <: Integer] :Unit = {} - } """ + val code = """object Test { + | def foo[B <: Integer]: Unit = {} + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } } + "should not report warning" - { "for partial function" in { - val code = - """ object TestObject { - | val test: PartialFunction[Array[String], Int] = { - | case _ ⇒ -1 - | } - | } - """.stripMargin + val code = """object TestObject { + | val test: PartialFunction[Array[String], Int] = { + | case _ ⇒ -1 + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for applied type" in { - val code = - """ object TestObject { - | val a = List[String]("sam") - | } - """.stripMargin + val code = """object TestObject { + | val a = List[String]("sam") + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for class with non final type bound" in { val code = """class Test[A <: Exception]""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for class with any type bound" in { val code = """class Test[A <: Any]""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for class with no type bound" in { val code = """class Test""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for method with non final type bound" in { val code = """object Test { | def foo[B <: Exception] = {} @@ -67,31 +69,35 @@ class BoundedByFinalTypeTest extends InspectionTest { compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for method with any type bound" in { val code = """object Test { | def foo[B <: Any] = {} - |} """.stripMargin + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for method with no type bound" in { val code = """object Test { | def foo = {} - |} """.stripMargin + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for type alias" in { val code = """class A { - type Texty = String - }""" + | type Texty = String + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for type constructor" in { val code = """class A { - type ListBuffer[A] = scala.collection.mutable.ListBuffer[A] - }""" + | type ListBuffer[A] = scala.collection.mutable.ListBuffer[A] + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/inferrence/PointlessTypeBoundsTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/inferrence/PointlessTypeBoundsTest.scala index e64769fc..ef7b2363 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/inferrence/PointlessTypeBoundsTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/inferrence/PointlessTypeBoundsTest.scala @@ -1,174 +1,159 @@ package com.sksamuel.scapegoat.inspections.inferrence -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.inference.PointlessTypeBounds +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class PointlessTypeBoundsTest extends InspectionTest { - override val inspections = Seq(new PointlessTypeBounds) + override val inspections: Seq[Inspection] = Seq(new PointlessTypeBounds) "PointlessTypeBounds" - { "should report warning" - { "for class with Nothing lower bound" in { - - val code = - """class Test[A >: Nothing]""".stripMargin + val code = """class Test[A >: Nothing]""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } - "for class with Any upper bound" in { - val code = - """class Test[A <: Any]""".stripMargin + "for class with Any upper bound" in { + val code = """class Test[A <: Any]""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } - "for method with Any upper bound" in { - val code = - """object Test { - | def foo[A <: Any] = {} - |} """.stripMargin + "for method with Any upper bound" in { + val code = """object Test { + | def foo[A <: Any] = {} + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } - "for method with Nothing lower bound" in { - val code = - """object Test { - | def foo[A >: Nothing] = {} - |} """.stripMargin + "for method with Nothing lower bound" in { + val code = """object Test { + | def foo[A >: Nothing] = {} + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } - "for implicit class with Nothing lower bound" in { - val code = - """class Test { - | implicit class Monster[T >: Nothing](t:T) { - | def bite : T = t - | } - | "bfg".bite - |} """.stripMargin + "for implicit class with Nothing lower bound" in { + val code = """class Test { + | implicit class Monster[T >: Nothing](t: T) { + | def bite: T = t + | } + | "bfg".bite + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } - "for implicit class with Any upper bound" in { - val code = - """class Test { - | implicit class Monster[T <: Any](t:T) { - | def bite : T = t - | } - | "bfg".bite - |} """.stripMargin + "for implicit class with Any upper bound" in { + val code = """class Test { + | implicit class Monster[T <: Any](t: T) { + | def bite: T = t + | } + | "bfg".bite + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } } + "should not report warning" - { "for class with upper bound only" in { - - val code = - """class Test[A <: Exception]""".stripMargin + val code = """class Test[A <: Exception]""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "for class with no type bound" in { - val code = - """class Test""".stripMargin + "for class with no type bound" in { + val code = """class Test""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "for class with multiple type params" in { - val code = - """class Test[A,B]""".stripMargin + "for class with multiple type params" in { + val code = """class Test[A, B]""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "for class with multiple type params and single bounds" in { - val code = - """trait Foo - |class Test[A,B <: Foo]""".stripMargin + "for class with multiple type params and single bounds" in { + val code = """trait Foo + |class Test[A, B <: Foo]""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "for class with multiple type params and multiple bounds" in { - val code = - """package com.sammy - |trait Foo - |trait Boo - |class Test[A >: Boo,B <: Foo]""".stripMargin + "for class with multiple type params and multiple bounds" in { + val code = """package com.sammy + |trait Foo + |trait Boo + |class Test[A >: Boo, B <: Foo]""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "for method with declared lower bound" in { - val code = - """object Test { - | def foo[A >: String] = {} - |} """.stripMargin + "for method with declared lower bound" in { + val code = """object Test { + | def foo[A >: String] = {} + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "for method with upper bound only" in { - val code = - """object Test { - | def foo[B <: Thread] = {} - |} """.stripMargin + "for method with upper bound only" in { + val code = """object Test { + | def foo[B <: Thread] = {} + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "for method with no type bound" in { - val code = - """object Test { - | def foo = {} - |} """.stripMargin + "for method with no type bound" in { + val code = """object Test { + | def foo = {} + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "for implicit class with no type bound" in { - val code = - """class Test { - | implicit class Monster[T](t:T) { - | def bite : T = t - | } - | "bfg".bite - |} """.stripMargin + "for implicit class with no type bound" in { + val code = """class Test { + | implicit class Monster[T](t: T) { + | def bite: T = t + | } + | "bfg".bite + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for higher kinded type bound" in { - val code = - """package com.sam - import scala.language.higherKinds - class A { def f[CC[X] <: Traversable[X], A](x: CC[A]) = {} }""" + val code = """package com.sam + |import scala.language.higherKinds + |class A { def f[CC[X] <: Traversable[X], A](x: CC[A]) = {} }""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for bound starting with Any" in { compileCodeSnippet("class Test[T <: AnyRef, S]") compileCodeSnippet("class Test[T<: AnyRef, S]") diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/inferrence/ProductWithSerializableInferredTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/inferrence/ProductWithSerializableInferredTest.scala index 6cc00256..558337c0 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/inferrence/ProductWithSerializableInferredTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/inferrence/ProductWithSerializableInferredTest.scala @@ -1,24 +1,22 @@ package com.sksamuel.scapegoat.inspections.inferrence -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.inference.ProductWithSerializableInferred +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ProductWithSerializableInferredTest extends InspectionTest { - override val inspections = Seq(new ProductWithSerializableInferred) + override val inspections: Seq[Inspection] = Seq(new ProductWithSerializableInferred) "when Product with Serializable is inferred" - { "should report warning" in { - - val code = - """class Test { - |case class A() - |case class B() - |val list1 = List(A(), B()) // trigger warning - |val list2 = List(A()) // fine - |val list3 = List(A()) :+ A() // fine - |} """.stripMargin + val code = """class Test { + |case class A() + |case class B() + |val list1 = List(A(), B()) // trigger warning + |val list2 = List(A()) // fine + |val list3 = List(A()) :+ A() // fine + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/matching/RepeatedCaseBodyTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/matching/RepeatedCaseBodyTest.scala index 98e8b30a..7fe3d722 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/matching/RepeatedCaseBodyTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/matching/RepeatedCaseBodyTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.matching -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class RepeatedCaseBodyTest extends InspectionTest { - override val inspections = Seq(new RepeatedCaseBody) + override val inspections = Seq[Inspection](new RepeatedCaseBody) "repeated case bodies" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/matching/SuspiciousMatchOnClassObjectTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/matching/SuspiciousMatchOnClassObjectTest.scala index 993d7cbf..497777fc 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/matching/SuspiciousMatchOnClassObjectTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/matching/SuspiciousMatchOnClassObjectTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections.matching -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class SuspiciousMatchOnClassObjectTest extends InspectionTest { - override val inspections = Seq(new SuspiciousMatchOnClassObject) + override val inspections = Seq[Inspection](new SuspiciousMatchOnClassObject) "SuspiciousMatchOnClassObject" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalDoubleConstructorTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalDoubleConstructorTest.scala index 06146fb0..587f67e1 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalDoubleConstructorTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalDoubleConstructorTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.math -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class BigDecimalDoubleConstructorTest extends InspectionTest { - override val inspections = Seq(new BigDecimalDoubleConstructor) + override val inspections = Seq[Inspection](new BigDecimalDoubleConstructor) "big decimal double constructor" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalScaleWithoutRoundingModeTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalScaleWithoutRoundingModeTest.scala index 5a6b4ef8..816ff070 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalScaleWithoutRoundingModeTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/math/BigDecimalScaleWithoutRoundingModeTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections.math -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class BigDecimalScaleWithoutRoundingModeTest extends InspectionTest { - override val inspections = Seq(new BigDecimalScaleWithoutRoundingMode) + override val inspections = Seq[Inspection](new BigDecimalScaleWithoutRoundingMode) "BigDecimalScaleWithoutRoundingMode" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/math/BrokenOddnessTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/math/BrokenOddnessTest.scala index 2a98cde0..6fd4e786 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/math/BrokenOddnessTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/math/BrokenOddnessTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.math -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class BrokenOddnessTest extends InspectionTest { - override val inspections = Seq(new BrokenOddness) + override val inspections = Seq[Inspection](new BrokenOddness) "broken odd use" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/math/DivideByOneTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/math/DivideByOneTest.scala index a01de8ff..d9acacaa 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/math/DivideByOneTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/math/DivideByOneTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections.math -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class DivideByOneTest extends InspectionTest { - override val inspections = Seq(new DivideByOne) + override val inspections = Seq[Inspection](new DivideByOne) "divide by one" - { "for int" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/math/ModOneTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/math/ModOneTest.scala index d786078b..df3f1cb0 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/math/ModOneTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/math/ModOneTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.math -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ModOneTest extends InspectionTest { - override val inspections = Seq(new ModOne) + override val inspections = Seq[Inspection](new ModOne) "mod one use" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/math/NanComparisonTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/math/NanComparisonTest.scala index c32bd832..4c64c0d8 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/math/NanComparisonTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/math/NanComparisonTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections.math -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class NanComparisonTest extends InspectionTest { - override val inspections = Seq(new NanComparison) + override val inspections = Seq[Inspection](new NanComparison) "nan comparison" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseCbrtTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseCbrtTest.scala index df23c1a7..f8937fbd 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseCbrtTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseCbrtTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.math -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Matic Potočnik */ class UseCbrtTest extends InspectionTest { - override val inspections = Seq(new UseCbrt) + override val inspections = Seq[Inspection](new UseCbrt) "using pow instead of cbrt" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseExpM1Test.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseExpM1Test.scala index 201094d6..1752151e 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseExpM1Test.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseExpM1Test.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.math -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Matic Potočnik */ class UseExpM1Test extends InspectionTest { - override val inspections = Seq(new UseExpM1) + override val inspections = Seq[Inspection](new UseExpM1) "using exp(x) - 1 instead of expm1(x)" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseLog10Test.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseLog10Test.scala index b9902687..b055f7ac 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseLog10Test.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseLog10Test.scala @@ -1,10 +1,10 @@ package com.sksamuel.scapegoat.inspections.math -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class UseLog10Test extends InspectionTest { - override val inspections = Seq(new UseLog10) + override val inspections = Seq[Inspection](new UseLog10) "using log(x)/log(10) instead of log10(x)" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseLog1PTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseLog1PTest.scala index e7e48522..3fcf6f14 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseLog1PTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseLog1PTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections.math -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class UseLog1PTest extends InspectionTest { - override val inspections = Seq(new UseLog1P) + override val inspections = Seq[Inspection](new UseLog1P) "using log(x + 1) instead of log1p(x)" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseSqrtTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseSqrtTest.scala index 305fcbe1..4d588357 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseSqrtTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/math/UseSqrtTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections.math -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class UseSqrtTest extends InspectionTest { - override val inspections = Seq(new UseSqrt) + override val inspections = Seq[Inspection](new UseSqrt) "using pow instead of sqrt" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/math/ZeroNumeratorTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/math/ZeroNumeratorTest.scala index c6bbc5e3..e2071aec 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/math/ZeroNumeratorTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/math/ZeroNumeratorTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections.math -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class ZeroNumeratorTest extends InspectionTest { - override val inspections = Seq(new ZeroNumerator) + override val inspections = Seq[Inspection](new ZeroNumerator) "zero numerator" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/names/ClassNamesTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/names/ClassNamesTest.scala index abc8b9c4..a9499ee2 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/names/ClassNamesTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/names/ClassNamesTest.scala @@ -1,57 +1,50 @@ package com.sksamuel.scapegoat.inspections.names -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.naming.ClassNames +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ClassNamesTest extends InspectionTest { - override val inspections = Seq(new ClassNames) + override val inspections: Seq[Inspection] = Seq(new ClassNames) "ClassNames" - { "should report warning" - { "for classes beginning with lowercase" in { - val code = - """class aClass - |case class bClass() - """.stripMargin + val code = """class aClass + |case class bClass()""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 2 } + "for classes containing underscore" in { - val code = - """class My_class - |case class Your_class() - """.stripMargin + val code = """class My_class + |case class Your_class()""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 2 } } + "should not report warning" - { "for anon classes" in { - val code = - """ - |class Test { - | import java.util.{Observer, Observable} - | val observable = new Observable {} - | observable.addObserver(new Observer { - | override def update(o: Observable, arg: scala.Any): Unit = () - | }) - |} - """.stripMargin + val code = """class Test { + | import java.util.{Observer, Observable} + | val observable = new Observable {} + | observable.addObserver(new Observer { + | override def update(o: Observable, arg: scala.Any): Unit = () + | }) + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for implicit classes" in { - val code = - """ - |class Test { - | implicit class ClintEaswood(name:String) { - | def magnum = "boom" - | } - | "sammy".magnum - |} - """.stripMargin + val code = """class Test { + | implicit class ClintEaswood(name:String) { + | def magnum = "boom" + | } + | "sammy".magnum + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/names/MethodNamesTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/names/MethodNamesTest.scala index 08ba4658..808982ad 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/names/MethodNamesTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/names/MethodNamesTest.scala @@ -1,33 +1,31 @@ package com.sksamuel.scapegoat.inspections.names -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.naming.MethodNames +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class MethodNamesTest extends InspectionTest { - override val inspections = Seq(new MethodNames) + override val inspections: Seq[Inspection] = Seq(new MethodNames) "MethodNames" - { "should report warning" - { "for methods beginning with underscore" in { - val code = - """object A { - def _a = 1 - } - """.stripMargin + val code = """object A { + | def _a = 1 + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } + "for methods beginning with capital letter" in { - val code = - """object A { - def B = true - } - """.stripMargin + val code = """object A { + | def B = true + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } + "for something similar to unary operators, yet different (#271)" in { val code = """case class Amount(amount: BigDecimal) { | def unary_A = Amount(-amount) @@ -39,93 +37,87 @@ class MethodNamesTest extends InspectionTest { "should not report warning" - { "for camel case methods" in { - val code = - """object A { - def camelCase = false - } - """.stripMargin + val code = """object A { + | def camelCase = false + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for getter methods" in { - val code = - """object A { - val Name = "sammy" - } - """.stripMargin + val code = """object A { + | val Name = "sammy" + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for parameters" in { - val code = - """object A { - def foo(Name:String) = {} - } - """.stripMargin + val code = """object A { + | def foo(Name: String) = {} + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for setter methods" in { - val code = - """object A { - var Name = "sammy" - } - """.stripMargin + val code = """object A { + | var Name = "sammy" + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for nested vals" in { - val code = - """object A { - def foo = { - val AAAA = 1 - println(AAAA) - } - } - """.stripMargin + val code = """object A { + | def foo = { + | val AAAA = 1 + | println(AAAA) + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for nested traits" in { - val code = """ - object Test { - trait Inner { - def valueStr: String = "test" - } - } """.stripMargin + val code = """object Test { + | trait Inner { + | def valueStr: String = "test" + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for nested classes" in { - val code = """ - object Test { - class Inner { - def valueStr: String = "test" - } - } """.stripMargin + val code = """object Test { + | class Inner { + | def valueStr: String = "test" + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for nested objects" in { - val code = """ - object Test { - object Inner { - def valueStr: String = "test" - } - } """.stripMargin + val code = """object Test { + | object Inner { + | def valueStr: String = "test" + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for setter methods (2)" in { - val code = """ - object Test { - def hallo: String = "" - def hallo_=(x: String): Unit = {} - } - """ + val code = """object Test { + | def hallo: String = "" + | def hallo_=(x: String): Unit = {} + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings should have size 0 } + "for unary operators definition (#271)" in { val code = """case class Amount(amount: BigDecimal) { | def unary_- = Amount(-amount) diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/names/ObjectNamesTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/names/ObjectNamesTest.scala index cccadc9b..c6dc11e3 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/names/ObjectNamesTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/names/ObjectNamesTest.scala @@ -1,20 +1,18 @@ package com.sksamuel.scapegoat.inspections.names -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.naming.ObjectNames +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ObjectNamesTest extends InspectionTest { - override val inspections = Seq(new ObjectNames) + override val inspections: Seq[Inspection] = Seq(new ObjectNames) "ObjectNames" - { "should report warning" - { "for objects containing underscore" in { - val code = - """object My_class - |case object Your_class - """.stripMargin + val code = """object My_class + |case object Your_class""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 2 } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/nulls/NullAssignmentTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/nulls/NullAssignmentTest.scala index 0c15b159..d42cecbe 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/nulls/NullAssignmentTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/nulls/NullAssignmentTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.nulls -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class NullAssignmentTest extends InspectionTest { - override val inspections = Seq(new NullAssignment) + override val inspections = Seq[Inspection](new NullAssignment) "NullAssignment" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/nulls/NullParameterTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/nulls/NullParameterTest.scala index cdca2ab2..0d101ec5 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/nulls/NullParameterTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/nulls/NullParameterTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.nulls -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class NullParameterTest extends InspectionTest { - override val inspections = Seq(new NullParameter) + override val inspections = Seq[Inspection](new NullParameter) "NullParameter" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/option/ImpossibleOptionSizeConditionTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/option/ImpossibleOptionSizeConditionTest.scala index a921f03c..89110d88 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/option/ImpossibleOptionSizeConditionTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/option/ImpossibleOptionSizeConditionTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.option -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ImpossibleOptionSizeConditionTest extends InspectionTest { - override val inspections = Seq(new ImpossibleOptionSizeCondition) + override val inspections = Seq[Inspection](new ImpossibleOptionSizeCondition) "options.size > x where x is > 1" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/option/OptionGetTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/option/OptionGetTest.scala index 839a7d1b..aae0e242 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/option/OptionGetTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/option/OptionGetTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.option -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class OptionGetTest extends InspectionTest { - override val inspections = Seq(new OptionGet) + override val inspections = Seq[Inspection](new OptionGet) "option.get use" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/option/OptionSizeTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/option/OptionSizeTest.scala index de446aad..4e0b7848 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/option/OptionSizeTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/option/OptionSizeTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.option -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class OptionSizeTest extends InspectionTest { - override val inspections = Seq(new OptionSize) + override val inspections = Seq[Inspection](new OptionSize) "option.size use" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/string/ArraysInFormatTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/string/ArraysInFormatTest.scala index 55dcefac..0e2955d4 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/string/ArraysInFormatTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/string/ArraysInFormatTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.string -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ArraysInFormatTest extends InspectionTest { - override val inspections = Seq(new ArraysInFormat) + override val inspections = Seq[Inspection](new ArraysInFormat) "use of array in format" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/string/ArraysToStringTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/string/ArraysToStringTest.scala index 8d755cdd..95f552a0 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/string/ArraysToStringTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/string/ArraysToStringTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.string -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ArraysToStringTest extends InspectionTest { - override val inspections = Seq(new ArraysToString) + override val inspections = Seq[Inspection](new ArraysToString) "ArraysToString" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/string/EmptyInterpolatedStringTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/string/EmptyInterpolatedStringTest.scala index b161ee7b..d0c08ab1 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/string/EmptyInterpolatedStringTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/string/EmptyInterpolatedStringTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.string -import com.sksamuel.scapegoat.{isScala213, InspectionTest} +import com.sksamuel.scapegoat.{isScala213, Inspection, InspectionTest} /** @author Stephen Samuel */ class EmptyInterpolatedStringTest extends InspectionTest { - override val inspections = Seq(new EmptyInterpolatedString) + override val inspections = Seq[Inspection](new EmptyInterpolatedString) "EmptyInterpolatedString" - { "should report warning (for Scala < 2.13)" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/string/IllegalFormatStringTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/string/IllegalFormatStringTest.scala index 4330b0aa..12840a31 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/string/IllegalFormatStringTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/string/IllegalFormatStringTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.string -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class IllegalFormatStringTest extends InspectionTest { - override val inspections = Seq(new IllegalFormatString) + override val inspections = Seq[Inspection](new IllegalFormatString) "unknown conversion type" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/string/IncorrectNumberOfArgsToFormatTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/string/IncorrectNumberOfArgsToFormatTest.scala index 38e34741..530f304a 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/string/IncorrectNumberOfArgsToFormatTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/string/IncorrectNumberOfArgsToFormatTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.string -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class IncorrectNumberOfArgsToFormatTest extends InspectionTest { - override val inspections = Seq(new IncorrectNumberOfArgsToFormat) + override val inspections = Seq[Inspection](new IncorrectNumberOfArgsToFormat) "IncorrectNumberOfArgsToFormat" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/string/InvalidRegexTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/string/InvalidRegexTest.scala index 90945d49..4caaedb9 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/string/InvalidRegexTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/string/InvalidRegexTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.string -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class InvalidRegexTest extends InspectionTest { - override val inspections = Seq(new InvalidRegex) + override val inspections = Seq[Inspection](new InvalidRegex) "invalid regex" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/string/LooksLikeInterpolatedStringTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/string/LooksLikeInterpolatedStringTest.scala index ae3a10c4..06079908 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/string/LooksLikeInterpolatedStringTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/string/LooksLikeInterpolatedStringTest.scala @@ -1,9 +1,9 @@ package com.sksamuel.scapegoat.inspections.string -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class LooksLikeInterpolatedStringTest extends InspectionTest { - override val inspections = Seq(new LooksLikeInterpolatedString) + override val inspections = Seq[Inspection](new LooksLikeInterpolatedString) "LooksLikeInterpolatedString" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/string/StripMarginOnRegexTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/string/StripMarginOnRegexTest.scala index 7c540b9f..c5e7807b 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/string/StripMarginOnRegexTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/string/StripMarginOnRegexTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.string -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class StripMarginOnRegexTest extends InspectionTest { - override val inspections = Seq(new StripMarginOnRegex) + override val inspections = Seq[Inspection](new StripMarginOnRegex) "StripMarginOnRegex" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/string/SubstringZeroTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/string/SubstringZeroTest.scala index 79e49422..5f739ff9 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/string/SubstringZeroTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/string/SubstringZeroTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.string -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class SubstringZeroTest extends InspectionTest { - override val inspections = Seq(new SubstringZero) + override val inspections = Seq[Inspection](new SubstringZero) "String.substring(0)" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/string/UnsafeStringContainsTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/string/UnsafeStringContainsTest.scala index 488f29d8..dacd0ade 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/string/UnsafeStringContainsTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/string/UnsafeStringContainsTest.scala @@ -1,10 +1,10 @@ package com.sksamuel.scapegoat.inspections.string -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Zack Grannan */ class UnsafeStringContainsTest extends InspectionTest { - override val inspections = Seq(new UnsafeStringContains) + override val inspections = Seq[Inspection](new UnsafeStringContains) "unsafe string contains" - { "should report warning" in { val code = diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/style/AvoidOperatorOverloadTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/style/AvoidOperatorOverloadTest.scala index c081a5e7..1d15ae36 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/style/AvoidOperatorOverloadTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/style/AvoidOperatorOverloadTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.style -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class AvoidOperatorOverloadTest extends InspectionTest { - override val inspections = Seq(new AvoidOperatorOverload) + override val inspections = Seq[Inspection](new AvoidOperatorOverload) "AvoidOperatorOverload" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/style/ParameterlessMethodReturnsUnitTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/style/ParameterlessMethodReturnsUnitTest.scala index 3e727f78..3a377b3e 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/style/ParameterlessMethodReturnsUnitTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/style/ParameterlessMethodReturnsUnitTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.style -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class ParameterlessMethodReturnsUnitTest extends InspectionTest { - override val inspections = Seq(new ParameterlessMethodReturnsUnit) + override val inspections = Seq[Inspection](new ParameterlessMethodReturnsUnit) "ParameterlessMethodReturnsUnit" - { "should report warning" - { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/style/SimplifyBooleanExpressionTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/style/SimplifyBooleanExpressionTest.scala index 037ee27f..c586f6c9 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/style/SimplifyBooleanExpressionTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/style/SimplifyBooleanExpressionTest.scala @@ -1,11 +1,11 @@ package com.sksamuel.scapegoat.inspections.style -import com.sksamuel.scapegoat.InspectionTest +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class SimplifyBooleanExpressionTest extends InspectionTest { - override val inspections = Seq(new SimplifyBooleanExpression) + override val inspections = Seq[Inspection](new SimplifyBooleanExpression) "incorrectly named exceptions" - { "should report warning" in { diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/NoOpOverrideTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/NoOpOverrideTest.scala index e652991e..7344b0ae 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/NoOpOverrideTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/NoOpOverrideTest.scala @@ -1,60 +1,51 @@ package com.sksamuel.scapegoat.inspections.unnecessary -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.NoOpOverride +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class NoOpOverrideTest extends InspectionTest { - override val inspections = Seq(new NoOpOverride) + override val inspections: Seq[Inspection] = Seq(new NoOpOverride) "UnnecessaryOverride" - { "should report warning" - { "when overriding method to just call super" in { - - val code = - """class Test { - | override def finalize() { - | super.finalize() - | } - |} - """.stripMargin + val code = """class Test { + | override def finalize() { + | super.finalize() + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } } + "should not report warning" - { "when overriding method with super call and other code" in { - - val code = - """class Test { - | override def finalize() { - | super.finalize() - | println("sam") - | } - |} - """.stripMargin + val code = """class Test { + | override def finalize() { + | super.finalize() + | println("sam") + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "when overriding method calls super with different args" in { - val code = - """ - |class A { - | def method(what: String) = "A " + what - |} - |class B extends A { - | override def method(what: String) = super.method("something else than " + what) - |} - """.stripMargin + "when overriding method calls super with different args" in { + val code = """class A { + | def method(what: String) = "A " + what + |} + |class B extends A { + | override def method(what: String) = super.method("something else than " + what) + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - } } } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/StoreBeforeReturnTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/StoreBeforeReturnTest.scala index 081c23a0..72807324 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/StoreBeforeReturnTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/StoreBeforeReturnTest.scala @@ -1,40 +1,34 @@ package com.sksamuel.scapegoat.inspections.unnecessary -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.unneccesary.StoreBeforeReturn +import com.sksamuel.scapegoat.{Inspection, InspectionTest} class StoreBeforeReturnTest extends InspectionTest { - override val inspections = Seq(new StoreBeforeReturn) + override val inspections: Seq[Inspection] = Seq(new StoreBeforeReturn) "store value before explicit return" - { "should report warning" in { - val code = - """ - |object Test { - | def hello(): String = { - | var s = "sammy" - | return s - | } - |} - |""".stripMargin + val code = """object Test { + | def hello(): String = { + | var s = "sammy" + | return s + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } "should report warning in a nested function" in { - val code = - """ - |object Test { - | def foo(): Int = { - | def bar(): Int = { - | val x = 1 - | return x - | } - | return bar() - | } - |} - |""".stripMargin + val code = """object Test { + | def foo(): Int = { + | def bar(): Int = { + | val x = 1 + | return x + | } + | return bar() + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } @@ -42,49 +36,41 @@ class StoreBeforeReturnTest extends InspectionTest { "store value before implicit return" - { "should report warning" in { - val code = - """ - |object Test { - | def hello(): String = { - | var s = "sammy" - | s - | } - |} - |""".stripMargin + val code = """object Test { + | def hello(): String = { + | var s = "sammy" + | s + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } "should report warning in a nested function" in { - val code = - """ - |object Test { - | def foo(): Int = { - | def bar(): Int = { - | val x = 1 - | x - | } - | bar() - | } - |} - |""".stripMargin + val code = """object Test { + | def foo(): Int = { + | def bar(): Int = { + | val x = 1 + | x + | } + | bar() + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 } } + "store value and modify before return" - { "should not report warning" in { - val code = - """ - |object Test { - | def hello(): Int = { - | var x = 1 - | x = x + 1 - | return x - | } - |} - |""".stripMargin + val code = """object Test { + | def hello(): Int = { + | var x = 1 + | x = x + 1 + | return x + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } @@ -92,19 +78,16 @@ class StoreBeforeReturnTest extends InspectionTest { "store value and return for mutually-recusive functions" - { "should report a warning, and terminate" in { - val code = - """ - |object Test { - | def foo(): Int = { - | var x = bar() - | return x - | } - | def bar(): Int = { - | val x = foo() - | return x - | } - |} - |""".stripMargin + val code = """object Test { + | def foo(): Int = { + | var x = bar() + | return x + | } + | def bar(): Int = { + | val x = foo() + | return x + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 2 } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnnecessaryConversionTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnnecessaryConversionTest.scala index 07ba47a3..c8180c13 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnnecessaryConversionTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnnecessaryConversionTest.scala @@ -1,164 +1,167 @@ package com.sksamuel.scapegoat.inspections.unnecessary -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.unneccesary.UnnecessaryConversion +import com.sksamuel.scapegoat.{isScala21312, Inspection, InspectionTest} /** @author Stephen Samuel */ class UnnecessaryConversionTest extends InspectionTest { - override val inspections = Seq(new UnnecessaryConversion) + override val inspections: Seq[Inspection] = Seq(new UnnecessaryConversion) "Unnecessary conversion" - { "should report warning" - { "when invoking toString on a String" in { - - val code = - """object Test { - val i = "sam" - val j = i.toString - }""".stripMargin + val code = """object Test { + | val i = "sam" + | val j = i.toString + |}""".stripMargin compileCodeSnippet(code) - compiler.scapegoat.feedback.warnings.size shouldBe 1 + val expectedWarnings = if (isScala21312) 0 else 1 + compiler.scapegoat.feedback.warnings.size shouldBe expectedWarnings } + "when invoking toInt on an int" in { - val code = - """object Test { - | val i = 4 - | val j = i.toInt - |}""".stripMargin + val code = """object Test { + | val i = 4 + | val j = i.toInt + |}""".stripMargin compileCodeSnippet(code) - compiler.scapegoat.feedback.warnings.size shouldBe 1 + val expectedWarnings = if (isScala21312) 0 else 1 + compiler.scapegoat.feedback.warnings.size shouldBe expectedWarnings } + "when invoking toInt on an integer literal" in { - val code = - """object Example extends App { - | val a = 3.toInt // NullPointerException here (v1.3.6). - | val b = (10 / 5).toInt // NullPointerException here (v1.3.6). - |}""".stripMargin + val code = """object Example extends App { + | val a = 3.toInt // NullPointerException here (v1.3.6). + | val b = (10 / 5).toInt // NullPointerException here (v1.3.6). + |}""".stripMargin compileCodeSnippet(code) - compiler.scapegoat.feedback.warnings.size shouldBe 2 + val expectedWarnings = if (isScala21312) 0 else 2 + compiler.scapegoat.feedback.warnings.size shouldBe expectedWarnings } + "when invoking toLong on a long" in { - val code = - """object Test { - | val i: Long = 436 - | val j = i.toLong - |}""".stripMargin + val code = """object Test { + | val i: Long = 436 + | val j = i.toLong + |}""".stripMargin compileCodeSnippet(code) - compiler.scapegoat.feedback.warnings.size shouldBe 1 + val expectedWarnings = if (isScala21312) 0 else 1 + compiler.scapegoat.feedback.warnings.size shouldBe expectedWarnings } + "when invoking toLong on a Long literal" in { - val code = - """object Example extends App { - | val a = 123456789012L - | val b = a.toLong - |}""".stripMargin + val code = """object Example extends App { + | val a = 123456789012L + | val b = a.toLong + |}""".stripMargin compileCodeSnippet(code) - compiler.scapegoat.feedback.warnings.size shouldBe 1 + val expectedWarnings = if (isScala21312) 0 else 1 + compiler.scapegoat.feedback.warnings.size shouldBe expectedWarnings } + "when invoking toList on a list" in { - val code = - """object Test { - | val list = List(1,2,3) - | val something = list.toList - |}""".stripMargin + val code = """object Test { + | val list = List(1, 2, 3) + | val something = list.toList + |}""".stripMargin compileCodeSnippet(code) - compiler.scapegoat.feedback.warnings.size shouldBe 1 + val expectedWarnings = if (isScala21312) 0 else 1 + compiler.scapegoat.feedback.warnings.size shouldBe expectedWarnings } + "when invoking toSet on a set" in { - val code = - """object Test { - | val set = Set(4,3,6) - | val something = set.toSet - |}""".stripMargin + val code = """object Test { + | val set = Set(4, 3, 6) + | val something = set.toSet + |}""".stripMargin compileCodeSnippet(code) - compiler.scapegoat.feedback.warnings.size shouldBe 1 + val expectedWarnings = if (isScala21312) 0 else 1 + compiler.scapegoat.feedback.warnings.size shouldBe expectedWarnings } + "when invoking toSeq on a seq" in { - val code = - """object Test { - | val seq = Seq(4,3,6) - | val something = seq.toSeq - |}""".stripMargin + val code = """object Test { + | val seq = Seq(4, 3, 6) + | val something = seq.toSeq + |}""".stripMargin compileCodeSnippet(code) - compiler.scapegoat.feedback.warnings.size shouldBe 1 + val expectedWarnings = if (isScala21312) 0 else 1 + compiler.scapegoat.feedback.warnings.size shouldBe expectedWarnings } } "should not report warning" - { "when invoking toString on a BigDecimal" in { - val code = - """object Test { - val s = BigDecimal(5) - val t = s.toString - }""".stripMargin + val code = """object Test { + | val s = BigDecimal(5) + | val t = s.toString + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "when invoking toInt on a String" in { - val code = - """object Test { - | val s = "5" - | val t = s.toInt - |}""".stripMargin + val code = """object Test { + | val s = "5" + | val t = s.toInt + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } "when invoking toInt on an Integer" in { - val code = - """object Test { - | def test(i: java.lang.Integer) = { - | val t = i.toInt - | } - |}""".stripMargin + val code = """object Test { + | def test(i: java.lang.Integer) = { + | val t = i.toInt + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "when invoking toLong on a int" in { - val code = - """object Test { - | val i: Int = 436 - | val j = i.toLong - |}""".stripMargin + val code = """object Test { + | val i: Int = 436 + | val j = i.toLong + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "when invoking toSeq on a set" in { - val code = - """object Test { - | val set = Set(4,3,6) - | val something = set.toSeq - |}""".stripMargin + val code = """object Test { + | val set = Set(4, 3, 6) + | val something = set.toSeq + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "when invoking toSet on a list or seq" in { - val code = - """object Test { - | val list = List(4,3,6) - | val something = list.toSet - | val seq = Seq(1,3,6) - | val thing = seq.toSet - |}""".stripMargin + val code = """object Test { + | val list = List(4, 3, 6) + | val something = list.toSet + | val seq = Seq(1, 3, 6) + | val thing = seq.toSet + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - } } } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnnecessaryIfTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnnecessaryIfTest.scala index aa185fb2..cd77c03b 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnnecessaryIfTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnnecessaryIfTest.scala @@ -1,32 +1,30 @@ package com.sksamuel.scapegoat.inspections.unnecessary -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.unneccesary.UnnecessaryIf +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class UnnecessaryIfTest extends InspectionTest { - override val inspections = Seq(new UnnecessaryIf) + override val inspections: Seq[Inspection] = Seq(new UnnecessaryIf) "unncessary if" - { "should report warning" in { - val code = """object Test { - val a = "sam" - if (a == "sam") true else false - if (a == "sam") false else true - } """.stripMargin + | val a = "sam" + | if (a == "sam") true else false + | if (a == "sam") false else true + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 2 } + "should not report warning" - { "in empty case classes" in { - val code = - """object Test { - case class DebuggerShutdownEvent() - } - """.stripMargin + val code = """object Test { + | case class DebuggerShutdownEvent() + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnnecessaryReturnUseTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnnecessaryReturnUseTest.scala index bb944100..9db6d09a 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnnecessaryReturnUseTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnnecessaryReturnUseTest.scala @@ -1,30 +1,28 @@ package com.sksamuel.scapegoat.inspections.unnecessary -import com.sksamuel.scapegoat.InspectionTest import com.sksamuel.scapegoat.inspections.unneccesary.UnnecessaryReturnUse +import com.sksamuel.scapegoat.{Inspection, InspectionTest} /** @author Stephen Samuel */ class UnnecessaryReturnUseTest extends InspectionTest { - override val inspections = Seq(new UnnecessaryReturnUse) + override val inspections: Seq[Inspection] = Seq[Inspection](new UnnecessaryReturnUse) "return keyword use" - { "should report warning" in { - val code = """class Test { - def hello : String = { - val s = "sammy" - return s - } - - def earlyOutReturn: Unit = { - if(Math.random() > 0.5) { - println("early out return") - return () // Acceptable - } - println("not reachable") - } - } """.stripMargin + | def hello : String = { + | val s = "sammy" + | return s + | } + | def earlyOutReturn: Unit = { + | if(Math.random() > 0.5) { + | println("early out return") + | return () // Acceptable + | } + | println("not reachable") + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 diff --git a/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnusedMethodParameterTest.scala b/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnusedMethodParameterTest.scala index 59c2fb46..2f2ca9cd 100644 --- a/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnusedMethodParameterTest.scala +++ b/src/test/scala/com/sksamuel/scapegoat/inspections/unnecessary/UnusedMethodParameterTest.scala @@ -1,116 +1,122 @@ package com.sksamuel.scapegoat.inspections.unnecessary import com.sksamuel.scapegoat.inspections.unneccesary.UnusedMethodParameter -import com.sksamuel.scapegoat.{InspectionTest, Warning} +import com.sksamuel.scapegoat.{Inspection, InspectionTest, Warning} +import org.scalatest.Assertion /** @author Stephen Samuel */ class UnusedMethodParameterTest extends InspectionTest { - override val inspections = Seq(new UnusedMethodParameter) + override val inspections: Seq[Inspection] = Seq(new UnusedMethodParameter) "UnusedMethodParameter" - { "should report warning" - { "for unused parameters in concrete methods" in { val code = """class Test { - val initstuff = "sammy" - def foo(a:String, b:Int, c:Int) { - println(b) - foo(a,b,b) - } - } """.stripMargin + | val initstuff = "sammy" + | def foo(a: String, b: Int, c: Int) { + | println(b) + | foo(a, b, b) + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 1 compiler.scapegoat.feedback.warns.size shouldBe 1 } } - "should ignore @SuppressWarnings" in { + "should ignore @SuppressWarnings" in { val code = """class Test { - @SuppressWarnings(Array("all")) - def foo(a:String, b:Int, c:Int) { - println(b) - foo(a,b,b) - } - } """.stripMargin + | @SuppressWarnings(Array("all")) + | def foo(a: String, b: Int, c: Int) { + | println(b) + | foo(a, b, b) + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "should not report warning" - { "for main method" in { val code = """class Test { - def main(args: Array[String]) : Unit = {} - } """.stripMargin + | def main(args: Array[String]): Unit = {} + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "for abstract methods" in { + "for abstract methods" in { val code = """abstract class Test { - def foo(name:String) : String - } """.stripMargin + | def foo(name: String): String + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "for abstract constructor" in { + "for abstract constructor" in { val code = """abstract class EventBusMessage(messageVersion: Int)""" compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } - "for methods not returning" in { + "for methods not returning" in { val code = """class Test { - | def foo(name:String) = throw new RuntimeException + | def foo(name: String) = throw new RuntimeException |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for methods not returning when their return type is specified" in { val code = """class Test { - | def foo(name:String): String = throw new RuntimeException + | def foo(name: String): String = throw new RuntimeException |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for overridden method" in { val code = """package com.sam - trait Foo { - def foo(name:String):String - } - object Fool extends Foo { - override def foo(name:String) : String = "sam" - } """ + |trait Foo { + | def foo(name: String): String + |} + |object Fool extends Foo { + | override def foo(name: String): String = "sam" + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for overridden method without override keyword" in { val code = """package com.sam - trait Foo { - def foo(name:String):String - } - object Fool extends Foo { - def foo(name:String) : String = "sam" - } """ + |trait Foo { + | def foo(name: String): String + |} + |object Fool extends Foo { + | def foo(name: String): String = "sam" + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 } + "for implemented method" in { val code = """package com.sam - trait Foo { - def foo(name:String): String - } - case class Fool() extends Foo { - def foo(name:String): String = "sam" - } """ + |trait Foo { + | def foo(name: String): String + |} + |case class Fool() extends Foo { + | def foo(name: String): String = "sam" + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 @@ -118,22 +124,18 @@ class UnusedMethodParameterTest extends InspectionTest { "for js.native defined method" in { val code = """package scala.scalajs { - object js { - def native: Nothing = ??? - } - } - - package com.sam { - - import scalajs.js - - class Foo { - def foo(name: String): String = js.native - } - } """ + | object js { + | def native: Nothing = ??? + | } + |} + |package com.sam { + | import scalajs.js + | class Foo { + | def foo(name: String): String = js.native + | } + |}""".stripMargin compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 - } } @@ -157,8 +159,7 @@ class UnusedMethodParameterTest extends InspectionTest { | def example: String = { | s"x = $x, y = $y" | } - |} - """.stripMargin) + |}""".stripMargin) } "not warn on case class secondary params used as params" in { @@ -166,8 +167,7 @@ class UnusedMethodParameterTest extends InspectionTest { | println(s"x = $x, y = $y") | | def example: String = "irrelevant" - |} - """.stripMargin) + |}""".stripMargin) } "warn on unused non-case class primary params" in { @@ -185,8 +185,7 @@ class UnusedMethodParameterTest extends InspectionTest { | def example: String = { | s"x = $x" | } - |} - """.stripMargin) + |}""".stripMargin) } "not warn on non-case class primary params used as params" in { @@ -194,8 +193,7 @@ class UnusedMethodParameterTest extends InspectionTest { | println(s"x = $x") | | def example: String = "irrelevant" - |} - """.stripMargin) + |}""".stripMargin) } "not warn on non-case class primary params marked val" in { @@ -204,7 +202,7 @@ class UnusedMethodParameterTest extends InspectionTest { } } - private def assertNoWarnings(code: String) = { + private def assertNoWarnings(code: String): Assertion = { compileCodeSnippet(code) compiler.scapegoat.feedback.warnings.size shouldBe 0 }