@@ -10,6 +10,7 @@ where
1010
1111import Data.Bifunctor
1212import Data.Function (on)
13+import Data.Generics (gcompare)
1314import Data.List (sortBy)
1415import GHC hiding (GhcPs, IE)
1516import HsExtension
@@ -31,11 +32,11 @@ sortImports = sortBy compareIdecl . fmap (fmap sortImportLists)
3132
3233compareIdecl :: LImportDecl GhcPs -> LImportDecl GhcPs -> Ordering
3334compareIdecl (L _ m0) (L _ m1) =
34− if isPrelude n0
35− then GT
36− else if isPrelude n1
37− then LT
38− else n0 `compare` n1
35+ case (isPrelude n0, isPrelude n1) of
36+ (False, False) -> n0 `compare` n1
37+ (True, False) -> GT
38+ (False, True) -> LT
39+ (True, True) -> m0 `gcompare` m1
3940 where
4041 n0 = unLoc (ideclName m0)
4142 n1 = unLoc (ideclName m1)