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
Avoid empty lines in the beginning and end of blocks #1431
Merged
poslegm
merged 13 commits into
scalameta:master
from
famly:avoid_empty_lines_in_start_and_end_of_blocks
Oct 28, 2019
Merged
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f518bc0
Add features for avoiding empty lines at start/end of a block
tdidriksen e79000d
Add tests for avoidEmptyLineAfterOpenCurly and avoidEmptyLineBeforeCl…
tdidriksen 4e5fcef
Add docs for avoidEmptyLineBeforeClosingCurly and avoidEmptyLineAfter…
tdidriksen 630181f
Improve wording in tests, say empty lines instead of newlines
tdidriksen 063302b
Merge branch 'master' into avoid_empty_lines_in_start_and_end_of_blocks
tdidriksen 4fa0c27
Merge avoidEmptyLineBeforeClosingCurly and avoidEmptyLineAfterOpenCurly
tdidriksen 71895e1
Apply avoidEmptyLinesAroundBlock to existing tests
tdidriksen da30fbf
Introduce editions
tdidriksen 8bbcde0
Make default value for avoidEmptyLinesAroundBlock depend on edition
tdidriksen d9ae32f
Remove newlines.avoidEmptyLinesAroundBlock section from config docs
tdidriksen 23e9394
Move avoidEmptyLinesAroundBlock check into ScalafmtConfig
tdidriksen 4ec5e99
Address feedback on editions
olafurpg dd78111
Merge pull request #1 from olafurpg/avoid_empty_lines_in_start_and_en…
tdidriksen File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
scalafmt-core/shared/src/main/scala/org/scalafmt/config/Edition.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package org.scalafmt.config | ||
|
||
import metaconfig.{Conf, ConfDecoder, ConfEncoder, Configured} | ||
|
||
sealed abstract class Edition(val order: Int, val name: String) | ||
|
||
object Edition { | ||
implicit val ordering: Ordering[Edition] = Ordering.by[Edition, Int](_.order) | ||
|
||
implicit val decoder: ConfDecoder[Edition] = ConfDecoder.instance { | ||
case Conf.Str("2019-10") => Configured.ok(Edition201910) | ||
case _ => Configured.ok(EditionLatest) | ||
} | ||
|
||
implicit val encoder: ConfEncoder[Edition] = | ||
ConfEncoder.instance(edition => Conf.Str(edition.name)) | ||
} | ||
|
||
case object Edition201910 extends Edition(0, "2019-10") | ||
case object EditionLatest extends Edition(Int.MaxValue, "latest") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,8 @@ package org.scalafmt.config | |
import metaconfig._ | ||
import metaconfig.generic.Surface | ||
|
||
import Edition.ordering._ | ||
|
||
/** | ||
* @param penalizeSingleSelectMultiArgList | ||
* If true, adds a penalty to newlines before a dot starting a select | ||
|
@@ -110,9 +112,14 @@ case class Newlines( | |
beforeImplicitKWInVerticalMultiline: Boolean = false, | ||
alwaysBeforeElseAfterCurlyIf: Boolean = false, | ||
alwaysBeforeMultilineDef: Boolean = true, | ||
avoidAfterYield: Boolean = true | ||
avoidAfterYield: Boolean = true, | ||
avoidEmptyLinesAroundBlock: Option[Boolean] = None | ||
) { | ||
val reader: ConfDecoder[Newlines] = generic.deriveDecoder(this).noTypos | ||
|
||
def shouldAvoidEmptyLinesAroundBlock(edition: Edition): Boolean = { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's move this to a |
||
avoidEmptyLinesAroundBlock.getOrElse(edition > Edition201910) | ||
} | ||
} | ||
|
||
object Newlines { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,7 +132,6 @@ object A { | |
} | ||
>>> | ||
object A { | ||
|
||
/** test */ | ||
def foo(): Int = 0 | ||
// bar | ||
|
55 changes: 55 additions & 0 deletions
55
scalafmt-tests/src/test/resources/newlines/avoidEmptyLinesAroundBlock.stat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
maxColumn = 80 | ||
newlines.avoidEmptyLinesAroundBlock = true | ||
|
||
<<< should remove empty lines at the beginning of a def block | ||
def other: String = { | ||
|
||
"Result" | ||
} | ||
>>> | ||
def other: String = { | ||
"Result" | ||
} | ||
|
||
<<< should remove empty lines at the beginning and end of a def block | ||
def other: String = { | ||
|
||
"Result" | ||
|
||
} | ||
>>> | ||
def other: String = { | ||
"Result" | ||
} | ||
|
||
<<< should remove empty lines at the beginning and end of a val block | ||
def other: String = { | ||
|
||
val aux = { | ||
|
||
"Result" | ||
|
||
} | ||
|
||
aux | ||
|
||
} | ||
>>> | ||
def other: String = { | ||
val aux = { | ||
"Result" | ||
} | ||
|
||
aux | ||
} | ||
|
||
<<< should remove empty lines at the end of a block | ||
def other: String = { | ||
"Result" | ||
|
||
|
||
} | ||
>>> | ||
def other: String = { | ||
"Result" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This section can be removed now.