Skip to content
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

Separate qualified and unqualified imports #1148

Open
nikita-volkov opened this issue Dec 9, 2024 · 1 comment
Open

Separate qualified and unqualified imports #1148

nikita-volkov opened this issue Dec 9, 2024 · 1 comment
Labels
style Nitpicking and things related to purely visual aspect for formatting.

Comments

@nikita-volkov
Copy link

Here's an example of an import block formatted with Ormolu:

module MyPackage where

import qualified Data.Primitive.ByteArray as ByteArray
import qualified Data.Text.Array as Array
import MyPackage.Classes (SomeClass(..))
import MyPackage.Prelude
import qualified MyPackage.TextCompat.Array as Array

data SomeType
ImportQualifiedPost version
module MyPackage where

import Data.Primitive.ByteArray qualified as ByteArray
import Data.Text.Array qualified as Array
import MyPackage.Classes (SomeClass(..))
import MyPackage.Prelude
import MyPackage.TextCompat.Array qualified as Array

data SomeType

I suggest to visually separate the imports into qualified and unqualified blocks:

module MyPackage where

import MyPackage.Classes (SomeClass(..))
import MyPackage.Prelude

import qualified Data.Primitive.ByteArray as ByteArray
import qualified Data.Text.Array as Array
import qualified MyPackage.TextCompat.Array as Array

data SomeType
ImportQualifiedPost version
module MyPackage where

import MyPackage.Classes (SomeClass(..))
import MyPackage.Prelude

import Data.Primitive.ByteArray qualified as ByteArray
import Data.Text.Array qualified as Array
import MyPackage.TextCompat.Array qualified as Array

data SomeType

Why?

  1. It removes the annoying chaotic jumps before module names, caused by the qualified keyword.
  2. It clearly separates qualified and unqualified imports, which is especially useful in case of ImportQualifiedPost, because the type of import is no longer immediately distinguishable.
@amesgen amesgen added the style Nitpicking and things related to purely visual aspect for formatting. label Dec 9, 2024
@michaelpj
Copy link
Contributor

You will be able to do this in fourmolu on the next release with the new import grouping feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
style Nitpicking and things related to purely visual aspect for formatting.
Projects
None yet
Development

No branches or pull requests

3 participants