Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use newer version of scalafmt #1575

Open
nyoungstudios opened this issue May 10, 2024 · 0 comments
Open

use newer version of scalafmt #1575

nyoungstudios opened this issue May 10, 2024 · 0 comments

Comments

@nyoungstudios
Copy link

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, I noticed that it does not download the same version as specified in the .scalafmt.conf file. I noticed this because the rewrite.trailingCommas.style setting is not available; instead, it was looking for the setting located at trailingCommas. Instead, it downloads version 3.0.0 per this line of code:

"artifact": "org.scalameta:scalafmt-core_2.12:3.0.0",

I was able to override the version like this in my WORKSPACE file:

load("@io_bazel_rules_scala//scala/scalafmt:scalafmt_repositories.bzl", "scalafmt_default_config", "scalafmt_repositories")

scalafmt_default_config()

scalafmt_repositories(overriden_artifacts = {
    "org_scalameta_scalafmt_core": {
        "artifact": "org.scalameta:scalafmt-core_2.12:3.7.17",
        "sha256": "284bdc4da7969eca7910b0fc2c9c626a2acdc83c8f0be7709964dad4e3dbfeb9",
    },
})

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):

  • these .bzl files here.
  • this dependency list here.
  • this artifact ids list 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant