gpt4 book ai didi

scala - 如何使用标量自动格式化 sbt 构建文件?

转载 作者:行者123 更新时间:2023-12-04 02:05:16 26 4
gpt4 key购买 nike

我想用标量格式化我的 sbt 构建文件。启动 sbt 时是否可以在构建定义本身上运行 scalariform?

最佳答案

把这个放在 project/scalariform.sbt :

addSbtPlugin("com.typesafe.sbt" % "sbt-scalariform" % "1.2.0")

而这在 scalariform.sbt :
import scalariform.formatter.preferences._
import ScalariformKeys._

lazy val BuildConfig = config("build") extend Compile
lazy val BuildSbtConfig = config("buildsbt") extend Compile

val foo: Int => Int = {
case 1 => 1
case 2 => 2
}

noConfigScalariformSettings

inConfig(BuildConfig)(configScalariformSettings)

inConfig(BuildSbtConfig)(configScalariformSettings)

scalaSource in BuildConfig := baseDirectory.value / "project"

scalaSource in BuildSbtConfig := baseDirectory.value

includeFilter in (BuildConfig, format) := ("*.scala": FileFilter)

includeFilter in (BuildSbtConfig, format) := ("*.sbt": FileFilter)

format in BuildConfig := {
val x = (format in BuildSbtConfig).value
(format in BuildConfig).value
}

preferences := preferences.value.
setPreference(AlignSingleLineCaseStatements, true).
setPreference(AlignParameters, true)

运行:
helloworld> build:scalariformFormat
[info] Formatting 1 Scala source {file:/Users/eed3si9n/work/helloworld/}helloworld(buildsbt) ...
[info] Reformatted 1 Scala source {file:/Users/eed3si9n/work/helloworld/}helloworld(buildsbt).
[success] Total time: 1 s, completed Oct 5, 2013 2:58:45 PM

魔法!
val foo: Int => Int = {
case 1 => 1
case 2 => 2
}

关于scala - 如何使用标量自动格式化 sbt 构建文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19201509/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com