Skip to content

Commit

Permalink
Removed silencer SBT plugin
Browse files Browse the repository at this point in the history
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),<init>) at readTasty
```

I also added a few improvements in the build itself, and fixed a few tests.
  • Loading branch information
tPl0ch committed May 23, 2023
1 parent 07c878e commit 39a5f0f
Show file tree
Hide file tree
Showing 15 changed files with 85 additions and 70 deletions.
15 changes: 10 additions & 5 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import BuildHelper._

welcomeMessage

inThisBuild(
List(
organization := "dev.zio",
Expand All @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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
),
Expand All @@ -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
),
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
20 changes: 7 additions & 13 deletions project/BuildHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -213,23 +213,19 @@ 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
semanticdbOptions += "-P:semanticdb:synthetics:on",
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)),
Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
@@ -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]
}
Original file line number Diff line number Diff line change
@@ -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]
}
Original file line number Diff line number Diff line change
@@ -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]
}
Original file line number Diff line number Diff line change
@@ -1,47 +1,45 @@
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)
}
},
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)
}
},
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)
}
},
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)))

Expand All @@ -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"))

Expand All @@ -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"))

Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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, _}

Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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._
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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._
Expand Down

0 comments on commit 39a5f0f

Please sign in to comment.