diff options
author | Maxim Koltsov <kolmax94@gmail.com> | 2020-10-05 01:53:26 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-05 00:53:26 +0200 |
commit | 3f4edcce319c3dafd1d1309b281625beb854e8a7 (patch) | |
tree | d58e883d66e4a79612541d3199c2ff143783013a /lib | |
parent | 20dbe3a444a79dc5a8e0bf564b987db5393d127b (diff) | |
download | stylish-haskell-3f4edcce319c3dafd1d1309b281625beb854e8a7.tar.gz |
Fix "group" import sort with multi-line imports
When some import line spans multuple lines, e.g. when import list is
long, stylish-haskell breaks a group at this line, leading to bad
result.
This commits makes sure that import groups are recognized solely by
empty lines.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Language/Haskell/Stylish/Module.hs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/lib/Language/Haskell/Stylish/Module.hs b/lib/Language/Haskell/Stylish/Module.hs index 3647f3c..2cc8f47 100644 --- a/lib/Language/Haskell/Stylish/Module.hs +++ b/lib/Language/Haskell/Stylish/Module.hs @@ -201,10 +201,13 @@ moduleImportGroups = go [] Nothing . moduleImports -> [NonEmpty (Located Import)] go acc _ [] = ne acc go acc mbCurrentLine (imp : impRest) = - let l2 = getStartLineUnsafe imp in + let + lStart = getStartLineUnsafe imp + lEnd = getEndLineUnsafe imp in case mbCurrentLine of - Just l1 | l1 + 1 < l2 -> ne acc ++ go [imp] (Just l2) impRest - _ -> go (acc ++ [imp]) (Just l2) impRest + Just lPrevEnd | lPrevEnd + 1 < lStart + -> ne acc ++ go [imp] (Just lEnd) impRest + _ -> go (acc ++ [imp]) (Just lEnd) impRest ne [] = [] ne (x : xs) = [x :| xs] |