I setup scalafmt with my bazel project successfully following the instructions in this repo and some other examples on GitHub. Here is a minimal example .scalafmt.conf file I was using.
# .scalafmt.conf
# https://scalameta.org/scalafmt/docs/configuration.html
maxColumn = 100
version = 3.7.17
runner.dialect = scala212
# this doesn't work
rewrite.trailingCommas.style = always
# this works
# trailingCommas = always
However, after overriding this artifact, I still got this error.
external/io_bazel_rules_scala/scala/scalafmt/scalafmt/ScalafmtWorker.scala:8: error: object FileOps is not a member of package org.scalafmt.util
import org.scalafmt.util.FileOps
^
external/io_bazel_rules_scala/scala/scalafmt/scalafmt/ScalafmtWorker.scala:21: error: not found: value FileOps
val source = FileOps.readFile(namespace.getOrElse("input", new File("")))(Codec.UTF8)
^
external/io_bazel_rules_scala/scala/scalafmt/scalafmt/ScalafmtWorker.scala:23: error: value fromHoconFile is not a member of object org.scalafmt.config.Config
val config = Config.fromHoconFile(namespace.getOrElse("config", new File(""))).get
Looking at that file in the scalafmt repo, you can see that they moved the FileOps object from the scalafmt-core to the scalafmt-sysops package; thus, it is published as a separate Maven package.
I couldn't figure out how to also include that package when running the formatter, but I imagine it is probably better to support it by adding it here.
I imagine the package would need to be added in a handful of spots including (I'm probably missing some spots):
I setup scalafmt with my bazel project successfully following the instructions in this repo and some other examples on GitHub. Here is a minimal example
.scalafmt.conf
file I was using.However, I noticed that it does not download the same version as specified in the
.scalafmt.conf
file. I noticed this because therewrite.trailingCommas.style
setting is not available; instead, it was looking for the setting located attrailingCommas
. Instead, it downloads version 3.0.0 per this line of code: https://github.com/bazelbuild/rules_scala/blob/98689d0bb1cbe2e684b95d44dd9962fa54aef5fa/third_party/repositories/scala_2_12.bzl#L123I was able to override the version like this in my
WORKSPACE
file:However, after overriding this artifact, I still got this error.
Looking at that file in the scalafmt repo, you can see that they moved the
FileOps
object from thescalafmt-core
to thescalafmt-sysops
package; thus, it is published as a separate Maven package.I couldn't figure out how to also include that package when running the formatter, but I imagine it is probably better to support it by adding it here.
I imagine the package would need to be added in a handful of spots including (I'm probably missing some spots):
.bzl
files here.Aside from those updates, I think it would be cool for this automatically download the correct version. But I imagine that would be more complicated.