scalafix-cli
The recommended way to install the scalafix command-line interface is with coursier.
// coursier
coursier bootstrap ch.epfl.scala:scalafix-cli_@:0.5.2 -f --main scalafix.cli.Cli -o scalafix
./scalafix --help
// homebrew
brew install --HEAD olafurpg/scalafmt/scalafix
scalafix --help
// wget
wget -O scalafix https://github.com/scalacenter/scalafix/blob/master/scalafix?raw=true
./scalafix --help
Once the scalafix cli is installed, consult the –help page for further usage instructions.
scalafix 0.5.2-62-95d69c47-20171010-1852
Usage: scalafix [options] [<file>...]
--usage
Print usage and exit
--help | -h
Print help message and exit
--version | -v
Print version number and exit
--verbose
If set, print out debugging inforation to stderr.
--config | -c <.scalafix.conf>
File path to a .scalafix.conf configuration file.
--config-str | -c <imports.organize=false>
String representing scalafix configuration
--sourceroot </foo/myproject>
Absolute path passed to semanticdb with
-P:semanticdb:sourceroot:<path>. Relative filenames persisted in the
Semantic DB are absolutized by the sourceroot. Defaults to current
working directory if not provided.
--classpath <entry1.jar:entry2.jar:target/scala-2.12/classes>
java.io.File.pathSeparator separated list of directories or jars
containing '.semanticdb' files. The 'semanticdb' files are emitted by
the semanticdb-scalac compiler plugin and are necessary for semantic
rules like ExplicitResultTypes to function.
--classpath-auto-roots <target:project/target>
Automatically infer --classpath starting from these directories.
Ignored if --classpath is provided.
--no-strict-semanticdb
Disable validation when loading semanticdb files.
--rules | -r <ProcedureSyntax OR file:LocalFile.scala OR scala:full.Name OR https://gist.com/.../Rule.scala>
Scalafix rules to run.
--stdout
If set, print fix to stdout instead of writing to file.
--test
Exit non-zero code if files have not been fixed. Won't write to files.
--out-from </shared/>
Regex that is passed as first argument to
fileToFix.replaceAll(outFrom, outTo)
--out-to </custom/>
Replacement string that is passed as second argument to
fileToFix.replaceAll(outFrom, outTo)
--exclude <core Foobar.scala>
Space separated list of regexes to exclude which files to fix. If a
file match one of the exclude regexes, then it will not get fixed.
Defaults to excluding no files.
--single-thread
If true, run on single thread. If false (default), use all available
cores
--no-sys-exit
If true, does not sys.exit at the end. Useful for example in
sbt-scalafix
--quiet-parse-errors
Don't report parse errors for non-explictly passed filepaths.
--bash
Print out bash completion file for scalafix. To install on scalafix
--bash > /usr/local/etc/bash_completion.d/scalafix # Mac scalafix
--bash > /etc/bash_completion.d/scalafix # Linux
--zsh
Print out zsh completion file for scalafix. To install: scalafix --zsh
> /usr/local/share/zsh/site-functions/_scalafix
--non-interactive
Don't use fancy progress bar.
--project-id <value>
String ID to prefix reported messages with
Available rules: DottyKeywords, NoValInForComprehension, RemoveXmlLiterals, VolatileLazyVal, ProcedureSyntax, ExplicitUnit, DottyVolatileLazyVal, DottyVarArgPattern, NoInfer, Sbt1, ExplicitResultTypes, ExplicitReturnTypes, RemoveUnusedImports, RemoveUnusedTerms, NoAutoTupling, Disable
NOTE. The command line tool is mostly intended to be invoked programmatically
from build-tool integrations such as sbt-scalafix. The necessary fixture to run
semantic rules is tricky to setup manually.
Scalafix chooses which files to fix according to the following rules:
- scalafix <directory> <rule> finds *.scala files in <directory>
- when <rule> is semantic
- if --classpath and --sourceroot are provided, then those are used to find .semanticdb files
- otherwise, Scalafix will automatically look for META-INF/semanticdb directories from the
current working directory.
Examples (semantic):
$ scalafix # automatically finds .semanticdb files and runs rule configured in .scalafix.conf.
$ scalafix <directory> # same as above except only run on files in <directory>
$ scalafix --rules RemoveUnusedImports # same as above but run RemoveUnusedImports.
$ scalafix --classpath <foo.jar:target/classes> # explicitly pass classpath, --sourceroot is cwd.
$ scalafix --classpath <foo.jar:target/classes> --sourceroot <directory>
$ cat .scalafix.conf
rules = [ProcedureSyntax]
$ scalafix Code.scala # Same as --rules ProcedureSyntax
Exit status codes:
Ok=0
UnexpectedError=1
ParseError=2
ScalafixError=4
InvalidCommandLineOption=8
MissingSemanticApi=16
StaleSemanticDB=32
TestFailed=64
LinterError=128