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

Add MultilineOnly LostListAlign variant #468

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# CHANGELOG

- Unreleased
* #468 Add MultilineOnly LongListAlign variant (by sorki)

- 0.14.5.0 (2023-06-23)
* #459 Support GHC 9.6 (By Michael Peyton Jones)
* #445 Default `ghc-lib` flag to True (by amesgen)
Expand Down
2 changes: 2 additions & 0 deletions data/stylish-haskell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ steps:
# > , delete
# > )
#
# - multiline_only: One line per import entry.
#
# Default: inline
long_list_align: inline

Expand Down
1 change: 1 addition & 0 deletions lib/Language/Haskell/Stylish/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ parseImports config o = fmap (Imports.step columns) $ Imports.Options
, ("new_line", Imports.InlineWithBreak)
, ("new_line_multiline", Imports.InlineToMultiline)
, ("multiline", Imports.Multiline)
, ("multiline_only", Imports.MultilineOnly)
]

emptyListAligns =
Expand Down
2 changes: 2 additions & 0 deletions lib/Language/Haskell/Stylish/Step/Imports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ data LongListAlign
| InlineWithBreak -- new_line
| InlineToMultiline -- new_line_multiline
| Multiline -- multiline
| MultilineOnly -- multiline_only
deriving (Eq, Show)

-- | A rule for grouping imports that specifies which module names
Expand Down Expand Up @@ -479,6 +480,7 @@ printQualified Options{..} padNames stats ldecl = do
Multiline -> wrapping
(space >> printAsSingleLine)
printAsMultiLine
MultilineOnly -> printAsMultiLine
Inline | NewLine <- listAlign -> do
modifyCurrentLine trimRight
newline >> putOffset >> printAsInlineWrapping (putText wrapPrefix)
Expand Down
31 changes: 31 additions & 0 deletions tests/Language/Haskell/Stylish/Step/Imports/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ tests = testGroup "Language.Haskell.Stylish.Step.Imports.Tests"
, testCase "case 16" case16
, testCase "case 17" case17
, testCase "case 18" case18
, testCase "case 18b" case18b
, testCase "case 19" case19
, testCase "case 19b" case19b
, testCase "case 19d" case19c
Expand Down Expand Up @@ -564,6 +565,36 @@ case18 =
, " )"
]

case18b :: Assertion
case18b =
let
options = defaultOptions { importAlign = None, longListAlign = MultilineOnly }
in
assertSnippet (step (Just 40) options)
[ "import Data.Foo as Foo (Bar, Baz, Foo)"
, ""
, "import Data.Identity (Identity (Identity, runIdentity))"
, ""
, "import Data.Acid as Acid (closeAcidState, createCheckpoint, openLocalStateFrom)"
]
----------------------------------------
[ "import Data.Foo as Foo"
, " ( Bar"
, " , Baz"
, " , Foo"
, " )"
, ""
, "import Data.Identity"
, " ( Identity (Identity, runIdentity)"
, " )"
, ""
, "import Data.Acid as Acid"
, " ( closeAcidState"
, " , createCheckpoint"
, " , openLocalStateFrom"
, " )"
]


--------------------------------------------------------------------------------
case19 :: Assertion
Expand Down