Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -158,13 +158,11 @@ object Align {
implicit val alignTokensDecoder: ConfDecoderEx[Seq[AlignToken]] = AlignToken
.seqDecoder.except { case (_, conf) =>
preset.lift(conf).map(x => Configured.Ok(x.tokens))
}.contramap {
case Conf.Obj(List(("add", c))) =>
Console.err.println(
"""'align.tokens.add' is deprecated; use align.tokens."+" instead.""",
)
Conf.Obj("+" -> c)
case conf => conf
}.contramapPartial { case Conf.Obj(List(("add", c))) =>
Console.err.println(
"""'align.tokens.add' is deprecated; use align.tokens."+" instead.""",
)
Conf.Obj("+" -> c)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ object IndentOperator {

val boolToAssign: PartialFunction[Conf, Conf] = { case Conf.Bool(value) =>
if (value) Conf.Obj(
exemptScopeName -> Conf.nameOf(Exempt.notAssign),
Conf.nameOf(default.excludeRegex).value -> Conf.Str(".*"),
(exemptScopeName, Conf.nameOf(Exempt.notAssign)),
(Conf.nameOf(default.excludeRegex), Conf.Str(".*")),
)
else Conf.Obj.empty
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,8 @@ object Newlines {
.deriveSurface[SelectChain]
implicit val encoder: ConfEncoder[SelectChain] = generic.deriveEncoder
implicit val decoder: ConfDecoderEx[SelectChain] = generic
.deriveDecoderEx(default).noTypos.contramap {
case conf: Conf.Str => Conf.Obj("style" -> conf)
case conf => conf
}
.deriveDecoderEx(default).noTypos
.contramapPartial { case conf: Conf.Str => Conf.Obj("style" -> conf) }
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,11 @@ object Presets {

val presetKey = "preset"

def contramap[A <: Product](
baseDecoder: ConfDecoderEx[A],
)(f: PartialFunction[Conf, Conf]): ConfDecoderEx[A] = baseDecoder.contramap {
case conf @ Conf.Obj(v) => v.collectFirst { case (`presetKey`, x) => x }
.flatMap(f.lift.apply)
.fold(conf)(x => Conf.Obj((presetKey -> x) :: v.filter(_._1 != presetKey)))
case conf => conf
def contramap[A <: Product](baseDecoder: ConfDecoderEx[A])(
f: PartialFunction[Conf, Conf],
): ConfDecoderEx[A] = baseDecoder.contramapPartialOpt { case Conf.Obj(v) =>
v.collectFirst { case (`presetKey`, x) => x }.flatMap(f.lift.apply)
.map(x => Conf.Obj((presetKey -> x) :: v.filter(_._1 != presetKey)))
}

def mapDecoder[A <: Product](
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,13 @@ object RewriteScala3Settings {

implicit final val decoder: ConfDecoderEx[RemoveOptionalBraces] = generic
.deriveDecoderEx[RemoveOptionalBraces](no).noTypos.detectSectionRenames
.contramap {
.contramapPartial {
case Conf.Bool(true) | Conf.Str("yes") => Conf
.Obj("enabled" -> Conf(true))
case Conf.Bool(false) | Conf.Str("no") => Conf
.Obj("enabled" -> Conf(false))
case Conf.Str("oldSyntaxToo") => Conf
.Obj("enabled" -> Conf(true), "oldSyntaxToo" -> Conf(true))
case conf => conf
}

}
Expand Down