Skip to content

Commit

Permalink
ScalafmtConfig: use Sbt dialect for .sbt files
Browse files Browse the repository at this point in the history
Apply this default unless another dialect, different from the primary
one, was explicitly specified through `fileOverride`.
  • Loading branch information
kitbellew committed Feb 23, 2024
1 parent 5262eb1 commit 8bb934c
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import java.nio.file.Path

import metaconfig.Configured
import scala.meta.Input
import scala.meta.dialects
import scala.meta.parsers.ParseException
import scala.util.Failure
import scala.util.Success
Expand All @@ -12,6 +13,7 @@ import scala.util.Try
import org.scalafmt.Error.PreciseIncomplete
import org.scalafmt.config.FormatEvent.CreateFormatOps
import org.scalafmt.config.LineEndings
import org.scalafmt.config.NamedDialect
import org.scalafmt.config.ScalafmtConfig
import org.scalafmt.internal.BestFirstSearch
import org.scalafmt.internal.FormatOps
Expand Down Expand Up @@ -65,7 +67,11 @@ object Scalafmt {
): Formatted.Result = {
def getStyleByFile(style: ScalafmtConfig) = {
val isSbt = FileOps.isSbt(filename)
if (isSbt) style.forSbt else style
if (isSbt) {
val sbtStyle = style.forSbt
if (sbtStyle.dialect ne baseStyle.dialect) sbtStyle
else sbtStyle.withDialect(NamedDialect(dialects.Sbt))
} else style
}
val styleTry =
if (filename == defaultFilename) Success(baseStyle)
Expand Down
3 changes: 2 additions & 1 deletion scalafmt-tests/src/test/resources/scala3/Issues.stat
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,6 @@ lazy val versions = new {
val cats = "2.10.0"
}
>>> build.sbt
lazy val versions = new:
lazy val versions = new {
val cats = "2.10.0"
}

0 comments on commit 8bb934c

Please sign in to comment.