从 scalastyle sbt 插件中排除文件夹 [英] excluding folder from scalastyle sbt plugin
问题描述
我在这个主题上发现的所有其他问题都很老了.
All the other questions I've found on this topic are quite old.
我正在使用 sbt
和 scala-style
插件构建一个 Scala 项目,但我找不到排除特定文件夹的方法,其中我有一些生成的代码.
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.
在官网http://www.scalastyle.org/sbt.html我找不到任何文档,尽管似乎实际上可以从中排除路径/文件.
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.
所以看起来我们实际上可以通过:
so it seems that we can actually pass:
println(" -x, --excludedFiles STRING regular expressions to exclude file paths (delimited by semicolons)")
在我的 build.sbt
中,我调用:
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
有没有办法用 sbt 插件
实现这一点?
Is there a way to achieve that with the sbt plugin
?
推荐答案
您可以获取src/main/scala"下的所有文件/目录并过滤掉您的目录:
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...
这篇关于从 scalastyle sbt 插件中排除文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!