sbt / sbt-scalariform

sbt plugin adding support for source code formatting using Scalariform
258 stars 63 forks source link

Use unmanagedSourceDirectories for sourceDirectories #43

Closed fthomas closed 7 years ago

fthomas commented 8 years ago

sourceDirectories in scalariformFormat is currently initialized with List(scalaSource.value) which means that sbt-scalariform only looks into one source directory per project. But a typical Scala.js cross project has at least two source directories: js/ and shared/ or jvm/ and shared/. In other projects there are multiple source directories for different Scala versions.

This change initializes sourceDirectories in scalariformFormat with unmanagedSourceDirectories which contains all source directories with manually created sources. This setting always includes scalaSource because sbt defines it as:

unmanagedSourceDirectories := makeCrossSources(
  scalaSource.value,
  javaSource.value,
  scalaBinaryVersion.value,
  crossPaths.value)

Here are for example both settings for typelevel/cats:

coreJVM/scalaSource [info] cats/core/.jvm/src/main/scala

coreJVM/unmanagedSourceDirectories [info] List( cats/core/.jvm/src/main/scala-2.11, cats/core/.jvm/src/main/scala, cats/core/.jvm/src/main/java, cats/core/src/main/scala)

And since cats has no sources in cats/core/.jvm/src/main/scala (all sources are in cats/core/src/main/scala), sbt-scalariform won't format anything.

This change has been tested successfully with one of my projects and allowed to get rid of this workaround to pick up all relevant source directories.

fthomas commented 8 years ago

It seems that https://github.com/sbt/sbt-scalariform/issues/32#issuecomment-175375785 also suggests to use unmanagedSourceDirectories instead of scalaSource.

godenji commented 7 years ago

@fthomas looks like you moved on to scalafmt.

Since Scalariform has been updated to 0.2.0 it makes sense to publish a new release for Sbt-Scalariform as well. Did you encounter any problems after submitting this PR, or were things stable wrt to addressing the scala/scala.js issue?

fthomas commented 7 years ago

As far as I remember there where no problems. I did a similar change in the old scalafmt sbt plugin and it didn't caused any trouble there: https://github.com/scalameta/scalafmt/pull/229