Search code examples
scalascalametascalafixsemanticdb

Obtaining a SemanticDocument from a Scala source file using ScalaFix


What are the steps of parsing a Scala source file into a SemanticDocument using ScalaFix?


Solution

  • As of scalafix(0.9.4),

    To write a SemanticRule , one has to extend the abstract class SemanticRule and this abstract class has a method fix with the following signature:

    def fix(implicit doc: SemanticDocument): Patch
    

    If we override this method to create a Patch either for fixing or linting, we will have access to implicit value doc. Scalafix populates this variable by parsing a single source file. doc represents a single source file.