From 39a5f0f4aa3de65433e1658269a3eab68ea0e03a Mon Sep 17 00:00:00 2001 From: Thomas Ploch Date: Tue, 23 May 2023 11:55:31 +0200 Subject: [PATCH] Removed silencer SBT plugin The plugin is not necessary anymore since it was back-ported to all currently supported compiler versions. It also breaks when using this library with the 3.3.1-RC1 Scala version: ``` [error] -- Error: typesafe/shared/src/main/scala/zio/config/typesafe/TypesafeConfigSource.scala:15:0 [error] undefined: new com.github.ghik.silencer.silent # -1: TermRef(TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class ghik)),object silencer),silent),) at readTasty ``` I also added a few improvements in the build itself, and fixed a few tests. --- build.sbt | 15 ++++++++---- .../zio/config/derivation/NeedsDerive.scala | 23 ------------------- .../examples/SimpleReadConfigExample.scala | 7 ++++-- .../AutoDerivationCustomKeys.scala | 3 --- project/BuildHelper.scala | 20 ++++++---------- .../scala/zio/config/refined/package.scala | 3 --- .../zio/config/refined/NumericTestTypes.scala | 13 +++++++++++ .../zio/config/refined/NumericTestTypes.scala | 12 ++++++++++ .../zio/config/refined/NumericTestTypes.scala | 12 ++++++++++ .../config/refined/NumericSupportTest.scala | 22 ++++++++---------- .../config/refined/RequiredNumericTypes.scala | 10 ++++++++ .../magnolia/CoproductSealedTraitSpec.scala | 5 ++-- .../typesafe/TypesafeConfigProvider.scala | 4 ++-- .../xml/experimental/XmlConfigProvider.scala | 2 -- .../zio/config/yaml/YamlConfigProvider.scala | 4 ++-- 15 files changed, 85 insertions(+), 70 deletions(-) delete mode 100644 derivation/shared/src/main/scala-2.11/zio/config/derivation/NeedsDerive.scala create mode 100644 refined/shared/src/test/scala-2.12/zio/config/refined/NumericTestTypes.scala create mode 100644 refined/shared/src/test/scala-2.13/zio/config/refined/NumericTestTypes.scala create mode 100644 refined/shared/src/test/scala-3/zio/config/refined/NumericTestTypes.scala create mode 100644 refined/shared/src/test/scala/zio/config/refined/RequiredNumericTypes.scala diff --git a/build.sbt b/build.sbt index d8fe16d21..935f8c189 100644 --- a/build.sbt +++ b/build.sbt @@ -1,5 +1,7 @@ import BuildHelper._ +welcomeMessage + inThisBuild( List( organization := "dev.zio", @@ -24,13 +26,12 @@ inThisBuild( addCommandAlias("fmt", "; scalafmtSbt; scalafmt; test:scalafmt") addCommandAlias("fix", "; all compile:scalafix test:scalafix; all scalafmtSbt scalafmtAll") -addCommandAlias("compileAll", "; ++2.12.16; root2-12/compile; ++2.13.8!; root2-13/compile") -addCommandAlias("testAll", "; ++2.12.16; root2-12/test; ++2.13.8!; root2-13/test") +addCommandAlias("compileAll", "; ++2.12.16; root2-12/compile; ++2.13.8!; root2-13/compile; ++3.2.2!; root3/compile;") +addCommandAlias("testAll", "; ++2.12.16; root2-12/test; ++2.13.8!; root2-13/test; ++3.2.2!; root3/test;") addCommandAlias( "testJS", ";zioConfigJS/test" ) - addCommandAlias( "testJVM212", ";zioConfigJVM/test;zioConfigTypesafeJVM/test;zioConfigDerivationJVM/test;zioConfigYamlJVM/test;examplesJVM/test;zioConfigAwsJVM/test;zioConfigZioAwsJVM/test;zioConfigXmlJVM/test" @@ -43,6 +44,10 @@ addCommandAlias( "testJVM3x", ";zioConfigJVM/test;zioConfigTypesafeJVM/test;zioConfigDerivationJVM/test;zioConfigYamlJVM/test;zioConfigMagnoliaJVM/test;zioConfigAwsJVM/test;zioConfigZioAwsJVM/test;zioConfigXmlJVM/test" ) +addCommandAlias( + "testJVM", + ";testJVM212;testJVM213;testJVM3x;" +) val awsVersion = "1.12.360" val zioAwsVersion = "5.19.33.2" @@ -373,7 +378,7 @@ lazy val zioConfigCats = crossProject(JSPlatform, JVMPlatform, NativePlatform) .settings(crossProjectSettings) .settings( libraryDependencies ++= Seq( - "org.typelevel" %% "cats-core" % "2.8.0", + "org.typelevel" %% "cats-core" % "2.9.0", "dev.zio" %% "zio-test" % zioVersion % Test, "dev.zio" %% "zio-test-sbt" % zioVersion % Test ), @@ -390,7 +395,7 @@ lazy val zioConfigEnumeratum = crossProject(JSPlatform, JVMPlatform, NativePlatf .settings(crossProjectSettings) .settings( libraryDependencies ++= Seq( - "com.beachape" %% "enumeratum" % "1.7.0", + "com.beachape" %% "enumeratum" % "1.7.2", "dev.zio" %% "zio-test" % zioVersion % Test, "dev.zio" %% "zio-test-sbt" % zioVersion % Test ), diff --git a/derivation/shared/src/main/scala-2.11/zio/config/derivation/NeedsDerive.scala b/derivation/shared/src/main/scala-2.11/zio/config/derivation/NeedsDerive.scala deleted file mode 100644 index 2813d5871..000000000 --- a/derivation/shared/src/main/scala-2.11/zio/config/derivation/NeedsDerive.scala +++ /dev/null @@ -1,23 +0,0 @@ -package zio.config.derivation - -import scala.annotation.implicitNotFound - -@implicitNotFound( - "Can't derive Config for `List[T]`, `Option[T]` or `Either[A, B]` directly." + - " Wrap it with a `case class Config(list: List[T])` or use `listOf(deriveConfig[T])` manually." -) -sealed trait NeedsDerive[+T] - -object NeedsDerive extends NeedsDerive[Nothing] { - - implicit def needsDerive[R]: NeedsDerive[R] = NeedsDerive - - implicit def needsDeriveAmbiguousList1: NeedsDerive[List[Nothing]] = NeedsDerive - implicit def needsDeriveAmbiguousList2: NeedsDerive[List[Nothing]] = NeedsDerive - - implicit def needsDeriveAmbiguousOption1: NeedsDerive[Option[Nothing]] = NeedsDerive - implicit def needsDeriveAmbiguousOption2: NeedsDerive[Option[Nothing]] = NeedsDerive - - implicit def needsDeriveAmbiguousEither1: NeedsDerive[Either[Nothing, Nothing]] = NeedsDerive - implicit def needsDeriveAmbiguousEither2: NeedsDerive[Either[Nothing, Nothing]] = NeedsDerive -} diff --git a/examples/shared/src/main/scala/zio/config/examples/SimpleReadConfigExample.scala b/examples/shared/src/main/scala/zio/config/examples/SimpleReadConfigExample.scala index 38655f96a..d9edeeef9 100644 --- a/examples/shared/src/main/scala/zio/config/examples/SimpleReadConfigExample.scala +++ b/examples/shared/src/main/scala/zio/config/examples/SimpleReadConfigExample.scala @@ -3,6 +3,8 @@ package zio.config.examples import zio.config._ import zio.{Config, ConfigProvider, Console, _} +import scala.annotation.nowarn + final case class Prod(ldap: String, port: Int, dburl: Option[String]) object Prod { @@ -15,11 +17,12 @@ object Prod { object ReadConfig extends ZIOAppDefault { - val configProvider: ConfigProvider = + private val configProvider: ConfigProvider = ConfigProvider.fromMap(Map("LDAP" -> "ldap", "PORT" -> "1999", "DB_URL" -> "ddd")) + @nowarn("cat=lint-infer-any") def run: URIO[Any, ExitCode] = - read(Prod.prodConfig from ConfigProvider.fromMap(Map("LDAP" -> "ldap", "PORT" -> "1999", "DB_URL" -> "ddd"))) + read(Prod.prodConfig from configProvider) .foldZIO( failure => Console.printLine(failure.toString), value => Console.printLine(value.toString) diff --git a/examples/shared/src/main/scala/zio/config/examples/autoderivation/AutoDerivationCustomKeys.scala b/examples/shared/src/main/scala/zio/config/examples/autoderivation/AutoDerivationCustomKeys.scala index a4b98fdf1..b82170589 100644 --- a/examples/shared/src/main/scala/zio/config/examples/autoderivation/AutoDerivationCustomKeys.scala +++ b/examples/shared/src/main/scala/zio/config/examples/autoderivation/AutoDerivationCustomKeys.scala @@ -1,15 +1,12 @@ package zio.config.examples.autoderivation -import com.github.ghik.silencer.silent import zio.config._ import zio.config.examples.typesafe.EitherImpureOps import zio.config.magnolia.deriveConfig import zio.config.typesafe.TypesafeConfigProvider import zio.{Config, IO} - import examples._ -@silent("deprecated") object AutoDerivationCustomKeys extends App with EitherImpureOps { final case class MyConfig(accountId: String, awsRegion: String) diff --git a/project/BuildHelper.scala b/project/BuildHelper.scala index 53022dcec..dc14430e4 100644 --- a/project/BuildHelper.scala +++ b/project/BuildHelper.scala @@ -139,7 +139,7 @@ object BuildHelper { ) case Some((2, 13)) => Seq( - "-Ywarn-unused:params,-implicits" + "-Wunused:params,-implicits,-nowarn" ) ++ std2xOptions ++ optimizerOptions(optimize) case Some((2, 12)) => Seq( @@ -213,14 +213,10 @@ object BuildHelper { scalacOptions := stdOptions ++ extraOptions(scalaVersion.value, optimize = !isSnapshot.value), libraryDependencies ++= { if (scalaVersion.value == ScalaDotty) - Seq( - "com.github.ghik" % s"silencer-lib_$Scala213" % SilencerVersion % Provided - ) + Seq() else Seq( - "com.github.ghik" % "silencer-lib" % SilencerVersion % Provided cross CrossVersion.full, - compilerPlugin("com.github.ghik" % "silencer-plugin" % SilencerVersion cross CrossVersion.full), - compilerPlugin("org.typelevel" %% "kind-projector" % "0.13.2" cross CrossVersion.full) + compilerPlugin("org.typelevel" %% "kind-projector" % "0.13.2" cross CrossVersion.full) ) }, semanticdbEnabled := scalaVersion.value != ScalaDotty, // enable SemanticDB @@ -228,8 +224,8 @@ object BuildHelper { semanticdbVersion := scalafixSemanticdb.revision, // use Scalafix compatible version ThisBuild / scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value), ThisBuild / scalafixDependencies ++= List( - "com.github.liancheng" %% "organize-imports" % "0.5.0", - "com.github.vovapolu" %% "scaluzzi" % "0.1.18" + "com.github.liancheng" %% "organize-imports" % "0.6.0", + "com.github.vovapolu" %% "scaluzzi" % "0.1.23" ), Test / parallelExecution := true, incOptions ~= (_.withLogRecompileOnMacro(false)), @@ -300,15 +296,13 @@ object BuildHelper { |${header(s"/____|___\\___/ ${version.value}")} | |Useful sbt tasks: - |${item("build")} - Prepares sources, compiles and runs tests. - |${item("prepare")} - Prepares sources by applying both scalafix and scalafmt + |${item("compileAll")} - Prepares sources & compiles. + |${item("testAll")} - Prepares sources & runs all tests. |${item("fix")} - Fixes sources files using scalafix |${item("fmt")} - Formats source files using scalafmt - |${item("~compileJVM")} - Compiles all JVM modules (file-watch enabled) |${item("testJVM")} - Runs all JVM tests |${item("testJS")} - Runs all ScalaJS tests |${item("testOnly *.YourSpec -- -t \"YourLabel\"")} - Only runs tests with matching term e.g. - |${subItem("coreTestsJVM/testOnly *.ZIOSpec -- -t \"happy-path\"")} |${item("docs/docusaurusCreateSite")} - Generates the ZIO microsite """.stripMargin } diff --git a/refined/shared/src/main/scala/zio/config/refined/package.scala b/refined/shared/src/main/scala/zio/config/refined/package.scala index ca07f13fd..f1f290861 100644 --- a/refined/shared/src/main/scala/zio/config/refined/package.scala +++ b/refined/shared/src/main/scala/zio/config/refined/package.scala @@ -1,6 +1,5 @@ package zio.config -import com.github.ghik.silencer.silent import eu.timepit.refined.api.{RefType, Refined, Validate} import zio.Config import zio.config.magnolia.DeriveConfig @@ -10,7 +9,6 @@ package object refined { /** * FIXME Automatically derive instances of Descriptor for any refined types */ - @silent("deprecated") implicit def deriveRefinedDescriptor[A, P](implicit desc: DeriveConfig[A], validate: Validate[A, P] @@ -29,7 +27,6 @@ package object refined { * refined[String, Uuid]("ID") * }}} */ - @silent("deprecated") def refine[A, P](path: String)(implicit desc: DeriveConfig[A], validate: Validate[A, P] diff --git a/refined/shared/src/test/scala-2.12/zio/config/refined/NumericTestTypes.scala b/refined/shared/src/test/scala-2.12/zio/config/refined/NumericTestTypes.scala new file mode 100644 index 000000000..3d90b80e4 --- /dev/null +++ b/refined/shared/src/test/scala-2.12/zio/config/refined/NumericTestTypes.scala @@ -0,0 +1,13 @@ +package zio.config.refined + +import eu.timepit.refined.W +import eu.timepit.refined.numeric.{Divisible, Greater, GreaterEqual, Less, LessEqual, NonDivisible} + +private[refined] trait NumericTestTypes { + type Less10 = Less[W.`10`.T] + type Greater10 = Greater[W.`10`.T] + type GreaterOrEqual10 = GreaterEqual[W.`10`.T] + type LessOrEqual10 = LessEqual[W.`10`.T] + type DivisibleBy10 = Divisible[W.`10`.T] + type NonDivisibleBy10 = NonDivisible[W.`10`.T] +} diff --git a/refined/shared/src/test/scala-2.13/zio/config/refined/NumericTestTypes.scala b/refined/shared/src/test/scala-2.13/zio/config/refined/NumericTestTypes.scala new file mode 100644 index 000000000..b16395f4a --- /dev/null +++ b/refined/shared/src/test/scala-2.13/zio/config/refined/NumericTestTypes.scala @@ -0,0 +1,12 @@ +package zio.config.refined + +import eu.timepit.refined.numeric.{Divisible, Greater, GreaterEqual, Less, LessEqual, NonDivisible} + +private[refined] trait NumericTestTypes { + type Less10 = Less[10] + type Greater10 = Greater[10] + type GreaterOrEqual10 = GreaterEqual[10] + type LessOrEqual10 = LessEqual[10] + type DivisibleBy10 = Divisible[10] + type NonDivisibleBy10 = NonDivisible[10] +} diff --git a/refined/shared/src/test/scala-3/zio/config/refined/NumericTestTypes.scala b/refined/shared/src/test/scala-3/zio/config/refined/NumericTestTypes.scala new file mode 100644 index 000000000..b16395f4a --- /dev/null +++ b/refined/shared/src/test/scala-3/zio/config/refined/NumericTestTypes.scala @@ -0,0 +1,12 @@ +package zio.config.refined + +import eu.timepit.refined.numeric.{Divisible, Greater, GreaterEqual, Less, LessEqual, NonDivisible} + +private[refined] trait NumericTestTypes { + type Less10 = Less[10] + type Greater10 = Greater[10] + type GreaterOrEqual10 = GreaterEqual[10] + type LessOrEqual10 = LessEqual[10] + type DivisibleBy10 = Divisible[10] + type NonDivisibleBy10 = NonDivisible[10] +} diff --git a/refined/shared/src/test/scala/zio/config/refined/NumericSupportTest.scala b/refined/shared/src/test/scala/zio/config/refined/NumericSupportTest.scala index ce4b0dbb6..b1463bf7f 100644 --- a/refined/shared/src/test/scala/zio/config/refined/NumericSupportTest.scala +++ b/refined/shared/src/test/scala/zio/config/refined/NumericSupportTest.scala @@ -1,21 +1,19 @@ package zio.config.refined -import eu.timepit.refined.W import eu.timepit.refined.api.Refined -import eu.timepit.refined.numeric.{Divisible, Greater, GreaterEqual, Less, LessEqual, NonDivisible} import zio.config._ import zio.test.Assertion._ import zio.test._ import zio.{Config, ConfigProvider, Scope, ZIO} -object NumericSupportTest extends ZIOSpecDefault { +object NumericSupportTest extends ZIOSpecDefault with RequiredNumericTypes with NumericTestTypes { override val spec: Spec[Environment with TestEnvironment with Scope, Any] = suite("Refined Numeric support")( test("Refined config Less invalid") { check(Gen.int(10, 100)) { p => - val cfg = refine[Int, Less[W.`10`.T]]("TEST") - val p2: ZIO[Any, Config.Error, Refined[Int, Less[W.`10`.T]]] = + val cfg = refine[Int, Less10]("TEST") + val p2: ZIO[Any, Config.Error, Refined[Int, Less10]] = read(cfg from ConfigProvider.fromMap(Map("TEST" -> p.toString), "test")) assertZIO(p2.either)(isLeft) @@ -23,8 +21,8 @@ object NumericSupportTest extends ZIOSpecDefault { }, test("Refined config Greater invalid") { check(Gen.int(1, 10)) { p => - val cfg = refine[Int, Greater[W.`10`.T]]("TEST") - val p2: ZIO[Any, Config.Error, Refined[Int, Greater[W.`10`.T]]] = + val cfg = refine[Int, Greater10]("TEST") + val p2: ZIO[Any, Config.Error, Refined[Int, Greater10]] = read(cfg from ConfigProvider.fromMap(Map("TEST" -> p.toString))) assertZIO(p2.either)(isLeft) @@ -32,8 +30,8 @@ object NumericSupportTest extends ZIOSpecDefault { }, test("Refined config LessEqual invalid") { check(Gen.int(11, 100)) { p => - val cfg = refine[Int, LessEqual[W.`10`.T]]("TEST") - val p2: ZIO[Any, Config.Error, Refined[Int, LessEqual[W.`10`.T]]] = + val cfg = refine[Int, LessOrEqual10]("TEST") + val p2: ZIO[Any, Config.Error, Refined[Int, LessOrEqual10]] = read(cfg from ConfigProvider.fromMap(Map("TEST" -> p.toString), "test")) assertZIO(p2.either)(isLeft) @@ -41,7 +39,7 @@ object NumericSupportTest extends ZIOSpecDefault { }, test("Refined config GreaterEqual invalid") { check(Gen.int(1, 9)) { p => - val cfg = refine[Int, GreaterEqual[W.`10`.T]]("TEST") + val cfg = refine[Int, GreaterOrEqual10]("TEST") val p2 = read(cfg from ConfigProvider.fromMap(Map("TEST" -> p.toString))) @@ -50,7 +48,7 @@ object NumericSupportTest extends ZIOSpecDefault { }, test("Refined config Divisible invalid") { check(Gen.int(1, 10).map(_ * 10 + 1)) { p => - val cfg = refine[Int, Divisible[W.`10`.T]]("TEST") + val cfg = refine[Int, DivisibleBy10]("TEST") val p2 = read(cfg from ConfigProvider.fromMap(Map("TEST" -> p.toString), "test")) @@ -59,7 +57,7 @@ object NumericSupportTest extends ZIOSpecDefault { }, test("Refined config NonDivisible invalid") { check(Gen.int(1, 10).map(_ * 10)) { p => - val cfg = refine[Int, NonDivisible[W.`10`.T]]("TEST") + val cfg = refine[Int, NonDivisibleBy10]("TEST") val p2 = read(cfg from ConfigProvider.fromMap(Map("TEST" -> p.toString), "test")) diff --git a/refined/shared/src/test/scala/zio/config/refined/RequiredNumericTypes.scala b/refined/shared/src/test/scala/zio/config/refined/RequiredNumericTypes.scala new file mode 100644 index 000000000..657596acc --- /dev/null +++ b/refined/shared/src/test/scala/zio/config/refined/RequiredNumericTypes.scala @@ -0,0 +1,10 @@ +package zio.config.refined + +private[refined] trait RequiredNumericTypes { this: NumericTestTypes => + type Less10 + type Greater10 + type GreaterOrEqual10 + type LessOrEqual10 + type DivisibleBy10 + type NonDivisibleBy10 +} diff --git a/typesafe-magnolia-tests/shared/src/test/scala/zio/config/magnolia/CoproductSealedTraitSpec.scala b/typesafe-magnolia-tests/shared/src/test/scala/zio/config/magnolia/CoproductSealedTraitSpec.scala index 08a07b40d..ee82e1a8b 100644 --- a/typesafe-magnolia-tests/shared/src/test/scala/zio/config/magnolia/CoproductSealedTraitSpec.scala +++ b/typesafe-magnolia-tests/shared/src/test/scala/zio/config/magnolia/CoproductSealedTraitSpec.scala @@ -2,8 +2,7 @@ package zio.config.magnolia import zio.ConfigProvider import zio.config._ -import zio.config.derivation.name -import zio.config.magnolia._ +import zio.config.derivation.{ name => derivedName } import zio.test.Assertion._ import zio.test.{ZIOSpecDefault, _} @@ -13,7 +12,7 @@ object CoproductSealedTraitSpec extends ZIOSpecDefault { case object A extends X case object B extends X - @name("c") + @derivedName("c") case object C extends X case class D(detail: Detail) extends X case class E(detail: Detail) extends X diff --git a/typesafe/shared/src/main/scala/zio/config/typesafe/TypesafeConfigProvider.scala b/typesafe/shared/src/main/scala/zio/config/typesafe/TypesafeConfigProvider.scala index 8ca520911..a631e6117 100644 --- a/typesafe/shared/src/main/scala/zio/config/typesafe/TypesafeConfigProvider.scala +++ b/typesafe/shared/src/main/scala/zio/config/typesafe/TypesafeConfigProvider.scala @@ -1,16 +1,16 @@ package zio.config.typesafe -import com.github.ghik.silencer.silent import com.typesafe.config._ import zio.config.IndexedFlat.{ConfigPath, KeyComponent} import zio.config._ import zio.{Chunk, ConfigProvider} import java.io.File +import scala.annotation.nowarn import scala.jdk.CollectionConverters._ import scala.util.{Failure, Success, Try} -@silent("Unused import") +@nowarn("cat=unused-imports") object TypesafeConfigProvider { import VersionSpecificSupport._ diff --git a/xml/shared/src/main/scala/zio/config/xml/experimental/XmlConfigProvider.scala b/xml/shared/src/main/scala/zio/config/xml/experimental/XmlConfigProvider.scala index 0f8f9cc2c..21d9d6d1c 100644 --- a/xml/shared/src/main/scala/zio/config/xml/experimental/XmlConfigProvider.scala +++ b/xml/shared/src/main/scala/zio/config/xml/experimental/XmlConfigProvider.scala @@ -1,10 +1,8 @@ package zio.config.xml.experimental -import com.github.ghik.silencer.silent import zio.ConfigProvider import zio.config.IndexedFlat.ConfigPath -@silent("Unused import") object XmlConfigProvider { /** diff --git a/yaml/shared/src/main/scala/zio/config/yaml/YamlConfigProvider.scala b/yaml/shared/src/main/scala/zio/config/yaml/YamlConfigProvider.scala index 8adfad445..264b0170c 100644 --- a/yaml/shared/src/main/scala/zio/config/yaml/YamlConfigProvider.scala +++ b/yaml/shared/src/main/scala/zio/config/yaml/YamlConfigProvider.scala @@ -1,6 +1,5 @@ package zio.config.yaml -import com.github.ghik.silencer.silent import org.snakeyaml.engine.v2.api.{Load, LoadSettings} import zio.config._ import zio.config.syntax.IndexKey @@ -11,9 +10,10 @@ import java.lang.{Boolean => JBoolean, Double => JDouble, Float => JFloat, Integ import java.nio.charset.Charset import java.nio.file.Path import java.{util => ju} +import scala.annotation.nowarn import scala.jdk.CollectionConverters._ -@silent("Unused import") +@nowarn("cat=unused-imports") object YamlConfigProvider { import scala.collection.compat._