Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
6 changes: 5 additions & 1 deletion docs/rules/OrganizeImports.md
Original file line number Diff line number Diff line change
Expand Up @@ -1119,13 +1119,17 @@ the [`OrganizeImports.groups`](#groups) option.

### Value type

Enum: `Ascii | SymbolsFirst | Keep`
Enum: `Ascii | AsciiCaseInsensitive | SymbolsFirst | Keep`

#### `Ascii`
Sort import statements by ASCII codes. This is the default sorting order
that the IntelliJ IDEA Scala import optimizer picks ("lexicographically"
option).

#### `AsciiCaseInsensitive`
Sort import statements by ASCII codes, but not distinguishing uppercase
and lowercase letters.

#### `SymbolsFirst`
Put wildcard imports and grouped imports with braces first, otherwise
same as `Ascii`. This replicates IntelliJ IDEA Scala’s "scalastyle
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,8 @@ class OrganizeImports(
// pretty-print an `Importer` into a single line.
case ImportsOrder.Ascii =>
importeesSorted sortBy (i => importerSyntax(i.copy()))
case ImportsOrder.AsciiCaseInsensitive =>
importeesSorted sortBy (i => importerSyntax(i.copy()).toLowerCase)
case ImportsOrder.SymbolsFirst =>
sortImportersSymbolsFirst(importeesSorted)
case ImportsOrder.Keep =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ sealed trait ImportsOrder

object ImportsOrder {
case object Ascii extends ImportsOrder
case object AsciiCaseInsensitive extends ImportsOrder
case object SymbolsFirst extends ImportsOrder
case object Keep extends ImportsOrder

def all: List[ImportsOrder] =
List(Ascii, SymbolsFirst, Keep)
List(Ascii, AsciiCaseInsensitive, SymbolsFirst, Keep)

implicit def reader: ConfDecoder[ImportsOrder] =
ReaderUtil.fromMap(all.map(x => x.toString -> x).toMap)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
rules = [OrganizeImports]
OrganizeImports {
importsOrder = AsciiCaseInsensitive
removeUnused = false
}
*/
package test.organizeImports

import test.organizeImports.Case.b.c
import test.organizeImports.Case.A.b
import test.organizeImports.Case.A.C
import test.organizeImports.Case.b.b
import test.organizeImports.Case.C.c
import test.organizeImports.Case.A.A
import test.organizeImports.Case.C.a
import test.organizeImports.Case.b.A
import test.organizeImports.Case.C.B

object ImportsOrderAsciiCaseInsensitive
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package test.organizeImports

import test.organizeImports.Case.A.A
import test.organizeImports.Case.A.b
import test.organizeImports.Case.A.C
import test.organizeImports.Case.b.A
import test.organizeImports.Case.b.b
import test.organizeImports.Case.b.c
import test.organizeImports.Case.C.a
import test.organizeImports.Case.C.B
import test.organizeImports.Case.C.c

object ImportsOrderAsciiCaseInsensitive
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package test.organizeImports

object Case {
object A {
object A
object b
object C
}
object b {
object A
object b
object c
}
object C {
object a
object B
object c
}
}