scalameta / sbt-scalafmt

sbt plugin for Scalafmt

Home Page:https://scalameta.org/scalafmt/

Repository from Github https://github.comscalameta/sbt-scalafmtRepository from Github https://github.comscalameta/sbt-scalafmt

Plugin doesn't check/format a sources for scripted tests

ihostage opened this issue · comments

If I'm writing a scripted tests for my SBT plugin, I can't to check a format the files in the default sbt-test directory. And includePaths configuration can't help me also.

I am wondering why in the sbt-scalafmt project a sbt-test folder is excluded:

project.excludeFilters = [
plugin/src/sbt-test
]

This would indicate IMHO that this sbt-test folder would otherwise included in the formatting process if it wouldn't be excluded.
Or am I wrong?

So, this is were the sources are defined which get formatted:

val sources = (unmanagedSources in scalafmt).?.value.getOrElse(Seq.empty)
val dirs = (unmanagedSourceDirectories in scalafmt).?.value.getOrElse(Nil)

Looks like sbt-test folders are not part of unmanagedSources in scalafmt / unmanagedSourceDirectories in scalafmt.

Maybe we could make use of sf:

project.includeFilters = [
  plugin/src/sbt-test
]

however looking at how ScalafmtPlugin works I think that settings might not even get taken into account when using sbt-scalafmt?

@mkurz as you correctly surmised, this plugin only processes files used by sbt during build.

Would be nice to have some config to add additional files/folders which should get formatted.

@mkurz @ihostage have you tried defining a project within your build, pointing to this standalone directory, thus setting source files/dirs for it?

sbt-scalafmt doesn't format stuff that doesn't belong to any project, as formatting happens within the scope of a project. so it seems that you simply need to create a project and put them under it.

Sorry, @kitbellew, but I don't understand what you mean. We already have a project (for example https://github.com/sbt/sbt-maven-plugin) and sbt-test folder (default for scripted tests) is a part of this project. Yes, sbt-test isn't a *Sources folder as @mkurz pointed above, but I think definition another one fictive project only for formatting is inconvenient 😞 Moreover I will need disable compilation/publishing/etc for this project and it's looks very strange for me 🤷‍♂️

i was simply asking if you tried it and if that worked. if that's inconvenient, then perhaps you -- as sbt plugin experts -- can help fix this problem here. i don't fully understand sbt scopes, projects etc, and others haven't looked at it for a while.