gpt4 book ai didi

sbt - 如何在项目中自动运行 scalafmt?

转载 作者:行者123 更新时间:2023-12-01 06:13:35 39 4
gpt4 key购买 nike

我使用 scalafmt我项目中的插件,我也使用 scalafmt plugin for Intellj为了格式化我的 Scala 代码。通常我使用热键或运行 sbt scalafmt 来格式化。

sbt.version=1.0.3
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.3.0")

问题:任何建议如何在编译时自动使用 scalafmt 格式化代码?

最佳答案

更新:只需更新插件版本并使用

scalafmtOnCompile := true

下面的答案已经过时了,它建议使用替代插件,但现在是另一种方式,官方是最新的并且开箱即用地支持此功能。

来自 scalafmt installation instructions对于您使用的插件:

The sbt plugin does not provide reformat on compile settings. This gist shows a DIY plugin to enable reformat on compile. YMMV.

Why isn't that gist included in the sbt plugin? See #597.

我推荐你试试neo-sbt-scalafmt反而。它通常更具可配置性和更好的维护(放弃了其他插件,请参阅上面链接的问题)。使用此插件,您可以使用简单的方式打开编译格式

scalafmtOnCompile := true

docs更多选择。

关于sbt - 如何在项目中自动运行 scalafmt?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47127351/

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