-
Notifications
You must be signed in to change notification settings - Fork 278
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ScalafmtRunner: extract Dialect as NamedDialect
- Loading branch information
Showing
7 changed files
with
64 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
scalafmt-core/shared/src/main/scala/org/scalafmt/config/NamedDialect.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.scalafmt.config | ||
|
||
import scala.meta.Dialect | ||
import scala.meta.dialects._ | ||
|
||
case class NamedDialect(name: String, dialect: Dialect) | ||
|
||
object NamedDialect { | ||
|
||
def apply(pair: sourcecode.Text[Dialect]): NamedDialect = { | ||
apply(pair.source.toLowerCase, pair.value) | ||
} | ||
|
||
val scala212 = Scala212 | ||
.withAllowTrailingCommas(true) // SIP-27, 2.12.2 | ||
val scala213 = Scala213 | ||
.withAllowTrailingCommas(true) | ||
val scala3 = Scala3 | ||
|
||
private[config] val known = Seq[sourcecode.Text[Dialect]]( | ||
Scala211, | ||
scala212, | ||
Scala212Source3, | ||
scala213, | ||
Scala213Source3, | ||
Sbt0137, | ||
Sbt1, | ||
scala3 | ||
).map(apply).sortBy(_.name) | ||
|
||
private[config] val defaultName = "default" | ||
// current default is 213 | ||
private[config] val default = apply(defaultName, scala213) | ||
|
||
def getName(dialect: Dialect): Option[String] = | ||
known.find(_.dialect eq dialect).map(_.name) | ||
|
||
def getUnknownError = { | ||
val knownStr = known.map(_.name).mkString(",") | ||
s"""Default dialect is deprecated; use explicit: [$knownStr] | ||
|Also see https://scalameta.org/scalafmt/docs/configuration.html#scala-dialects" | ||
|""".stripMargin | ||
} | ||
|
||
implicit val codec = | ||
ReaderUtil.oneOf(known.map(x => sourcecode.Text(x, x.name)): _*) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters