Skip to content
N.S. Cutler edited this page Jul 14, 2017 · 13 revisions

Scalariform can be used as a stand-alone command-line utility.

Installation

You can download the executable JAR from the releases page

You can also build the executable jar yourself by running sbt "project cli" "assembly" and then retrieving the jar from cli/target/scala-{scalaMajorVersion}/cli-assembly-{version}.jar (rename to scalariform.jar)

To cross build the jar for all versions of scala in crossScalaVersions of build.sbt instead run the command `sbt "project cli" "+assembly"

Unix

Place scalariform.jar in a directory in your $PATH. For example, ~/bin/. Create a script called scalariform containing:

java -jar `dirname $0`/scalariform.jar "$@"

Then make it executable:

chmod u+x ~/bin/scalariform

Examples

Format a single file in place:

scalariform Foo.scala

Format all .scala files in a directory:

scalariform --recurse src/main/scala

Use Scalariform as a filter:

cat Foo.scala | scalariform --stdin

Use preferences from a properties file:

scalariform --preferenceFile=formatterPreferences.properties Foo.scala

Boolean preferences can be set to true with +preference, or to false with -preference; other preferences take an argument:

scalariform +spaceBeforeColon -alignParameters -indentSpaces=2 Foo.scala

Option summary

Usage: scalariform [options] [files...]

Options:
  --encoding=<encoding>                Set the encoding, e.g. UTF-8. If not set, defaults to the platform default encoding (currently UTF-8).
  --fileList=<path>, -l=<path>         Read the list of input file(s) from a text file (one per line)
  --forceOutput, -f                    If using --stdout, print the source unchanged if it cannot be parsed correctly.
  --help, -h                           Show help
  --preferenceFile=<path>, -p=<path>   Read preferences from a properties file
  --quiet, -q                          Work quietly
  --recurse, -r                        If any given file is a directory, recurse beneath it and collect all .scala files for processing
  --scalaVersion=<v>, -s=<v>           Assume the source is written against the given version of Scala (e.g. 2.9.2). Default is runtime version (currently 2.9.2).
  --stdin                              Read Scala source from standard input
  --stdout                             Write the formatted output to standard output
  --test, -t                           Check the input(s) to see if they are correctly formatted, return a non-zero error code if not.
  --version                            Show Scalariform version

Preferences:
  [+|-]alignArguments                                        Enable/disable Align arguments on different lines in the same column
  [+|-]alignParameters                                       Enable/disable Align parameters on different lines in the same column
  [+|-]alignSingleLineCaseStatements                         Enable/disable Align the arrows of consecutive single-line case statements
  [+|-]compactControlReadability                             Enable/disable Enable Compact Control Readability style
  [+|-]compactStringConcatenation                            Enable/disable Omit spaces when formatting a '+' operator on String literals
  [+|-]danglingCloseParenthesis                              Enable/disable placing a newline before a ')' in an argument expression
  [+|-]doubleIndentClassDeclaration                          (DEPRECATED) Enable/disable Double indent a class's inheritance list
  [+|-]doubleIndentConstructorArguments                      Enable/disable Double indent a class's parameter list
  [+|-]doubleIndentMethodDeclaration                         Enable/disable Double indent a method's parameters, if they span multiple lines
  [+|-]firstArgumentOnNewline                                Enable/disable Placement of the first argument to functions calls on a new line
  [+|-]firstParameterOnNewline                               Enable/disable Placement of the first parameter in function or class definitions on a new line
  [+|-]formatXml                                             Enable/disable Format XML literals
  [+|-]indentLocalDefs                                       Enable/disable Indent local defs an extra level
  [+|-]indentPackageBlocks                                   Enable/disable Indent package blocks
  [+|-]indentWithTabs                                        Enable/disable Use a tab character for indentation
  [+|-]multilineScaladocCommentsStartOnFirstLine             Enable/disable Start multiline Scaladoc comment body on same line as the opening '/**'
  [+|-]newlineAtEndOfFile                                    Enable/disable Add a newline at the end of all files
  [+|-]placeScaladocAsterisksBeneathSecondAsterisk           Enable/disable Place Scaladoc asterisks beneath the second asterisk in the opening '/**', as opposed to the first
  [+|-]preserveSpaceBeforeArguments                          Enable/disable Preserve a space before a parenthesis argument
  [+|-]rewriteArrowSymbols                                   Enable/disable Replace arrow tokens with unicode equivalents: => with ⇒, and <- with ←
  [+|-]spaceBeforeColon                                      Enable/disable Add a space before colons
  [+|-]spaceBeforeContextColon                               Enable/disable Add a space before colons in context bounds
  [+|-]spaceInsideBrackets                                   Enable/disable Require a space after '[' and before ']'
  [+|-]spaceInsideParentheses                                Enable/disable Require a space after '(' and before ')'
  [+|-]spacesAroundMultiImports                              Enable/disable Place spaces around multi imports (e.g. import a.{ b, c, d })
  [+|-]spacesWithinPatternBinders                            Enable/disable Add a space around the @ token in pattern binders
  -alignSingleLineCaseStatements.maxArrowIndent=[1-100]      Set Maximum number of spaces inserted before an arrow to align case statements
  -indentSpaces=[1-10]                                       Set Number of spaces to use for indentation

Examples:
 scalariform +spaceBeforeColon -alignParameters -indentSpaces=2 foo.scala
 scalariform +rewriteArrowSymbols --test --recurse .
 echo 'class A ( n  :Int )' | scalariform --stdin
Clone this wiki locally