Skip to content

Commit

Permalink
Imports: implement contiguousGroups logic
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Sep 2, 2021
1 parent 02fa738 commit 88b5711
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ object Imports extends RewriteFactory {
): Unit =
if (settings.groups.isEmpty && settings.sort.eq(Sort.none))
processEachLine(stats)
else if (settings.contiguousGroups eq ContiguousGroups.only)
processEachGroup(stats)
else
processAllGroups(stats)

Expand All @@ -504,6 +506,13 @@ object Imports extends RewriteFactory {
processTokenRanges(importString, getTokenRange(group))
}

private def processEachGroup(stats: Seq[Seq[ImportExportStat]]): Unit =
stats.foreach { group =>
val tokenRange = getTokenRange(group)
val importString = processImports(group)
processTokenRanges(importString, tokenRange)
}

private def processAllGroups(stats: Seq[Seq[ImportExportStat]]): Unit = {
val tokenRanges = stats.map(getTokenRange)
val importString = processImports(stats.flatten)
Expand Down
4 changes: 2 additions & 2 deletions scalafmt-tests/src/test/resources/rewrite/Imports.source
Original file line number Diff line number Diff line change
Expand Up @@ -687,10 +687,10 @@ object Main {
object Main {
// c1
import Foo._ // c2
// c4
import bar.ec // c5
// c3
val bar: Bar = getBar
// c4
import bar.ec // c5

def getBar: Foo.Bar = ???
}
Expand Down

0 comments on commit 88b5711

Please sign in to comment.