Skip to content

Commit

Permalink
Use wildcard imports for metaconfig (and others)
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Dec 12, 2024
1 parent 038e198 commit 1520f52
Show file tree
Hide file tree
Showing 16 changed files with 42 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ package org.scalafmt.config

import java.nio.file.Path

import metaconfig.Input
import metaconfig.MetaconfigParser
import metaconfig._

object PlatformConfig {
val isScalaNative = false
implicit val parser = metaconfig.hocon.hoconMetaconfigParser
implicit val parser = hocon.hoconMetaconfigParser
def metaconfigInputFromFile(input: Path) = Input.File(input)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@ package org.scalafmt.config

import java.nio.file.Path

import metaconfig.Input
import metaconfig.MetaconfigParser
import metaconfig._

object PlatformConfig {
val isScalaNative = false
implicit val parser: MetaconfigParser =
metaconfig.typesafeconfig.typesafeConfigMetaconfigParser
typesafeconfig.typesafeConfigMetaconfigParser
def metaconfigInputFromFile(input: Path) = Input.File(input)
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package org.scalafmt.config

import java.nio.file.Files
import java.nio.file.Path
import java.nio.file._

import metaconfig.Input
import metaconfig.MetaconfigParser
import metaconfig._

object PlatformConfig {
val isScalaNative = true
implicit val parser: MetaconfigParser =
metaconfig.sconfig.sConfigMetaconfigParser
implicit val parser: MetaconfigParser = sconfig.sConfigMetaconfigParser
def metaconfigInputFromFile(input: Path) = Input
.String(new String(Files.readAllBytes(input)))
}
14 changes: 4 additions & 10 deletions scalafmt-core/shared/src/main/scala/org/scalafmt/Scalafmt.scala
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package org.scalafmt

import org.scalafmt.Error.PreciseIncomplete
import org.scalafmt.config.FormatEvent.CreateFormatOps
import org.scalafmt.config.NamedDialect
import org.scalafmt.config.ScalafmtConfig
import org.scalafmt.internal.BestFirstSearch
import org.scalafmt.internal.FormatOps
import org.scalafmt.internal.FormatWriter
import org.scalafmt.config._
import org.scalafmt.internal._
import org.scalafmt.rewrite.Rewrite
import org.scalafmt.sysops.FileOps
import org.scalafmt.util.MarkdownParser
Expand All @@ -18,9 +14,7 @@ import scala.meta.tokenizers.TokenizerOptions

import java.nio.file.Path

import scala.util.Failure
import scala.util.Success
import scala.util.Try
import scala.util._

import metaconfig.Configured

Expand Down Expand Up @@ -121,7 +115,7 @@ object Scalafmt {
},
tree => {
implicit val formatOps = new FormatOps(tree, style, file)
runner.event(CreateFormatOps(formatOps))
runner.event(FormatEvent.CreateFormatOps(formatOps))
implicit val formatWriter = new FormatWriter(formatOps)
Try(BestFirstSearch(range)).flatMap { res =>
val formattedString = formatWriter.mkString(res.state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package org.scalafmt.config
import scala.meta._

import metaconfig._
import metaconfig.annotation.ExtraName
import metaconfig.generic.Surface

/** @param openParenCallSite
* If true AND bin-packing is true, then call-site arguments won't be aligned
Expand Down Expand Up @@ -78,7 +76,7 @@ case class Align(
closeParenSite: Boolean = false,
private val openBracketCallSite: Option[Boolean] = None,
openParenCallSite: Boolean = false,
@ExtraName("ifWhileOpenParen")
@annotation.ExtraName("ifWhileOpenParen")
openParenCtrlSite: Boolean = false,
private val openBracketDefnSite: Option[Boolean] = None,
openParenDefnSite: Boolean = false,
Expand Down Expand Up @@ -134,7 +132,8 @@ object Align {
val some = Align()
val default = some
val more: Align = some.copy(tokens = AlignToken.default)
implicit lazy val surface: Surface[Align] = generic.deriveSurface[Align]
implicit lazy val surface: generic.Surface[Align] = generic
.deriveSurface[Align]
implicit lazy val encoder: ConfEncoder[Align] = generic.deriveEncoder
implicit lazy val decoder: ConfDecoderEx[Align] = Presets
.mapDecoder(generic.deriveDecoderEx(default).noTypos, "align")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import org.scalafmt.util.ParamClauseParent

import java.util.regex.{Pattern => jurPattern}

import metaconfig.Configured.Ok
import metaconfig._
import metaconfig.annotation.DeprecatedName
import metaconfig.generic.Surface

/** Configuration option for aligning tokens.
*
Expand All @@ -18,7 +15,7 @@ import metaconfig.generic.Surface
*/
case class AlignToken(
code: String,
@DeprecatedName("owner", "use owners instead", "3.0.0")
@annotation.DeprecatedName("owner", "use owners instead", "3.0.0")
owner: String = null,
owners: Seq[AlignToken.Owner] = Seq.empty,
) {
Expand Down Expand Up @@ -49,10 +46,11 @@ object AlignToken {
def getMatcher: Matcher =
new Matcher(regex.map(pattern), parents.map(pattern))
}
implicit val ownerSurface: Surface[Owner] = generic.deriveSurface[Owner]
implicit val ownerSurface: generic.Surface[Owner] = generic
.deriveSurface[Owner]
implicit val ownerCodec: ConfCodecEx[Owner] = generic.deriveCodecEx(Owner())

implicit lazy val surface: Surface[AlignToken] = generic
implicit lazy val surface: generic.Surface[AlignToken] = generic
.deriveSurface[AlignToken]
implicit lazy val encoder: ConfEncoder[AlignToken] = generic.deriveEncoder
val applyInfix = "Term.ApplyInfix"
Expand All @@ -61,9 +59,9 @@ object AlignToken {
implicit val decoder: ConfDecoderEx[AlignToken] = {
val base = generic.deriveDecoderEx[AlignToken](fallbackAlign).noTypos
ConfDecoderEx.from {
case (_, Conf.Str("caseArrow")) => Ok(caseArrow)
case (_, Conf.Str(regex)) =>
Ok(default.find(_.code == regex).getOrElse(AlignToken(regex)))
case (_, Conf.Str("caseArrow")) => Configured.Ok(caseArrow)
case (_, Conf.Str(regex)) => Configured
.Ok(default.find(_.code == regex).getOrElse(AlignToken(regex)))
case (state, conf) => base.read(state, conf)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.scalafmt.config

import java.util.regex.Matcher
import java.util.regex.Pattern
import java.util.regex._

import metaconfig._
import metaconfig.generic.Surface

case class AvoidInfixSettings(
// partial match
Expand Down Expand Up @@ -82,7 +80,7 @@ object AvoidInfixSettings {
}

private[config] object Filter {
implicit lazy val surface: Surface[Filter] = generic.deriveSurface
implicit lazy val surface: generic.Surface[Filter] = generic.deriveSurface
implicit lazy val encoder: ConfEncoder[Filter] = ConfEncoder
.instance(x => Conf.Str(x.pattern))
implicit lazy val decoder: ConfDecoderEx[Filter] = ConfDecoderEx
Expand All @@ -101,7 +99,8 @@ object AvoidInfixSettings {
def apply(value: String): Filter = parse(value).get
}

implicit lazy val surface: Surface[AvoidInfixSettings] = generic.deriveSurface
implicit lazy val surface: generic.Surface[AvoidInfixSettings] =
generic.deriveSurface
implicit lazy val codec: ConfCodecEx[AvoidInfixSettings] = generic
.deriveCodecEx(default).noTypos

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

import metaconfig.Conf
import metaconfig.ConfCodecEx
import metaconfig.Configured
import metaconfig._

sealed abstract class LineEndings

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.scalafmt.util.TreeOps
import scala.meta._

import metaconfig._
import metaconfig.generic.Surface

/** @param penalizeSingleSelectMultiArgList
* - If true, adds a penalty to newlines before a dot starting a select chain
Expand Down Expand Up @@ -343,7 +342,7 @@ case class Newlines(
}

object Newlines {
implicit lazy val surface: Surface[Newlines] = generic.deriveSurface
implicit lazy val surface: generic.Surface[Newlines] = generic.deriveSurface
implicit lazy val codec: ConfCodecEx[Newlines] = generic
.deriveCodecEx(Newlines()).noTypos

Expand Down Expand Up @@ -500,7 +499,8 @@ object Newlines {
def isEmpty: Boolean = before == 0 && after == 0
}
object NumBlanks {
implicit val surface: Surface[NumBlanks] = generic.deriveSurface[NumBlanks]
implicit val surface: generic.Surface[NumBlanks] = generic
.deriveSurface[NumBlanks]
implicit val encoder: ConfEncoder[NumBlanks] = generic
.deriveEncoder[NumBlanks]
implicit val decoder: ConfDecoderEx[NumBlanks] = {
Expand Down Expand Up @@ -540,7 +540,7 @@ object Newlines {
pattern.forall(_.matcher(prefix).find())
}
object TopStatBlanks {
implicit val surface: Surface[TopStatBlanks] = generic
implicit val surface: generic.Surface[TopStatBlanks] = generic
.deriveSurface[TopStatBlanks]
implicit val codec: ConfCodecEx[TopStatBlanks] = generic
.deriveCodecEx(TopStatBlanks()).noTypos
Expand Down Expand Up @@ -577,7 +577,7 @@ object Newlines {
}
private[config] object ConfigStyleElement {
private val default = ConfigStyleElement()
implicit val surface: Surface[ConfigStyleElement] = generic
implicit val surface: generic.Surface[ConfigStyleElement] = generic
.deriveSurface[ConfigStyleElement]
implicit val codec: ConfCodecEx[ConfigStyleElement] = generic
.deriveCodecEx(default).noTypos
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.scalafmt.config

import metaconfig._
import metaconfig.generic.Surface

/** @param configStyleArguments
* Call-sites where there is a newline after opening ( and newline before
Expand Down Expand Up @@ -121,7 +120,7 @@ case class OptIn(
)

object OptIn {
implicit lazy val surface: Surface[OptIn] = generic.deriveSurface
implicit lazy val surface: generic.Surface[OptIn] = generic.deriveSurface
implicit lazy val codec: ConfCodecEx[OptIn] = generic.deriveCodecEx(OptIn())
.noTypos
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,19 @@ import java.nio.file
import scala.annotation.tailrec

import metaconfig._
import metaconfig.annotation.DeprecatedName

case class ProjectFiles(
git: Boolean = false,
layout: Option[ProjectFiles.Layout] = None,
includePaths: Seq[String] = ProjectFiles.defaultIncludePaths,
excludePaths: Seq[String] = Nil,
@DeprecatedName(
@annotation.DeprecatedName(
"includeFilters",
"use `includePaths` with `regex:` prefix",
"v3.0.0",
)
includeFilters: Seq[String] = Nil,
@DeprecatedName(
@annotation.DeprecatedName(
"excludeFilters",
"use `excludePaths` with `regex:` prefix",
"v3.0.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package org.scalafmt.config

import metaconfig._
import metaconfig.annotation.ExtraName

case class RedundantBracesSettings(
@ExtraName("methodBodies")
@annotation.ExtraName("methodBodies")
defnBodies: RedundantBracesSettings.DefnBodies =
RedundantBracesSettings.DefnBodies.all,
includeUnitMethods: Boolean = true,
@ExtraName("maxLines")
@annotation.ExtraName("maxLines")
maxBreaks: Int = 100,
stringInterpolation: Boolean = false,
parensForOneLineApply: Boolean = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,7 @@ import scala.meta.parsers.Parse._

import scala.io.Codec

import metaconfig.Conf
import metaconfig.ConfCodecEx
import metaconfig.ConfDecoderEx
import metaconfig.Configured
import metaconfig._

object ScalafmtConfDecoders extends ScalafmtConfDecoders

Expand Down
10 changes: 3 additions & 7 deletions scalafmt-docs/src/main/scala/docs/DefaultsModifier.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@ package docs

import org.scalafmt.config.ScalafmtConfig

import scala.meta.inputs.Input
import scala.meta.inputs.Position
import scala.meta.inputs._

import mdoc.Reporter
import mdoc.StringModifier
import metaconfig.Conf
import metaconfig.ConfEncoder
import metaconfig.Configured
import mdoc._
import metaconfig._

class DefaultsModifier extends StringModifier {
override val name: String = "defaults"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import org.scalafmt.config.ConfParsed

import scala.meta._

import java.nio.file.FileSystems
import java.nio.file.Path
import java.nio.file._

import metaconfig.Conf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ import java.util.regex.Pattern
import scala.annotation.tailrec
import scala.collection.mutable

import metaconfig.Conf
import metaconfig.Configured
import metaconfig._
import munit.Assertions._
import munit.Location

Expand Down

0 comments on commit 1520f52

Please sign in to comment.