dau_sama
dau_sama

Reputation: 4347

excluding folder from scalastyle sbt plugin

All the other questions I've found on this topic are quite old.

I am building a scala project with sbt and the scala-style plugin but I can't find a way to exclude a specific folder where I have some generated code.

Is there a way to force the plugin to not check that particular folder?

Right now I am editing the files manually and adding:

// scalastyle:off

on the top of the file, but this is quite annoying.

In the official website http://www.scalastyle.org/sbt.html I couldn't find any documentation, although it seems that it is actually possible to exclude paths/files from it.

https://github.com/scalastyle/scalastyle/blob/e19b54eacb6502b47b1f84d7b2a6b5d33f3993bc/src/main/scala/org/scalastyle/Main.scala#L51

so it seems that we can actually pass:

println(" -x, --excludedFiles STRING      regular expressions to exclude file paths (delimited by semicolons)")

In my build.sbt I call:

lazy val compileScalastyle = taskKey[Unit]("compileScalastyle")
compileScalastyle := org.scalastyle.sbt.ScalastylePlugin.scalastyle.in(Compile).toTask("").value
(compile in Compile) <<= (compile in Compile) dependsOn compileScalastyle

Is there a way to achieve that with the sbt plugin?

Upvotes: 2

Views: 1509

Answers (1)

insan-e
insan-e

Reputation: 3922

You could get all files/directories under "src/main/scala" and filter out your directory:

lazy val root = (project in file(".")).
  settings(
    (scalastyleSources in Compile) := {
      // all .scala files in "src/main/scala"
      val scalaSourceFiles = ((scalaSource in Compile).value ** "*.scala").get    
      val fSep = java.io.File.separator // "/" or "\"
      val dirNameToExclude = "com" + fSep + "folder_to_exclude" // "com/folder_to_exclude"
      scalaSourceFiles.filterNot(_.getAbsolutePath.contains(dirNameToExclude))
    }
  )

EDIT:
I've added a more "generic" solution where it checks the path of each file to exclude...

Upvotes: 5

Related Questions