excluding folder from scalastyle sbt plugin

痴心易碎 提交于 2019-12-11 06:26:11

问题


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 (delimitted 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?


回答1:


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...



来源:https://stackoverflow.com/questions/41508749/excluding-folder-from-scalastyle-sbt-plugin

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!