Skip to content

Commit

Permalink
Literals: move Case inside the companion
Browse files Browse the repository at this point in the history
First, it is used only with Literals, and second, it avoids conflicts
with scala.meta.Case.
  • Loading branch information
kitbellew committed Oct 5, 2024
1 parent 289112a commit 3c960c6
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 24 deletions.
20 changes: 0 additions & 20 deletions scalafmt-core/shared/src/main/scala/org/scalafmt/config/Case.scala

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.scalafmt.config

import Literals.Case
import metaconfig._

case class Literals(
Expand All @@ -16,4 +17,21 @@ object Literals {
implicit val surface: generic.Surface[Literals] = generic.deriveSurface
implicit val codec: ConfCodecEx[Literals] = generic.deriveCodecEx(Literals())
.noTypos

sealed abstract class Case {
import Case._
def process(str: String): String = this match {
case Unchanged => str
case Lower => str.toLowerCase()
case Upper => str.toUpperCase()
}
}

object Case {
implicit val codec: ConfCodecEx[Case] = ReaderUtil
.oneOf[Case](Upper, Lower, Unchanged)
case object Upper extends Case
case object Lower extends Case
case object Unchanged extends Case
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import org.scalafmt.CompatCollections.JavaConverters._
import org.scalafmt.Error
import org.scalafmt.Formatted
import org.scalafmt.Scalafmt
import org.scalafmt.config.{Case => _, _}
import org.scalafmt.config._
import org.scalafmt.internal.RegexCompat._
import org.scalafmt.rewrite.RedundantBraces
import org.scalafmt.util.LiteralOps
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.scalafmt.util

import org.scalafmt.config.Case
import org.scalafmt.config.ScalafmtConfig
import org.scalafmt.config._

object LiteralOps {

Expand Down Expand Up @@ -52,7 +51,7 @@ object LiteralOps {
str: String,
suffixUpper: Char,
suffixLower: Char,
suffixCase: Case,
suffixCase: Literals.Case,
)(implicit style: ScalafmtConfig): String =
if (str.last == suffixUpper || str.last == suffixLower) style.literals
.scientific.process(str.dropRight(1)) +
Expand Down

0 comments on commit 3c960c6

Please sign in to comment.