Skip to content

Add flag to skip insertion of spaces within multi imports (rebase) #126

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 36 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
0a832ff
Add new option `noSpacesAroundMultiImports` to disable reformatting o…
gbasler Dec 17, 2012
f35f29e
Add multi-line case formatting option.
gbasler Dec 25, 2012
2aa4249
Add `GroupByNewLine` option that let's you format blocks in case stat…
gbasler Jan 13, 2013
1e2d29e
Update README.rst
gbasler Jan 13, 2013
63a17ee
Bugfix for `final` modifier in constructor arguments.
gbasler Jan 14, 2013
749a1c3
Update README.rst
gbasler Jan 14, 2013
f43acd0
Bugfix: align multi line case guards correctly in pattern matches.
gbasler Jan 16, 2013
a59db57
Bugfix: non-multi line cases were missing spaces before `=>`.
gbasler Jan 16, 2013
a713311
Fix multi line formatting.
gbasler Jan 20, 2013
c962c53
Fix newline detection for case clauses.
gbasler Jan 22, 2013
abf4f15
Bugfix: format new scopes after `=>` in lambda function correctly.
gbasler Jan 30, 2013
3e81616
Fix formatting for new scope after arrow.
gbasler Feb 4, 2013
2bdc319
Don't use snapshot version of eclipse plugin, disable signing.
gbasler Feb 4, 2013
9f72169
New option to reformat chained packages.
gbasler Feb 15, 2013
c6c45c6
Fix missing chained package format option.
gbasler Feb 15, 2013
8bd6c17
Fix multi line case clauses formatting.
gbasler Feb 21, 2013
cc917fb
Updates for Scala 2.10.0
mdr Apr 24, 2013
166d35d
Update CHANGELOG
mdr Apr 24, 2013
0810e74
Preparing for 0.1.4 release
mdr Apr 24, 2013
373889e
Version tweaks
mdr Apr 24, 2013
243a2ed
Tweaks for 0.1.4
mdr Apr 24, 2013
e055398
Update versions for 0.1.5-SNAPSHOT
mdr Apr 24, 2013
97cf986
Amazon S3 download link
mdr Apr 24, 2013
9521a84
Support parameterised traits per Scalac master
mdr Apr 25, 2013
adb872f
Added notes of hashes of scalac files to sync parser changes
mdr Apr 26, 2013
2780b45
Fix parser updates on Inferred Semi parser
mdr Apr 29, 2013
c29e9ff
Formatting tweaks
mdr Apr 29, 2013
c0b2403
FIX: Type formatter crash on multiline types
mdr Apr 29, 2013
7bf725e
Improvements for GUI
mdr Apr 30, 2013
ad8aef3
Corpus stuff
mdr May 24, 2013
41c5ca9
Remove long-dead "requires" keyword, fixes #79
mdr May 24, 2013
0f2145a
Upgrade to scala-maven-plugin 3.1.5
adriaanm Aug 26, 2013
983807b
Switch maven build to Kepler repo.
dragos Sep 11, 2013
3561fae
Upgrade Tycho and Scala (default) version.
dragos Sep 11, 2013
5a20ed2
Removed obsolete release profiles.
dragos Sep 11, 2013
563db39
Use vanilla Scala OSGi bundles.
dragos Feb 1, 2013
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
10 changes: 9 additions & 1 deletion CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
0.1.5 (..)
* FIX: Type formatter crash on multiline types
* Track scalac parser -- allow trait-position parents to have parameter blocks
* Sync changes to InferredSemicolonParser

0.1.4 (24/April/13)
* FIX: Allow declarations as last statement in case block (issue #60)
* Update to build 2.10 final

0.1.3 (3/October/12)
* Add EOF to ComplilationUnit, ensuring entire source is represented in the tree
* Support $this references in String interpolation
* Update build to sbt 0.12.1
* FIX: Allow declarations as last statement in case block (issue #60).

0.1.2 (7/May/12)

Expand Down
45 changes: 43 additions & 2 deletions README.rst
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,31 @@ You can also configure formatting to be run as a save action (Window -> Preferen

To set preferences, go to Window -> Preferences -> Scala -> Formatter

Integration with IntelliJ
-------------------------

IntelliJ already has a built-in Scala code formatter (C-L).
I use the original settings plus `Wraping and Braces` -> `Align columns in case branches`.
In order to achieve exactly the same formatting use the following options::


def formattingPreferences = {
import scalariform.formatter.preferences._
FormattingPreferences()
.setPreference(AlignParameters, true)
.setPreference(AlignSingleLineCaseStatements, true)
.setPreference(AlignSingleLineCaseStatements.AlignMultiLineCaseStatements, true)
.setPreference(AlignSingleLineCaseStatements.MaxArrowIndent, 120)
.setPreference(AlignSingleLineCaseStatements.GroupByNewLine, true) // IntelliJ compatible
.setPreference(CompactControlReadability, false)
.setPreference(NoSpacesAroundMultiImports, true)
.setPreference(FormatXml, false)
.setPreference(PreserveSpaceBeforeArguments, true)
.setPreference(IndentWithTabs, false)
.setPreference(SpacesWithinPatternBinders, false) // IntelliJ compatible
}


Integration with Emacs/ENSIME
-----------------------------

Expand Down Expand Up @@ -59,7 +84,7 @@ Usage::
<plugin>
<groupId>org.scalariform</groupId>
<artifactId>scalariform-maven-plugin</artifactId>
<version>0.1.3</version>
<version>0.1.4</version>
<executions>
<execution>
<phase>process-sources</phase>
Expand Down Expand Up @@ -103,7 +128,7 @@ the following to ``.vimrc`` ::

The executable scalariform.jar can be downloaded from:

https://github.com/downloads/mdr/scalariform/scalariform.jar
https://s3.amazonaws.com/scalariform/scalariform.jar

Command line tool
-----------------
Expand Down Expand Up @@ -474,6 +499,22 @@ If ``false``,::

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

chainedPackageClauses
~~~~~~~~~~~~~~~~~~~~~

Default: ``false``

Example::
```
package com.company.analytics.math.curves.interpolators
```

Will be reformatted to::
```
package com.company.analytics.math
package curves
package interpolators
```

Scala Style Guide
~~~~~~~~~~~~~~~~~
Expand Down
21 changes: 10 additions & 11 deletions cli/.classpath
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="bin" path="src/main/scala"/>
<classpathentry kind="src" output="bin" path="src/main/java"/>
<classpathentry kind="src" output="bin" path="src/test/scala"/>
<classpathentry kind="src" output="bin" path="src/test/java"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="lib" path="../lib_managed/jars/commons-io/commons-io/commons-io-1.4.jar" sourcepath="/lib_managed/srcs/commons-io/commons-io/commons-io-1.4-sources.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/scalariform"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<classpathentry output="bin" path="src/main/scala" kind="src"></classpathentry>
<classpathentry output="bin" path="src/main/java" kind="src"></classpathentry>
<classpathentry output="bin" path="src/test/scala" kind="src"></classpathentry>
<classpathentry output="bin" path="src/test/java" kind="src"></classpathentry>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"></classpathentry>
<classpathentry kind="lib" path="../lib_managed/jars/commons-io/commons-io/commons-io-1.4.jar" sourcepath="../lib_managed/srcs/commons-io/commons-io/commons-io-1.4-sources.jar"></classpathentry>
<classpathentry exported="true" path="/scalariform" kind="src" combineaccessrules="false"></classpathentry>
<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"></classpathentry>
<classpathentry path="bin" kind="output"></classpathentry>
</classpath>
15 changes: 0 additions & 15 deletions cli/src/main/scala/scalariform/commandline/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -254,26 +254,11 @@ object Main {

private def transformFilesInPlace(files: Seq[File], encoding: String, doFormat: String ⇒ Option[String], log: String ⇒ Unit): Boolean = {
var problems = false
// val futures =
// for (file ← files) yield asyncExec {
// problems &= transformFileInPlace(file, encoding, doFormat, log)
// }
// futures.map(_.get())
for (file ← files)
problems &= transformFileInPlace(file, encoding, doFormat, log)
problems
}

// private val lock = new ReentrantLock
// private lazy val executorService = Executors.newCachedThreadPool()
// private def asyncExec(x: ⇒ Unit): Future[_] = executorService.submit(new Runnable { def run() = x })
// private def withLock[T](x: ⇒ T): T = {
// lock.lock()
// try
// x
// finally
// lock.unlock()
// }
/**
* @return true iff file is already formatted correctly
*/
Expand Down
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
# built documents.
#
# The short X.Y version.
version = '0.1.4-SNAPSHOT'
version = '0.1.5-SNAPSHOT'
# The full version, including alpha/beta/rc tags.
release = '0.1.4-SNAPSHOT'
release = '0.1.5-SNAPSHOT'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
25 changes: 12 additions & 13 deletions misc/.classpath
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="bin" path="src/main/scala"/>
<classpathentry kind="src" output="bin" path="src/main/java"/>
<classpathentry kind="src" output="bin" path="src/test/scala"/>
<classpathentry kind="src" output="bin" path="src/test/java"/>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/>
<classpathentry kind="lib" path="../lib_managed/jars/commons-io/commons-io/commons-io-1.4.jar" sourcepath="/lib_managed/srcs/commons-io/commons-io/commons-io-1.4-sources.jar"/>
<classpathentry kind="lib" path="../lib_managed/jars/com.miglayout/miglayout/miglayout-3.7.4.jar" sourcepath="/lib_managed/srcs/com.miglayout/miglayout/miglayout-3.7.4-sources.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry combineaccessrules="false" kind="src" path="/cli"/>
<classpathentry combineaccessrules="false" kind="src" path="/scalariform"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<classpathentry output="bin" path="src/main/scala" kind="src"></classpathentry>
<classpathentry output="bin" path="src/main/java" kind="src"></classpathentry>
<classpathentry output="bin" path="src/test/scala" kind="src"></classpathentry>
<classpathentry output="bin" path="src/test/java" kind="src"></classpathentry>
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"></classpathentry>
<classpathentry kind="lib" path="../lib_managed/jars/commons-io/commons-io/commons-io-1.4.jar" sourcepath="../lib_managed/srcs/commons-io/commons-io/commons-io-1.4-sources.jar"></classpathentry>
<classpathentry kind="lib" path="../lib_managed/jars/com.miglayout/miglayout/miglayout-3.7.4.jar" sourcepath="../lib_managed/srcs/com.miglayout/miglayout/miglayout-3.7.4-sources.jar"></classpathentry>
<classpathentry exported="true" path="/scalariform" kind="src" combineaccessrules="false"></classpathentry>
<classpathentry exported="true" path="/cli" kind="src" combineaccessrules="false"></classpathentry>
<classpathentry path="org.eclipse.jdt.launching.JRE_CONTAINER" kind="con"></classpathentry>
<classpathentry path="bin" kind="output"></classpathentry>
</classpath>
29 changes: 15 additions & 14 deletions misc/src/main/scala/scalariform/corpusscan/CorpusScanner.scala
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package scalariform.corpusscan

import scalariform.lexer.{ Token ⇒ _, _ }
import scalariform.formatter._
import scalariform.formatter.preferences._
import scalariform.parser._
import scala.util.parsing.input._
import scala.util.parsing.combinator._
import java.io.File

import scala.io.Source
import scalariform.utils.Utils.writeText

import org.apache.commons.io.FileUtils

import scalariform.commandline.ScalaFileWalker
import scalariform.formatter._
import scalariform.formatter.preferences.FormattingPreferences
import scalariform.lexer._
import scalariform.parser._
import scalariform.utils.Utils.writeText

sealed trait ParseFault
case object TokensDoNotCoverSource extends ParseFault
Expand All @@ -31,9 +32,9 @@ object CorpusScanner extends SpecificFormatter {
val tokens = ScalaLexer.tokenise(source)
try {
val result = new ScalaParser(tokens.toArray).compilationUnitOrScript()
if (result.tokens != tokens.init) /* drop EOF */
if (result.tokens != tokens) {
Some(BadAstTokens)
else
} else
None
} catch {
case e: ScalaParserException ⇒ Some(UnsuccessfulParse)
Expand Down Expand Up @@ -66,9 +67,9 @@ object CorpusScanner extends SpecificFormatter {

}

object Runner {
object Runner extends App {

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

def checkParser() {
Expand All @@ -93,14 +94,14 @@ object Runner {
for (file ← ScalaFileWalker.findScalaFiles(corpusDir)) {
print("Formatting: " + file)
CorpusScanner.formatFile(file)
val parsed = CorpusScanner.attemptToParse(file)
require(parsed == None, parsed.toString)
val parseFaultOpt = CorpusScanner.attemptToParse(file)
require(parseFaultOpt == None, parseFaultOpt.toString)
println()
count += 1
}
println(count + " files formatted.")
}

def main(args: Array[String]) = formatInPlace()
formatInPlace()

}
Loading