import-grouping
Description | Rules for grouping import declarations |
---|---|
Options |
|
Default | legacy |
Ormolu | legacy |
Since | Unreleased |
Some basic presets are provided but you can configure your own rules via a dedicated YAML configuration.
Predefined presets:
legacy
: adopt the legacy behavior (before version 0.17), i.e.,single
whenrespectful
isfalse
andpreserve
whenrespectful
is true. Seerespectful
.preserve
: preserve the existing import groupssingle
: single group of importsby-qualified
: one group for unqualified imports, then one group for qualified importsby-scope
: one group for external imports, then one group for imports targeting modules from the current Cabal projectby-scope-then-qualified
: applyby-scope
first, thenby-qualified
Predefined matchers:
match: all
: matches all modulesmatch: local-modules
: matches modules defined in the current Cabal project. Those modules are automatically detected. Developers can add custom modules through the--local-modules
CLI option. Seelocal-modules
for more information.glob: pattern
: matches modules matching the providedpattern
.*
can be any character on the same module level.**
can be any character and can span multiple module levels.
Here's an example used in the custom
configuration:
import-grouping:
- name: "Text modules"
rules:
- glob: Data.Text
- name: "The rest"
rules:
- match: all
priority: 100
- name: "My internals and monads unqualified"
rules:
- match: local-modules
qualified: no
- glob: Control.Monad
qualified: no
- name: "My internals and monads qualified"
rules:
- match: local-modules
qualified: yes
- glob: Control.Monad
qualified: yes
- name: "Specific monads"
rules:
- glob: Control.Monad.**
Examples
import Control.Monad (Monad (..))
import qualified Control.Monad.Error as Error
import Control.Monad.State.Lazy (MonadState (..))
import Data.Maybe (maybe)
import Data.Text (Text)
import qualified Data.Text
import Data.Text.IO (hGetLine)
import SomeInternal.Module1 (anotherDefinition, someDefinition)
import SomeInternal.Module1.SubModuleA
import qualified SomeInternal.Module2 as Mod2
import qualified System.IO as SIO
import Text.Printf (printf)
import Control.Monad (Monad (..))
import Control.Monad.State.Lazy (MonadState (..))
import Data.Maybe (maybe)
import Data.Text (Text)
import Data.Text.IO (hGetLine)
import SomeInternal.Module1 (anotherDefinition, someDefinition)
import SomeInternal.Module1.SubModuleA
import Text.Printf (printf)
import qualified Control.Monad.Error as Error
import qualified Data.Text
import qualified SomeInternal.Module2 as Mod2
import qualified System.IO as SIO
import Control.Monad (Monad (..))
import qualified Control.Monad.Error as Error
import Control.Monad.State.Lazy (MonadState (..))
import Data.Maybe (maybe)
import Data.Text (Text)
import qualified Data.Text
import Data.Text.IO (hGetLine)
import qualified System.IO as SIO
import Text.Printf (printf)
import SomeInternal.Module1 (anotherDefinition, someDefinition)
import SomeInternal.Module1.SubModuleA
import qualified SomeInternal.Module2 as Mod2
import Control.Monad (Monad (..))
import Control.Monad.State.Lazy (MonadState (..))
import Data.Maybe (maybe)
import Data.Text (Text)
import Data.Text.IO (hGetLine)
import Text.Printf (printf)
import qualified Control.Monad.Error as Error
import qualified Data.Text
import qualified System.IO as SIO
import SomeInternal.Module1 (anotherDefinition, someDefinition)
import SomeInternal.Module1.SubModuleA
import qualified SomeInternal.Module2 as Mod2
import Data.Text (Text)
import qualified Data.Text
import Data.Maybe (maybe)
import Data.Text.IO (hGetLine)
import qualified System.IO as SIO
import Text.Printf (printf)
import Control.Monad (Monad (..))
import SomeInternal.Module1 (anotherDefinition, someDefinition)
import SomeInternal.Module1.SubModuleA
import qualified SomeInternal.Module2 as Mod2
import qualified Control.Monad.Error as Error
import Control.Monad.State.Lazy (MonadState (..))
For more examples, see the test files.