在教程https://scalacenter.github.io/scalafix/docs/developers/tutorial.html中,我看到了如何SemanticRule
为 scalafix 实现 a。我想直接在我从磁盘读取的 Scala 文件的源代码中调用它并转换文件。
在 scalameta 中,我可以执行以下操作:
val f = .... // some File
val path = f.toPath
val bytes = java.nio.file.Files.readAllBytes(path)
val text = new String(bytes, "UTF-8")
val input = Input.VirtualFile(path.toString, text)
val source = input.parse[Source].get
val transformer = new MyTransformer()
val transformedSource = transformer(source)
// The transformed source can be written into an output file
我想对 scalafix 做同样的事情,但使用SemanticRule
. 如果我读到这个:https :
//scalacenter.github.io/scalafix/docs/developers/tutorial.html#run-the-rule-from-source-code 它只向我展示了如何使用文件启动 scalafix 程序Scala 规则文件的路径,但这不是我想要的。