Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
379ba78
Made PreserveDanglingCloseParenthesis working for classes
mairbek Oct 27, 2012
acbb72f
adding specs for fancier alignParameters
Dec 21, 2013
342d6d9
Add test for MultipleParameterList
Dec 22, 2013
6b027fb
Start implementation Multiple parameters list formating.
Dec 22, 2013
041f7aa
Remove chaining of format state.
Dec 22, 2013
c7960f1
Change type in fold. Now folding IntertokenFormat
Dec 22, 2013
12a9871
Add configuration property.
Dec 22, 2013
ce5f3da
Simplify property applying to text
Dec 22, 2013
88a90e7
Format fixing.
Dec 22, 2013
f989836
Add threshold for breaking parameters group.
Dec 22, 2013
4356e6c
Add test for threshold.
Dec 22, 2013
2f56154
Implementation of threshold
Dec 22, 2013
443ebf3
Fix failure on definitions without parameters.
Dec 22, 2013
b91465f
Squashed commit of the following:
Jan 18, 2014
175aa28
Merge pull request #1 from daniel-trinh/alignParams_Issue62
daniel-trinh Jan 18, 2014
bb637dc
Merge remote-tracking branch 'mairbek/master' into alignParams_Issue62
Jan 18, 2014
9f17946
Merge remote-tracking branch 'origin/master'
Jan 18, 2014
418cf66
remove changelist for #62
Jan 18, 2014
cddbb76
fix missing type length calculation in formatting function types
Jan 18, 2014
eaf05fd
fix edge case of spacing being removed in single line implicit parame…
Jan 18, 2014
f10a478
fix multiple parameterized type length calculation
Jan 19, 2014
d7b7932
fixed another edge case with call by name params
Jan 19, 2014
d1e824a
switch type length calculation to a less brittle solution
Jan 19, 2014
59a5b8f
temporary work, added a few specs for testing this new feature
Jan 20, 2014
c24f6a5
added AlignArguments preference, and a few more unit tests
Jan 21, 2014
50da347
added support for param grouping by blank lines
Jan 21, 2014
1f17838
Merge branch 'alignParams_Issue61' into alignMethodCalls_Issue53
Jan 21, 2014
92bade1
build tweaks
Jan 23, 2014
5c716cb
remove unnecessary resolver
Jan 25, 2014
27f4320
Merge remote-tracking branch 'origin/0.1.5-SNAPSHOT' into alignMethod…
Jan 25, 2014
6a40b21
get basic method call alignment working
Feb 4, 2014
523d999
add missing tests
Feb 4, 2014
5997914
oops, adding method alignment for real this time
Feb 4, 2014
2ed909f
update documentation to include info about alignArguments
Feb 4, 2014
9f39500
add check to make sure IndentWithTabs is not on
Feb 4, 2014
7cba564
Add new option `noSpacesAroundMultiImports` to disable reformatting o…
gbasler Dec 17, 2012
ea3ab5b
add specs for NoSpacesAroundMultiImports
Feb 4, 2014
711c8ae
add fix for #62
Feb 4, 2014
6328944
tweak readme
Feb 4, 2014
219665b
update noSpacesAroundMultiImports -> spacesAroundMultiImports to matc…
Feb 4, 2014
73ec39c
cleanup extra debugging code and run scalariformFormat
Feb 4, 2014
73c5065
fix typo in readme
Feb 4, 2014
2435e0d
fix sbt reference in readme
Feb 5, 2014
4f4e82c
Add .travis.yml file
Feb 6, 2014
e942c7d
Add Travis-CI baner with build status.
Feb 6, 2014
565e76e
update banners to point to this remote
Feb 6, 2014
b71daaf
Building against JDK6 isn't going to work, due to an API change in th…
Feb 10, 2014
f9ac5ec
add a check in the build so that jdk 1.6 isn't used
Feb 10, 2014
c998e6d
initial deprecation of PreserveDanglingCloseParenthesis, implementing…
Feb 18, 2014
84a6644
fixed tons of corner cases with new indentless multi parameter argume…
Feb 19, 2014
ccbeb4b
deprecate PreserveDanglingParenthesis in param clauses, and removed e…
Feb 19, 2014
34ed081
remove .idea files
Feb 19, 2014
ef6d60b
add 2.11-M8 to the build
Feb 19, 2014
91fa592
run scalariform formatter
Feb 19, 2014
674d354
remove unnecessary format result merge operation
Feb 19, 2014
d848e9f
Merge pull request #11 from daniel-trinh/issue7_issue8_issue9
daniel-trinh Feb 19, 2014
3383e5a
Merge branch 'master' into multiple-parameters-list
bambuchaAdm Mar 12, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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