Skip to content

Commit

Permalink
Merge pull request #881 from xuwei-k/wildcard-syntax
Browse files Browse the repository at this point in the history
update `.scalafmt.conf`. enforce new wildcard syntax
  • Loading branch information
mkurz authored Jan 19, 2025
2 parents fa3ce3e + 2f17c3c commit ff7df61
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
6 changes: 6 additions & 0 deletions .scalafmt.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ rewrite.rules = [ AvoidInfix, ExpandImportSelectors, RedundantParens, SortModifi
rewrite.sortModifiers.order = [ "private", "protected", "final", "sealed", "abstract", "implicit", "override", "lazy" ]
spaces.inImportCurlyBraces = true # more idiomatic to include whitepsace in import x.{ yyy }
trailingCommas = preserve
rewrite.scala3.convertToNewSyntax = true
runner.dialectOverride {
allowSignificantIndentation = false
allowAsForImportRename = false
allowStarWildcardImport = false
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ case class BaseScalaTemplate[T <: Appendable[T], F <: Format[T]](format: F) {
case () => format.empty
case None => format.empty
case Some(v) => _display_(v)
case key: Optional[_] =>
case key: Optional[?] =>
(if (key.isPresent) Some(key.get) else None) match {
case None => format.empty
case Some(v) => _display_(v)
case _ => format.empty
}
case xml: scala.xml.NodeSeq => format.raw(xml.toString())
case escapeds: immutable.Seq[_] => format.fill(escapeds.map(_display_))
case escapeds: TraversableOnce[_] => format.fill(escapeds.map(_display_).toList)
case escapeds: Array[_] => format.fill(escapeds.view.map(_display_).toList)
case escapeds: java.util.List[_] =>
case escapeds: immutable.Seq[?] => format.fill(escapeds.map(_display_))
case escapeds: TraversableOnce[?] => format.fill(escapeds.map(_display_).toList)
case escapeds: Array[?] => format.fill(escapeds.view.map(_display_).toList)
case escapeds: java.util.List[?] =>
format.fill(JavaConverters.collectionAsScalaIterableConverter(escapeds).asScala.map(_display_).toList)
case string: String => format.escape(string)
case v if v != null => format.escape(v.toString)
Expand Down
2 changes: 1 addition & 1 deletion api/shared/src/main/scala/play/twirl/api/Content.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ abstract class BufferedContent[A <: BufferedContent[A]](

override def equals(obj: Any): Boolean =
obj match {
case other: BufferedContent[_] if this.getClass == other.getClass => body == other.body
case other: BufferedContent[?] if this.getClass == other.getClass => body == other.body
case _ => false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ object TwirlFeatureImports {
def using[T](t: T): T = t

/** Adds "truthiness" to iterables, making them false if they are empty. */
implicit def twirlIterableToBoolean(x: Iterable[_]): Boolean = x != null && !x.isEmpty
implicit def twirlIterableToBoolean(x: Iterable[?]): Boolean = x != null && !x.isEmpty

/** Adds "truthiness" to options, making them false if they are empty. */
implicit def twirlOptionToBoolean(x: Option[_]): Boolean = x != null && x.isDefined
implicit def twirlOptionToBoolean(x: Option[?]): Boolean = x != null && x.isDefined

/** Adds "truthiness" to strings, making them false if they are empty. */
implicit def twirlStringToBoolean(x: String): Boolean = x != null && !x.isEmpty
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class CompilerSpec extends AnyWordSpec with Matchers {
"compile successfully (existential)" in {
val helper = newCompilerHelper
val text = helper
.compile[(List[_] => Html)]("existential.scala.html", "html.existential")
.compile[(List[?] => Html)]("existential.scala.html", "html.existential")
.static(List(1, 2, 3))
.toString
.trim
Expand All @@ -157,7 +157,7 @@ class CompilerSpec extends AnyWordSpec with Matchers {
"compile successfully (var args existential)" in {
val helper = newCompilerHelper
val text = helper
.compile[(Array[List[_]] => Html)]("varArgsExistential.scala.html", "html.varArgsExistential")
.compile[(Array[List[?]] => Html)]("varArgsExistential.scala.html", "html.varArgsExistential")
.static(Array(List(1, 2, 3), List(4, 5, 6)))
.toString
.trim
Expand Down
8 changes: 4 additions & 4 deletions sbt-twirl/src/main/scala/play/twirl/sbt/SbtTwirl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ object SbtTwirl extends AutoPlugin {

override def trigger = noTrigger

override def projectSettings: Seq[Setting[_]] =
override def projectSettings: Seq[Setting[?]] =
inConfig(Compile)(twirlSettings) ++
inConfig(Test)(twirlSettings) ++
defaultSettings ++
positionSettings ++
dependencySettings

def twirlSettings: Seq[Setting[_]] =
def twirlSettings: Seq[Setting[?]] =
Seq(
compileTemplates / includeFilter := "*.scala.*",
compileTemplates / excludeFilter := HiddenFileFilter,
Expand All @@ -67,15 +67,15 @@ object SbtTwirl extends AutoPlugin {
managedSourceDirectories += (compileTemplates / target).value
)

def defaultSettings: Seq[Setting[_]] =
def defaultSettings: Seq[Setting[?]] =
Seq(
templateFormats := defaultFormats,
templateImports := TwirlCompiler.defaultImports(scalaVersion.value),
constructorAnnotations := Nil,
sourceEncoding := scalacEncoding(scalacOptions.value)
)

def positionSettings: Seq[Setting[_]] =
def positionSettings: Seq[Setting[?]] =
Seq(
sourcePositionMappers += TemplateProblem.positionMapper(Codec(sourceEncoding.value))
)
Expand Down

0 comments on commit ff7df61

Please sign in to comment.