scalascalafmtscalafix

Scalafmt how to exclude files in some directories


Classes, generated by scalaPb plugin,

does't pass scalafmtCheck ans scalaFix stages.

How could I exclude files from some directories, for example, from target and build

I tried to exclude these directories in .scalafix.conf and .scalafmt.conf like so:

 triggered.excludeFilters = [
  ".*/target/.*",
  ".*/build/.*"
  ]

But receive an error:

  found option 'triggered' which wasn't expected, or isn't valid in this context.

Solution

  • From scalafmt - Configuration - Project

    Project

    project.include/exclude

    # Defaults
    project.includePaths = ["glob:**.scala", "glob:**.sbt", "glob:**.sc", "glob:**.mill"]
    project.excludePaths = []
    

    Allows specifying PathMatcher selection patterns to identify further which files are to be formatted (explicit glob: or regex: prefixes are required; keep in mind that PathMatcher patterns must match the entire path).

    Which means, your .scalafmt.conf file should have something like

    project.excludePaths = [
      "glob:**/target/**",
      "glob:**/build/**"
    ]
    

    From scalafix - docs - Exclude files from Scalafix

    By default, the scalafix task processes all files in a project. If you use Scala 2.x, the scalafix task also respects -P:semanticdb:exclude.

    Use Compile / scalafix / unmanagedSources to optionally exclude files from the scalafix task.

    Compile / scalafix / unmanagedSources :=
      (Compile / unmanagedSources).value
        .filterNot(file => file.getName == "Macros.scala")