From 0070476258f79a4786ced34e876b777b879c651c Mon Sep 17 00:00:00 2001 From: Brice Jaglin Date: Sat, 21 Dec 2024 10:00:40 +0100 Subject: [PATCH] Update metaconfig-typesafe-config to 0.14.0 --- project/Dependencies.scala | 2 +- .../scala/scalafix/internal/v1/Args.scala | 24 +++++++++---------- .../internal/v1/ScalafixConfOps.scala | 20 ---------------- .../internal/config/MetaconfigOps.scala | 8 +++---- .../internal/rule/OrganizeImports.scala | 10 ++++++-- .../scalafix/testkit/SemanticRuleSuite.scala | 12 +++++++++- .../scalafix/tests/config/ArgsSuite.scala | 9 +++++-- 7 files changed, 43 insertions(+), 42 deletions(-) delete mode 100644 scalafix-cli/src/main/scala/scalafix/internal/v1/ScalafixConfOps.scala diff --git a/project/Dependencies.scala b/project/Dependencies.scala index 2b0694d58..679c9e7af 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -17,7 +17,7 @@ object Dependencies { val commontTextV = "1.13.0" val googleDiffV = "1.3.0" val jgitV = "5.13.3.202401111512-r" - val metaconfigV = "0.13.0" + val metaconfigV = "0.14.0" val nailgunV = "0.9.1" val scalaXmlV = "2.2.0" val scalametaV = "4.12.2" diff --git a/scalafix-cli/src/main/scala/scalafix/internal/v1/Args.scala b/scalafix-cli/src/main/scala/scalafix/internal/v1/Args.scala index 6c935a58a..44e29520e 100644 --- a/scalafix-cli/src/main/scala/scalafix/internal/v1/Args.scala +++ b/scalafix-cli/src/main/scala/scalafix/internal/v1/Args.scala @@ -255,23 +255,23 @@ case class Args( // With a --triggered flag, looking for settings in triggered block first, and fallback to standard settings. def maybeOverlaidConfWithTriggered(base: Conf): Conf = - if (triggered) - ScalafixConfOps.overlay(base, "triggered") - else - base + if (triggered) { + val triggeredOverlay = ConfGet + .getOrOK[Conf](base, "triggered" :: Nil, Configured.ok, Conf.Obj.empty) + .getOrElse(Conf.Obj.empty) + ConfOps.merge(base, triggeredOverlay) + } else base def rulesConf(base: () => Conf): Conf = { if (rules.isEmpty) { - val rulesInConf = - ConfGet.getKey( + ConfGet + .getOrOK[Conf]( maybeOverlaidConfWithTriggered(base()), - "rules" :: "rule" :: Nil + "rules" :: "rule" :: Nil, + Configured.ok, + Conf.Obj.empty ) - - rulesInConf match { - case Some(c) => c - case _ => Conf.Lst(Nil) - } + .getOrElse(Conf.Obj.empty) } else { Conf.Lst(rules.map(Conf.fromString)) } diff --git a/scalafix-cli/src/main/scala/scalafix/internal/v1/ScalafixConfOps.scala b/scalafix-cli/src/main/scala/scalafix/internal/v1/ScalafixConfOps.scala deleted file mode 100644 index a0c2f0197..000000000 --- a/scalafix-cli/src/main/scala/scalafix/internal/v1/ScalafixConfOps.scala +++ /dev/null @@ -1,20 +0,0 @@ -package scalafix.internal.v1 - -import metaconfig.Conf -import metaconfig.Conf.Obj -import metaconfig.ConfOps -import metaconfig.internal.ConfGet - -object ScalafixConfOps { - def drop(original: Conf, key: String): Conf = - ConfOps.fold(original)(obj = { confObj => - Obj(confObj.values.filterNot(_._1 == key)) - }) - - def overlay(original: Conf, key: String): Conf = { - val child = ConfGet.getKey(original, key :: Nil) - child.fold(original)( - ConfOps.merge(drop(original, key), _) - ) - } -} diff --git a/scalafix-core/src/main/scala/scalafix/internal/config/MetaconfigOps.scala b/scalafix-core/src/main/scala/scalafix/internal/config/MetaconfigOps.scala index d72fd3e13..83b9c8a65 100644 --- a/scalafix-core/src/main/scala/scalafix/internal/config/MetaconfigOps.scala +++ b/scalafix-core/src/main/scala/scalafix/internal/config/MetaconfigOps.scala @@ -36,10 +36,10 @@ object MetaconfigOps { def getKey[T](conf: Conf.Obj, path: String, extraNames: String*)(implicit ev: ConfDecoder[T] ): Configured[T] = { - ConfGet.getKey(conf, path +: extraNames) match { - case Some(value) => ev.read(value) - case None => ConfError.missingField(conf, path).notOk - } + ConfGet.getOrElse( + value => ev.read(value), + ConfError.missingField(conf, path).notOk + )(conf, path +: extraNames) } implicit class XtensionMetaconfigInputToMeta(input: Input) { diff --git a/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala b/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala index 4e4c01c08..80657ab8b 100644 --- a/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala +++ b/scalafix-rules/src/main/scala/scalafix/internal/rule/OrganizeImports.scala @@ -852,8 +852,14 @@ object OrganizeImports { ): Configured[OrganizeImportsConfig] = { val preset = OrganizeImportsConfig.presets(ruleConf.preset) val presetConf = ConfEncoder[OrganizeImportsConfig].write(preset) - val userConf = - ConfGet.getKey(conf, "OrganizeImports" :: Nil).getOrElse(Conf.Obj.empty) + val userConf = ConfGet + .getOrOK[Conf]( + conf, + "OrganizeImports" :: Nil, + Configured.ok, + Conf.Obj.empty + ) + .getOrElse(Conf.Obj.empty) val mergedConf = ConfOps.merge(presetConf, userConf) ConfDecoder[OrganizeImportsConfig].read(mergedConf) } diff --git a/scalafix-testkit/src/main/scala/scalafix/testkit/SemanticRuleSuite.scala b/scalafix-testkit/src/main/scala/scalafix/testkit/SemanticRuleSuite.scala index 30d85b812..dd6f33f88 100644 --- a/scalafix-testkit/src/main/scala/scalafix/testkit/SemanticRuleSuite.scala +++ b/scalafix-testkit/src/main/scala/scalafix/testkit/SemanticRuleSuite.scala @@ -6,6 +6,7 @@ import scala.meta._ import scala.meta.internal.inputs.XtensionInput import metaconfig.Conf +import metaconfig.Configured import metaconfig.internal.ConfGet import metaconfig.typesafeconfig.typesafeConfigMetaconfigParser import scalafix.internal.config.ScalafixConfig @@ -45,7 +46,16 @@ object SemanticRuleSuite { for { conf <- Try(Conf.parseString("comment", syntax)).toOption .flatMap(_.toEither.toOption) - rulesConf <- ConfGet.getKey(conf, "rules" :: "rule" :: Nil) + rulesConf <- + ConfGet + .getOrOK[Conf]( + conf, + "rules" :: "rule" :: Nil, + Configured.ok, + Conf.Obj.empty + ) + .toEither + .toOption scalafixConfig <- conf.as[ScalafixConfig].toEither.toOption } yield (comment, conf, rulesConf, scalafixConfig) } diff --git a/scalafix-tests/unit/src/test/scala/scalafix/tests/config/ArgsSuite.scala b/scalafix-tests/unit/src/test/scala/scalafix/tests/config/ArgsSuite.scala index 1fa4c7b3c..37b4b25cd 100644 --- a/scalafix-tests/unit/src/test/scala/scalafix/tests/config/ArgsSuite.scala +++ b/scalafix-tests/unit/src/test/scala/scalafix/tests/config/ArgsSuite.scala @@ -3,6 +3,7 @@ package scalafix.tests.config import scala.meta.io.AbsolutePath import metaconfig.Conf +import metaconfig.Configured import metaconfig.internal.ConfGet import metaconfig.typesafeconfig.typesafeConfigMetaconfigParser import scalafix.internal.config.ScalaVersion @@ -46,7 +47,9 @@ class ArgsSuite extends munit.FunSuite { val merged = args.maybeOverlaidConfWithTriggered(givenConf) - val disableSyntaxRule = ConfGet.getKey(merged, "DisableSyntax" :: Nil).get + val disableSyntaxRule = ConfGet + .getOrOK(merged, "DisableSyntax" :: Nil, Configured.ok, Conf.Obj.empty) + .get val expected = Conf.Obj("noVars" -> Conf.Bool(true), "noThrows" -> Conf.Bool(true)) @@ -64,7 +67,9 @@ class ArgsSuite extends munit.FunSuite { val merged = args.maybeOverlaidConfWithTriggered(givenConf) - val disableSyntaxRule = ConfGet.getKey(merged, "DisableSyntax" :: Nil).get + val disableSyntaxRule = ConfGet + .getOrOK(merged, "DisableSyntax" :: Nil, Configured.ok, Conf.Obj.empty) + .get val expected = Conf.Obj(