public interface ScalafixArguments
To obtain an instance of ScalafixArguments, use Scalafix.newArguments().
Instances of ScalafixArguments are immutable and thread safe. It is safe to re-use the same
ScalafixArguments instance for multiple Scalafix invocations. Re-using the same instance is
particularly encouraged when a custom toolClasspath is provided, in order to amortize the
cost/time of fetching artifacts, classloading them & warming up the JIT code cache.
| Modifier and Type | Method and Description |
|---|---|
java.util.List<ScalafixRule> |
availableRules()
The rules that are valid arguments for
withRules(List). |
ScalafixEvaluation |
evaluate()
Similar to
run(), but without any side effects on the source files. |
java.util.List<ScalafixRule> |
rulesThatWillRun()
The rules that would run when calling
run() |
ScalafixError[] |
run()
Run the Scalafix commmand-line interface
main function. |
java.util.Optional<ScalafixException> |
validate()
Validates that the passed arguments are valid.
|
ScalafixArguments |
withCharset(java.nio.charset.Charset charset) |
ScalafixArguments |
withClasspath(java.util.List<java.nio.file.Path> classpath) |
ScalafixArguments |
withConfig(java.util.Optional<java.nio.file.Path> config) |
ScalafixArguments |
withExcludedPaths(java.util.List<java.nio.file.PathMatcher> matchers) |
ScalafixArguments |
withMainCallback(ScalafixMainCallback callback) |
ScalafixArguments |
withMode(ScalafixMainMode mode) |
ScalafixArguments |
withParsedArguments(java.util.List<java.lang.String> args) |
ScalafixArguments |
withPaths(java.util.List<java.nio.file.Path> paths) |
ScalafixArguments |
withPrintStream(java.io.PrintStream out) |
ScalafixArguments |
withRules(java.util.List<java.lang.String> rules) |
ScalafixArguments |
withScalacOptions(java.util.List<java.lang.String> options) |
ScalafixArguments |
withScalaVersion(java.lang.String version) |
ScalafixArguments |
withSourceroot(java.nio.file.Path path) |
ScalafixArguments |
withToolClasspath(java.util.List<java.net.URL> customURLs) |
ScalafixArguments |
withToolClasspath(java.util.List<java.net.URL> customURLs,
java.util.List<java.lang.String> customDependenciesCoordinates) |
ScalafixArguments |
withToolClasspath(java.util.List<java.net.URL> customURLs,
java.util.List<java.lang.String> customDependenciesCoordinates,
java.util.List<coursierapi.Repository> repositories) |
ScalafixArguments |
withToolClasspath(java.net.URLClassLoader toolClasspath) |
ScalafixArguments |
withWorkingDirectory(java.nio.file.Path path) |
ScalafixArguments withRules(java.util.List<java.lang.String> rules)
rules - The rules passed via the --rules flag matching the syntax provided in
rules = [ "... " ] in .scalafix.conf files.ScalafixArguments withToolClasspath(java.util.List<java.net.URL> customURLs)
customURLs - Extra URLs for classloading and compiling external rules.ScalafixArguments withToolClasspath(java.util.List<java.net.URL> customURLs, java.util.List<java.lang.String> customDependenciesCoordinates) throws ScalafixException
customURLs - Extra URLs for classloading and compiling external rules.customDependenciesCoordinates - Extra dependencies for classloading and compiling external rules.
For example "com.nequissimus::sort-imports:0.5.2".
Artifacts will be resolved against the Scala version in the classloader
of the parent Scalafix instance and fetched using Coursier.ScalafixException - in case of errors during artifact resolution/fetching.ScalafixArguments withToolClasspath(java.util.List<java.net.URL> customURLs, java.util.List<java.lang.String> customDependenciesCoordinates, java.util.List<coursierapi.Repository> repositories) throws ScalafixException
customURLs - Extra URLs for classloading and compiling external rules.customDependenciesCoordinates - Extra dependencies for classloading and compiling external rules.
For example "com.nequissimus::sort-imports:0.5.2".
Artifacts will be resolved against the Scala version in the classloader
of the parent Scalafix instance and fetched using Coursier.repositories - Maven/Ivy repositories to fetch the artifacts from.ScalafixException - in case of errors during artifact resolution/fetching.ScalafixArguments withToolClasspath(java.net.URLClassLoader toolClasspath)
toolClasspath - Custom classpath for classloading and compiling external rules.
Must be a URLClassLoader (not regular ClassLoader) to support
compiling sources. This classloader must have as ancestor the
classloader of the Scalafix instance that returned this
ScalafixArguments instance. Unless you have an advanced
use-case, prefer the high-level overloads that cannot cause
runtime errors due to an invalid classloader hierarchy.ScalafixArguments withPaths(java.util.List<java.nio.file.Path> paths)
paths - Files and directories to run Scalafix on. The ability to pass in directories
is primarily supported to make it ergonomic to invoke the command-line interface.
It's recommended to only pass in files with this API. Directories are recursively
expanded for files matching the patterns *.scala and *.sbt
and files that do not match the path matchers provided in withExcludedPaths(List).ScalafixArguments withExcludedPaths(java.util.List<java.nio.file.PathMatcher> matchers)
matchers - Optional list of path matchers to exclude files when expanding directories
in withPaths(List).ScalafixArguments withWorkingDirectory(java.nio.file.Path path)
path - The working directory of where to invoke the command-line interface.
Primarily used to absolutize relative directories passed via
withPaths(List) and also to auto-detect the
location of .scalafix.conf.ScalafixArguments withConfig(java.util.Optional<java.nio.file.Path> config)
config - Optional path to a .scalafix.conf. If empty, Scalafix
will infer such a file from the working directory or fallback to the default
configuration.ScalafixArguments withMode(ScalafixMainMode mode)
mode - The mode to run via --check or --stdout or --auto-suppress-linter-errorsScalafixArguments withParsedArguments(java.util.List<java.lang.String> args) throws ScalafixException
args - Unparsed command-line arguments that are fed directly to main(Array[String])ScalafixException - In case of an error parsing the provided arguments.ScalafixArguments withPrintStream(java.io.PrintStream out)
out - The output stream to use for reporting diagnostics while running Scalafix.
Defaults to System.out.ScalafixArguments withClasspath(java.util.List<java.nio.file.Path> classpath)
classpath - Full Java classpath of the module being fixed. Required for running
semantic rewrites such as ExpliticResultTypes. Source files that
are to be fixed must be compiled with the semanticdb-scalac compiler
plugin and must have corresponding META-INF/semanticdb/../*.semanticdb
payloads. The dependency classpath must be included as well but dependency
sources do not have to be compiled with semanticdb-scalac.ScalafixArguments withSourceroot(java.nio.file.Path path)
path - The SemanticDB sources path passed via --sourceroot. Must match path
in -Xplugin:semanticdb:sourceroot:{path} if used. Defaults
to the current working directory.ScalafixArguments withMainCallback(ScalafixMainCallback callback)
callback - Handler for reported linter messages. If not provided, defaults to printing
linter messages to the Stdout.ScalafixArguments withCharset(java.nio.charset.Charset charset)
charset - Charset for reading source files from disk. Defaults to UTF-8.ScalafixArguments withScalaVersion(java.lang.String version)
version - The Scala compiler version used to compile this classpath.
For example "2.12.8". To be able to run advanced semantic rules
using the Scala Presentation Compiler (such as ExplicitResultTypes),
this must match the binary version available in the classloader of
this instance, as requested/provided in the static factory methods
of Scalafix.ScalafixArguments withScalacOptions(java.util.List<java.lang.String> options)
options - The Scala compiler flags used to compile this classpath.
For example List(-Ywarn-unused-import).java.util.List<ScalafixRule> availableRules()
withRules(List).
Takes into account built-in rules as well as the tool classpath provided via
withToolClasspath(URLClassLoader).
java.util.List<ScalafixRule> rulesThatWillRun() throws ScalafixException
run()
Takes into account rules that are configured in .scalafix.conf.
ScalafixException - In case of an error loading the configured rules.java.util.Optional<ScalafixException> validate()
Takes into account provided rules, .scalafix.conf configuration, scala version,
scalac options and other potential problems. The primary purpose
of this method is to validate the arguments before starting compilation
to populate withClasspath(List).
ScalafixError[] run()
main function.ScalafixEvaluation evaluate()
run(), but without any side effects on the source files. Via the returned ScalafixEvaluation,
for each file, diagnostics can be inspected, and patches can be previewed and applied.
Incompatible with withMainCallback(scalafix.interfaces.ScalafixMainCallback) and withMode(scalafix.interfaces.ScalafixMainMode).