@@ -3610,6 +3610,16 @@ or selector, as follows:
36103610
36113611> Since v3.0.0.
36123612
3613+ Let's define some terminology: an import statement consists of several parts:
3614+
3615+ - keyword: ` import ` or ` export `
3616+ - one or more comma-separated _ importers_
3617+ - for instance, ` import foo.bar, foo.baz.{qux => quux} ` contains two
3618+ importers, ` foo.bar ` and ` foo.baz.{qux => quux} `
3619+ - each importer is split, on the final dot, into
3620+ - _ reference_ : ` foo ` and ` foo.baz ` in the example above
3621+ - _ selectors_ : ` bar ` and ` {qux => quux} ` above
3622+
36133623#### Imports: ` expand `
36143624
36153625This parameter will attempt to create a separate line for each selector
@@ -3637,6 +3647,21 @@ import a.{
36373647 }
36383648```
36393649
3650+ #### Imports: sorting
3651+
3652+ Sorting is applied as follows:
3653+
3654+ - if disabled, no sorting
3655+ - if enabled, it applies to import _ selectors_ within one _ importer_
3656+ - if [ ` groups ` ] ( #imports-groups ) are used, sorting will also apply to importers
3657+ in the same group
3658+ - without groups, multiple import statements will ** not** be sorted
3659+ - importers are sorted one dot-separated label at a time
3660+ - importers ` foo.bar.baz ` and ` foo.bar as fbar ` will compare:
3661+ - ` foo ` and ` foo ` : equal
3662+ - ` bar ` and ` bar as fbar ` : ` bar ` comes earlier, just like it does
3663+ with equivalent scala2 selector syntax ` {bar => fbar} `
3664+
36403665#### Imports: ` sort = none `
36413666
36423667This default option causes no sorting.
@@ -3697,8 +3722,9 @@ import foo._
36973722> rule like ` OrganizeImports ` . However, on a large codebase, the overhead
36983723> of using semantic ` scalafix ` rules might be substantial.
36993724
3700- This rule will separate all import statements into groups. If sorting is
3701- enabled (i.e., not ` none ` ), imports will also be sorted within each group.
3725+ This rule will separate all import statements (or, to be more precise, all
3726+ [ importers] ( #imports ) from all import statements) into groups. If sorting
3727+ is enabled (i.e., not ` none ` ), imports will also be sorted within each group.
37023728
37033729The rule accepts the following parameters:
37043730
@@ -3715,13 +3741,15 @@ The rule accepts the following parameters:
37153741 (source, package, template etc.)
37163742
37173743``` scala mdoc:scalafmt
3744+ runner.dialect = scala3
37183745rewrite.rules = [Imports ]
37193746rewrite.imports.sort = ascii
37203747rewrite.imports.groups = [
37213748 [" foo\\ ..*" ],
37223749 [" bar\\ ..*" , " baz\\ ..*" ]
37233750]
37243751---
3752+ import bar .bar as bbar
37253753import bar .bar .{Random , bar , ~> , `symbol` }
37263754import baz .Baz .{bar => xyz , _ }
37273755import qux .`qux` .{Random , bar , ~> , `symbol` }
0 commit comments