neo-sbt-scalafmt icon indicating copy to clipboard operation
neo-sbt-scalafmt copied to clipboard

scalafmtOnCompile doesn't work for additional confifgurations

Open hseeberger opened this issue 7 years ago • 5 comments

I'm using the sbt-multi-jvm plugin which adds the MultiJvm configuration. I have added

inConfig(MultiJvm)(scalafmtSettings)

but sources under src/multi-jvm are not formatted on compile and also not when executing multi-ivm/scalafmt.

hseeberger avatar Jun 19 '17 09:06 hseeberger

Seeing something similar with the IntegrationTest configuration in vanilla SBT. However, it:scalafmt does work for me.

I have:

// ...
.settings(inConfig(IntegrationTest)(scalafmtSettings))
// ...

scalafmtOnCompile in ThisBuild := true

dvgica avatar Jun 20 '17 18:06 dvgica

I've got a multi-module project that has sub-projects that cross-build JVM and ScalaJS, and some that are just JVM. Reformat-on-compile and issuing scalafmt don't work on the ones that are JVM+ScalaJS. Is that related to this bug?

lloydmeta avatar Jul 06 '17 04:07 lloydmeta

I think the reason for this bug could be this line:

sourceDirectories := Seq(scalaSource.value)

The plugin should pick up all source directories if this is changed to sourceDirectories := unmanagedSourceDirectories.value. There has been a similar issue in the original scalafmt sbt plugin: https://github.com/scalameta/scalafmt/pull/229 which also contains more info about unmanagedSourceDirectories.

fthomas avatar Jul 11 '17 21:07 fthomas

This should probably be changed to use sources. Without examples, it's impossible to know if it will fix these, but I think it will be better.

pauldraper avatar Jul 11 '17 23:07 pauldraper

I think you should not touch sourceDirectories at all, i.e. delete the above mentioned line.

Then in lines 148 and 150 use unmanagedSourceDirectories.

hseeberger avatar Jul 12 '17 07:07 hseeberger