Skip to content
mdr edited this page Apr 29, 2013 · 10 revisions

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

Installation

You can download the executable JAR from here: scalariform.jar 0.1.4

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.jar

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:
  [+|-]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
  [+|-]doubleIndentClassDeclaration                          Enable/disable Double indent either a class's parameters or its inheritance list
  [+|-]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 '/**' 
  [+|-]placeScaladocAsterisksBeneathSecondAsterisk           Enable/disable Place Scaladoc asterisks beneath the second asterisk in the opening '/**', as opposed to the first
  [+|-]preserveDanglingCloseParenthesis                      Enable/disable Allow a newline before a ')' in an argument expression
  [+|-]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
  [+|-]spaceInsideBrackets                                   Enable/disable Require a space after '[' and before ']'
  [+|-]spaceInsideParentheses                                Enable/disable Require a space after '(' and before ')'
  [+|-]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