Disable scalafmt `if then` single line formatting

when I type

if 2 + 2 == 4 then
  print("Success")

metals formats this to

if 2 + 2 == 4 then print("Success")

I need to turn this rule off, while still preserving other rules like indentation correction. How can I?

Bonus question: Is there a way for me to turn off all rules, and then manually specify which ones I want; like a whitelist instead of a blacklist? Thanks.

1 Like

Hmm. How are you using scalafmt? It’s basically 100% configurable, so this question is confusing me a bit. You’re in charge of the rules for your repo, via the config file.

My point is it looks like there are hundreds of rules and I don’t want to spend hours reading through documentation trying to find specific rules or trying to understand each one of them. I want to turn all of them by default, and then only enable the ones I care about (like automatic indentation). I only have a few basic things I want scalafmt to do, and let me decide style on the rest.

I still have not found which rule causes

for i <- 1 to 100 do
  println(i)

to turn into

for i <- 1 to 100 do println(i)

and it’s not negotiable. I will have to turn off scalafmt entirely if turning this off is not possible.

Here is my .scalafmt.conf

version = "3.7.15"
runner.dialect = scala3
indent.main = 2
indent.callSite = 2

You may want to try newlines.source=keep which is generally a conservative option towards your bigger point (don’t mess with my code unless I ask).

2 Likes