Skip to content

Commit 3383e5a

Browse files
committed
Merge branch 'master' into multiple-parameters-list
Conflicts: scalariform/src/main/scala/scalariform/formatter/ExprFormatter.scala scalariform/src/main/scala/scalariform/formatter/preferences/PreferenceDescriptor.scala
2 parents 443ebf3 + d848e9f commit 3383e5a

32 files changed

+2094
-1002
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ docs/build
1818
nohup.out
1919
.history
2020
.cache
21+
.idea/

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: scala
2+
scala:
3+
- 2.10.3
4+
- 2.9.3
5+
jdk:
6+
- oraclejdk7
7+
- openjdk7

README.rst

Lines changed: 117 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Scalariform
22
===========
33

4+
.. image:: https://travis-ci.org/daniel-trinh/scalariform.png?branch=master
5+
:target: https://travis-ci.org/daniel-trinh/scalariform
6+
47
Scalariform is a code formatter for Scala. It's available as a
58
library, a stand-alone command line tool, or via integrations with
69
various editors and build tools (listed below).
@@ -14,6 +17,13 @@ Scalariform is licenced under `The MIT Licence`_.
1417
.. _Scala Style Guide: http://davetron5000.github.com/scala-style/
1518
.. _The MIT Licence: http://www.opensource.org/licenses/mit-license.php
1619

20+
Integration with sbt
21+
--------------------
22+
23+
A version for sbt >= 0.13.x has been written by Peter Vlugter: https://github.com/daniel-trinh/sbt-scalariform
24+
25+
Please see https://github.com/sbt/sbt-scalariform for older versions of sbt.
26+
1727
Integration with Eclipse
1828
------------------------
1929

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

25-
If you select some lines, only those will be formatted.
35+
If you select some lines, only those will be formatted.
2636

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

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

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

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

@@ -73,16 +83,6 @@ Usage::
7383
</executions>
7484
</plugin>
7585

76-
Integration with sbt
77-
--------------------
78-
79-
`sbt-scalariform`_, written by Olivier Michallat, provides an sbt plugin contributing formatting actions for sbt 0.7.x.
80-
81-
A version for sbt 0.10.x has been written by Peter Vlugter: https://github.com/typesafehub/sbt-scalariform
82-
83-
.. _sbt-scalariform: http://github.com/olim7t/sbt-scalariform
84-
85-
8686
Integration with TextMate
8787
-------------------------
8888

@@ -123,26 +123,72 @@ alignParameters
123123

124124
Default: ``false``
125125

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

128130
class Person(name: String,
129-
age: Int,
131+
age: Int = 24,
130132
birthdate: Date,
131-
astrologicalSign: String,
133+
astrologicalSign: String = "libra",
132134
shoeSize: Int,
133135
favoriteColor: java.awt.Color)
134136

135137
If ``true``, then::
136138

137-
class Person(name: String,
138-
age: Int,
139-
birthdate: Date,
140-
astrologicalSign: String,
141-
shoeSize: Int,
142-
favoriteColor: java.awt.Color)
139+
class Person(name: String,
140+
age: Int = 24,
141+
birthdate: Date,
142+
astrologicalSign: String = "libra",
143+
shoeSize: Int,
144+
favoriteColor: java.awt.Color)
145+
146+
This will also place the "implicit" keyword in parameters on it's own line, whenever
147+
the parameter being formatted contains a newline::
148+
149+
For example, if ``false``, then::
150+
151+
def formatBirthDate(
152+
implicit birthdate: Date = Date("11/11/11"),
153+
birthtime: Time): DateTime
154+
155+
If ``true``, then::
156+
157+
def formatBirthDate(
158+
implicit
159+
birthdate: Date = Date("11/11/11"),
160+
birthtime: Time): DateTime
143161

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

164+
165+
alignArguments
166+
~~~~~~~~~~~~~~
167+
168+
Default: ``false``
169+
170+
Aligns mult-line arguments
171+
172+
For example, if ``false``, then::
173+
174+
Cake(candles = 10,
175+
frostingFlavor = Vanilla,
176+
layerFlavor = Chocolate,
177+
icecream = true
178+
)
179+
180+
If ``true``, then::
181+
182+
Cake(
183+
candles = 10,
184+
frostingFlavor = Vanilla,
185+
layerFlavor = Chocolate,
186+
icecream = true
187+
)
188+
189+
This option is disabled if ``indentWithTabs`` is ``true``.
190+
191+
146192
alignSingleLineCaseStatements
147193
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
148194

@@ -204,7 +250,7 @@ using `Compact Control Readability`_ style:
204250

205251
try {
206252
foo()
207-
}
253+
}
208254
catch {
209255
case _ => bar()
210256
}
@@ -319,7 +365,7 @@ indentSpaces
319365

320366
Default: ``2``
321367

322-
The number of spaces to use for each level of indentation.
368+
The number of spaces to use for each level of indentation.
323369

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

@@ -330,7 +376,7 @@ Default: ``false``
330376

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

@@ -341,14 +387,14 @@ Default: ``false``
341387

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

344-
/** This method applies f to each
390+
/** This method applies f to each
345391
* element of the given list.
346392
*/
347393

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

350-
/**
351-
* This method applies f to each
396+
/**
397+
* This method applies f to each
352398
* element of the given list.
353399
*/
354400

@@ -358,7 +404,7 @@ preserveDanglingCloseParenthesis
358404
Default: ``false``
359405

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

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

422+
423+
Or with parameters, if ``true``::
424+
425+
def findBooks(
426+
author: Option[String] = None,
427+
title: Option[String] = None
428+
): List[Book]
429+
430+
If ``false``::
431+
432+
def findBooks(
433+
author: Option[String] = None,
434+
title: Option[String] = None): List[Book]
435+
436+
376437
placeScaladocAsterisksBeneathSecondAsterisk
377438
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
378439

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

383444
/** Wibble
384-
* wobble
445+
* wobble
385446
*/
386447
class A
387448

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

390451
/** Wibble
391-
* wobble
452+
* wobble
392453
*/
393454
class A
394455

@@ -474,6 +535,18 @@ If ``false``,::
474535

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

538+
spacesAroundMultiImports
539+
~~~~~~~~~~~~~~~~~~~~~~~~
540+
541+
Default: ``true``
542+
543+
Whether or not to add spaces around mutli-imports. For example, If ``true``, then::
544+
545+
import a.{ b, c, d }
546+
547+
If ``false``, then::
548+
549+
import a.{b,c,d}
477550

478551
Scala Style Guide
479552
~~~~~~~~~~~~~~~~~
@@ -487,14 +560,14 @@ make uncompliant source more compliant.
487560
============================ ========= =========
488561
Preference Value Default?
489562
============================ ========= =========
490-
alignParameters ``false``
491-
compactStringConcatenation ``false``
563+
alignParameters ``false``
564+
compactStringConcatenation ``false``
492565
doubleIndentClassDeclaration ``true`` No
493-
indentSpaces ``2``
566+
indentSpaces ``2``
494567
placeScaladocAsterisksBeneathSecondAsterisk ``true`` No
495-
preserveSpaceBeforeArguments ``false``
496-
rewriteArrowSymbols ``false``
497-
spaceBeforeColon ``false``
568+
preserveSpaceBeforeArguments ``false``
569+
rewriteArrowSymbols ``false``
570+
spaceBeforeColon ``false``
498571
spaceInsideBrackets ``false``
499572
spaceInsideParentheses ``false``
500573
============================ ========= =========
@@ -510,24 +583,24 @@ format: [ON|OFF]
510583
Disables the formatter for selective portions of a source file::
511584

512585
// format: OFF <-- this directive disables formatting from this point
513-
class AsciiDSL {
586+
class AsciiDSL {
514587
n ¦- "1" -+ { n: Node =>
515-
n ¦- "i"
516-
n ¦- "ii"
517-
n ¦- "iii"
518-
n ¦- "iv"
588+
n ¦- "i"
589+
n ¦- "ii"
590+
n ¦- "iii"
591+
n ¦- "iv"
519592
n ¦- "v"
520593
}
521594
n ¦- "2"
522595
n ¦- "3" -+ { n: Node =>
523-
n ¦- "i"
596+
n ¦- "i"
524597
n ¦- "ii" -+ { n: Node =>
525598
n ¦- "a"
526599
n ¦- "b"
527600
n ¦- "c"
528601
}
529-
n ¦- "iii"
530-
n ¦- "iv"
602+
n ¦- "iii"
603+
n ¦- "iv"
531604
n ¦- "v"
532605
}
533606
// format: ON <-- formatter resumes from this point

cli/src/main/scala/scalariform/commandline/Main.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import scalariform.ScalaVersions
1313
object Main {
1414

1515
def main(args: Array[String]) {
16-
exit(if (process(args)) 1 else 0)
16+
sys.exit(if (process(args)) 1 else 0)
1717
}
1818

1919
def process(args: Array[String]): Boolean = {

misc/src/main/scala/scalariform/corpusscan/CorpusScanner.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,15 @@ object CorpusScanner extends SpecificFormatter {
6767

6868
}
6969

70-
object Runner extends App {
70+
object Runner {
7171

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

75+
def main(args: Array[String]) {
76+
formatInPlace()
77+
}
78+
7579
def checkParser() {
7680
val files = ScalaFileWalker.findScalaFiles(corpusDir)
7781
var count = 0
@@ -101,7 +105,4 @@ object Runner extends App {
101105
}
102106
println(count + " files formatted.")
103107
}
104-
105-
formatInPlace()
106-
107-
}
108+
}

misc/src/main/scala/scalariform/gui/FormatterFrame.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,4 +426,3 @@ object Samples {
426426
|}""".stripMargin
427427
} // format: ON
428428

429-

misc/src/main/scala/scalariform/gui/Main.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package scalariform.gui
33
import scalariform.utils.Utils._
44
import javax.swing.JFrame
55

6-
object Main extends App {
6+
object Main {
77

8-
onSwingThread {
9-
val frame = new FormatterFrame
10-
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
11-
frame.setSize(1280, 600)
12-
frame.setVisible(true)
8+
def main(args: Array[String]) {
9+
onSwingThread {
10+
val frame = new FormatterFrame
11+
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
12+
frame.setSize(1280, 600)
13+
frame.setVisible(true)
14+
}
1315
}
14-
15-
}
16-
16+
}

misc/src/main/scala/scalariform/gui/ParseTreeModel.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class ParseTreeModel(rootAstNode: AstNode) extends TreeModel {
3131
val fields = astNode.getFields
3232

3333
lazy val children = fields flatMap {
34-
case (_, None) | (_, Nil) None
34+
case (_, None) | (_, Nil) None
3535
case (fieldName, value) Some(makeTreeNode(value.asInstanceOf[AnyRef], fieldName))
3636
}
3737

0 commit comments

Comments
 (0)