Skip to content

Commit

Permalink
Merge branch 'master' into multiple-parameters-list
Browse files Browse the repository at this point in the history
Conflicts:
	scalariform/src/main/scala/scalariform/formatter/ExprFormatter.scala
	scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala
  • Loading branch information
bambuchaAdm committed Mar 12, 2014
2 parents 443ebf3 + d848e9f commit 3383e5a
Show file tree
Hide file tree
Showing 32 changed files with 2,094 additions and 1,002 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ docs/build
nohup.out
.history
.cache
.idea/
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: scala
scala:
- 2.10.3
- 2.9.3
jdk:
- oraclejdk7
- openjdk7
161 changes: 117 additions & 44 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Scalariform
===========

.. image:: https://travis-ci.org/daniel-trinh/scalariform.png?branch=master
:target: https://travis-ci.org/daniel-trinh/scalariform

Scalariform is a code formatter for Scala. It's available as a
library, a stand-alone command line tool, or via integrations with
various editors and build tools (listed below).
Expand All @@ -14,6 +17,13 @@ Scalariform is licenced under `The MIT Licence`_.
.. _Scala Style Guide: http://davetron5000.github.com/scala-style/
.. _The MIT Licence: http://www.opensource.org/licenses/mit-license.php

Integration with sbt
--------------------

A version for sbt >= 0.13.x has been written by Peter Vlugter: https://github.com/daniel-trinh/sbt-scalariform

Please see https://github.com/sbt/sbt-scalariform for older versions of sbt.

Integration with Eclipse
------------------------

Expand All @@ -22,7 +32,7 @@ Scala IDE for Eclipse uses Scalariform for code formatting:
- Right click in the editor -> Source -> Format
- Press Ctrl-Shift-F

If you select some lines, only those will be formatted.
If you select some lines, only those will be formatted.

You can also configure formatting to be run as a save action (Window -> Preferences -> Java -> Editor -> Save Actions).

Expand All @@ -31,7 +41,7 @@ To set preferences, go to Window -> Preferences -> Scala -> Formatter
Integration with Emacs/ENSIME
-----------------------------

"`ENSIME`_ uses the Scalariform library to format Scala sources. Type C-c C-v f to format the current buffer."
"`ENSIME`_ uses the Scalariform library to format Scala sources. Type C-c C-v f to format the current buffer."

http://aemon.com/file_dump/ensime_manual.html#tth_sEc4.8

Expand Down Expand Up @@ -73,16 +83,6 @@ Usage::
</executions>
</plugin>

Integration with sbt
--------------------

`sbt-scalariform`_, written by Olivier Michallat, provides an sbt plugin contributing formatting actions for sbt 0.7.x.

A version for sbt 0.10.x has been written by Peter Vlugter: https://github.com/typesafehub/sbt-scalariform

.. _sbt-scalariform: http://github.com/olim7t/sbt-scalariform


Integration with TextMate
-------------------------

Expand Down Expand Up @@ -123,26 +123,72 @@ alignParameters

Default: ``false``

Align class/function parameters in the same column. For example, if ``false``, then::
Align class/function parameters (modifiers and name, type, and defaults) in three columns.

For example, if ``false``, then::

class Person(name: String,
age: Int,
age: Int = 24,
birthdate: Date,
astrologicalSign: String,
astrologicalSign: String = "libra",
shoeSize: Int,
favoriteColor: java.awt.Color)

If ``true``, then::

class Person(name: String,
age: Int,
birthdate: Date,
astrologicalSign: String,
shoeSize: Int,
favoriteColor: java.awt.Color)
class Person(name: String,
age: Int = 24,
birthdate: Date,
astrologicalSign: String = "libra",
shoeSize: Int,
favoriteColor: java.awt.Color)

This will also place the "implicit" keyword in parameters on it's own line, whenever
the parameter being formatted contains a newline::

For example, if ``false``, then::

def formatBirthDate(
implicit birthdate: Date = Date("11/11/11"),
birthtime: Time): DateTime

If ``true``, then::

def formatBirthDate(
implicit
birthdate: Date = Date("11/11/11"),
birthtime: Time): DateTime

This option is disabled if ``indentWithTabs`` is ``true``.


alignArguments
~~~~~~~~~~~~~~

Default: ``false``

Aligns mult-line arguments

For example, if ``false``, then::

Cake(candles = 10,
frostingFlavor = Vanilla,
layerFlavor = Chocolate,
icecream = true
)

If ``true``, then::

Cake(
candles = 10,
frostingFlavor = Vanilla,
layerFlavor = Chocolate,
icecream = true
)

This option is disabled if ``indentWithTabs`` is ``true``.


alignSingleLineCaseStatements
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand Down Expand Up @@ -204,7 +250,7 @@ using `Compact Control Readability`_ style:

try {
foo()
}
}
catch {
case _ => bar()
}
Expand Down Expand Up @@ -319,7 +365,7 @@ indentSpaces

Default: ``2``

The number of spaces to use for each level of indentation.
The number of spaces to use for each level of indentation.

This option is ignored if ``indentWithTabs`` is ``true``.

Expand All @@ -330,7 +376,7 @@ Default: ``false``

Use a tab for each level of indentation. When set to ``true``, this
ignores any setting given for ``indentSpaces``. In addition, for the
moment, ``alignSingleLineCaseStatements`` and ``alignParameters``
moment, ``alignSingleLineCaseStatements``, ``alignArguments``, and ``alignParameters``
options are not supported when indenting with tabs, and XML
indentation is handled differently.

Expand All @@ -341,14 +387,14 @@ Default: ``false``

If ``true``, start a multi-line Scaladoc comment body on same line as the opening comment delimiter::

/** This method applies f to each
/** This method applies f to each
* element of the given list.
*/

If ``false``, start the comment body on a separate line below the opening delimiter::

/**
* This method applies f to each
/**
* This method applies f to each
* element of the given list.
*/

Expand All @@ -358,7 +404,7 @@ preserveDanglingCloseParenthesis
Default: ``false``

If ``true``, it will keep a newline before a close parenthesis ')' in an
argument expression. For example::
argument expression or parameter clause. For example::

val book = Book(
name = "Name",
Expand All @@ -373,6 +419,21 @@ If ``false``, the parenthesis will be joined to the end of the argument list::
author = "Author",
rating = 5)


Or with parameters, if ``true``::

def findBooks(
author: Option[String] = None,
title: Option[String] = None
): List[Book]

If ``false``::

def findBooks(
author: Option[String] = None,
title: Option[String] = None): List[Book]


placeScaladocAsterisksBeneathSecondAsterisk
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Expand All @@ -381,14 +442,14 @@ Default: ``false``
If ``true``, Scaladoc asterisks will be placed beneath the second asterisk::

/** Wibble
* wobble
* wobble
*/
class A

Otherwise, if ``false``, beneath the first asterisk::

/** Wibble
* wobble
* wobble
*/
class A

Expand Down Expand Up @@ -474,6 +535,18 @@ If ``false``,::

case elem@Multi(values@_*) =>

spacesAroundMultiImports
~~~~~~~~~~~~~~~~~~~~~~~~

Default: ``true``

Whether or not to add spaces around mutli-imports. For example, If ``true``, then::

import a.{ b, c, d }

If ``false``, then::

import a.{b,c,d}

Scala Style Guide
~~~~~~~~~~~~~~~~~
Expand All @@ -487,14 +560,14 @@ make uncompliant source more compliant.
============================ ========= =========
Preference Value Default?
============================ ========= =========
alignParameters ``false``
compactStringConcatenation ``false``
alignParameters ``false``
compactStringConcatenation ``false``
doubleIndentClassDeclaration ``true`` No
indentSpaces ``2``
indentSpaces ``2``
placeScaladocAsterisksBeneathSecondAsterisk ``true`` No
preserveSpaceBeforeArguments ``false``
rewriteArrowSymbols ``false``
spaceBeforeColon ``false``
preserveSpaceBeforeArguments ``false``
rewriteArrowSymbols ``false``
spaceBeforeColon ``false``
spaceInsideBrackets ``false``
spaceInsideParentheses ``false``
============================ ========= =========
Expand All @@ -510,24 +583,24 @@ format: [ON|OFF]
Disables the formatter for selective portions of a source file::

// format: OFF <-- this directive disables formatting from this point
class AsciiDSL {
class AsciiDSL {
n ¦- "1" -+ { n: Node =>
n ¦- "i"
n ¦- "ii"
n ¦- "iii"
n ¦- "iv"
n ¦- "i"
n ¦- "ii"
n ¦- "iii"
n ¦- "iv"
n ¦- "v"
}
n ¦- "2"
n ¦- "3" -+ { n: Node =>
n ¦- "i"
n ¦- "i"
n ¦- "ii" -+ { n: Node =>
n ¦- "a"
n ¦- "b"
n ¦- "c"
}
n ¦- "iii"
n ¦- "iv"
n ¦- "iii"
n ¦- "iv"
n ¦- "v"
}
// format: ON <-- formatter resumes from this point
Expand Down
2 changes: 1 addition & 1 deletion cli/src/main/scala/scalariform/commandline/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import scalariform.ScalaVersions
object Main {

def main(args: Array[String]) {
exit(if (process(args)) 1 else 0)
sys.exit(if (process(args)) 1 else 0)
}

def process(args: Array[String]): Boolean = {
Expand Down
11 changes: 6 additions & 5 deletions misc/src/main/scala/scalariform/corpusscan/CorpusScanner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,15 @@ object CorpusScanner extends SpecificFormatter {

}

object Runner extends App {
object Runner {

val corpusDir = "/home/matthew/coding/scala-corpus/repos2"
// val corpusDir = "/home/matt/scala-corpus"

def main(args: Array[String]) {
formatInPlace()
}

def checkParser() {
val files = ScalaFileWalker.findScalaFiles(corpusDir)
var count = 0
Expand Down Expand Up @@ -101,7 +105,4 @@ object Runner extends App {
}
println(count + " files formatted.")
}

formatInPlace()

}
}
1 change: 0 additions & 1 deletion misc/src/main/scala/scalariform/gui/FormatterFrame.scala
Original file line number Diff line number Diff line change
Expand Up @@ -426,4 +426,3 @@ object Samples {
|}""".stripMargin
} // format: ON


18 changes: 9 additions & 9 deletions misc/src/main/scala/scalariform/gui/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package scalariform.gui
import scalariform.utils.Utils._
import javax.swing.JFrame

object Main extends App {
object Main {

onSwingThread {
val frame = new FormatterFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setSize(1280, 600)
frame.setVisible(true)
def main(args: Array[String]) {
onSwingThread {
val frame = new FormatterFrame
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
frame.setSize(1280, 600)
frame.setVisible(true)
}
}

}

}
2 changes: 1 addition & 1 deletion misc/src/main/scala/scalariform/gui/ParseTreeModel.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ParseTreeModel(rootAstNode: AstNode) extends TreeModel {
val fields = astNode.getFields

lazy val children = fields flatMap {
case (_, None) | (_, Nil) None
case (_, None) | (_, Nil) None
case (fieldName, value) Some(makeTreeNode(value.asInstanceOf[AnyRef], fieldName))
}

Expand Down
Loading

0 comments on commit 3383e5a

Please sign in to comment.