Questions tagged [scalafmt]

Questions about Scalafmt, a Scala Formatter

Scalafmt, a Scala Formatter - https://scalameta.org/scalafmt/

35 questions
8
votes
1 answer

How to configure IntelliJ to use short package names on "Optimize imports" for a scala codebase?

In a scala project where we are using IntelliJ community edition, we want to use multiple packages per file, so that we can reference them with shorter syntax: package com.dreamlines.dragonfly package api package domain package harbours import…
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
7
votes
2 answers

Using vs code, how to get scala format to work and format my code?

I have the scala format plugin in my multi project sbt repository. addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.3.2") So in the sbt console if I run scalafmt it works fine My build.sbt has: scalafmtOnCompile := true If I do a…
Blankman
  • 259,732
  • 324
  • 769
  • 1,199
6
votes
1 answer

How to create my own custom scalafmt style that my projects can depend on?

I have bunch of scala projects. They shall share a common code style. I am using scalafmt to enforce certain rules, yet I have to create a .scalafmt.conf for each project. If the team changes the scalafmt rules, we'd have to change it for each…
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
5
votes
0 answers

scalafmt configuration similar to IntelliJ ones

Is there a scalafmt config which is reformat code the same way like IntelliJ with scala plugin does now ? I have a problem with configuring it, and my team mates use IntelliJ only I VsCode and very often I need just open IntelliJ to reformat code…
FrancMo
  • 2,459
  • 2
  • 19
  • 39
4
votes
0 answers

Keep multiple parameters on one line in scalafmt

I want Scalafmt to accept this kind of formatting: val result = longMethodName( a, b, c, d) But currently it gets turned into: val result = longMethodName( a, b, c, d) When the parameters are short the first form is much more pleasing.…
Daniel Darabos
  • 26,991
  • 10
  • 102
  • 114
3
votes
1 answer

Reuse Scalafmt Config File Across Projects

I have a set of Scala projects and for all of those projects, I would like to introduce some scala source code formatting for which purpose, I'm using the scamafmt sbt pliugin. I have compiled the config file and this config file is in a separate…
joesan
  • 13,963
  • 27
  • 95
  • 232
3
votes
1 answer

Intellij has a problem with scalafmt and scala 3

my .scalafmt.conf file content is: version = 3.5.4 Intellij downloaded scalafmt for this version: but when I want to format file I have error saying literally nothing: IntelliJ Version: IntelliJ IDEA 2022.1.1 (Community Edition) Build…
FrancMo
  • 2,459
  • 2
  • 19
  • 39
3
votes
0 answers

is there a way to sort functions in a scala class/ object by their names using scalafmt?

I would like to sort the functions in the following objects alphabetically object A { def bfunc() = ??? def afunc() = ??? } would get sorted to object A { def afunc() = ??? def bfunc() = ??? } I tried to look through scala fmt docs, no…
Anil Muppalla
  • 416
  • 4
  • 14
3
votes
0 answers

Format code in VSCode automatically with Metals

I am using: Linux, VS Code, Dotty, Metals, SBT, scalafmt From the shell sbt scalaftm formats my files. From the editor I can do ctrl + shift + I, I get an error message: There is no formatter for 'scala' files installed. It allows me to install a…
Trylks
  • 1,458
  • 2
  • 18
  • 31
3
votes
0 answers

How to keep lambda parameter on the same line in scalafmt

By default scalafmt will reformat code like this myList(elem => elem .doThing .doOtherThing ) to look like this myList( elem => elem .doThing .doOtherThing ) How can it be configured to leave the anonymous function…
kag0
  • 5,624
  • 7
  • 34
  • 67
3
votes
0 answers

how to let scalafmt move multiple line string to new line

When there's multiple-line-string in a function call as parameter, my scalafmt will always put the start of it in the same line of previous codes, and the following string lines will have a long indent based on start position of string start. for…
K F
  • 645
  • 1
  • 6
  • 16
3
votes
1 answer

preserve existing code for arbitrary scalafmt settings

I'm trying to gently introduce scalafmt to a large existing codebase and I want it to make virtually no changes except for a handful of noncontroversial settings the whole team can agree on. With some settings like maxColumn I can override the…
codenoodle
  • 982
  • 6
  • 19
3
votes
1 answer

How to configure the alignToken for the cases in pattern matching syntax using scalafmt?

In scala using scalafmt and having the following content in my .scalafmt.conf file: style = default maxColumn = 120 continuationIndent.callSite = 2 continuationIndent.defnSite = 2 align.openParenDefnSite = false align.openParenCallSite =…
k0pernikus
  • 60,309
  • 67
  • 216
  • 347
2
votes
1 answer

Scalafmt: keep empty lines in a List

I want to keep a single empty line in the List definition using the scalafmt formatter: List( "some-random-string1" .trim .stripMargin, "some-random-string2" .intern .dropRight(3), "some-random-string3" .takeRight(4) …
2
votes
0 answers

Plugin sbt-scalafmt fails downloading scalafmt-core in Github Actions

Im experiencing some issues with scalafmt. My problem is that when running scalafmtCheck, it tries to download dynamically scalafmt core. I followed the documentation https://scalameta.org/scalafmt/docs/installation.html#sbt , and i put my sbt…
luisdue
  • 21
  • 1
1
2 3