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

Rename constructors and related parser strings of LongListAlign #467

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
5 changes: 5 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

- Unreleased
* #467 Rename constructors of LongListAlign to better reflect implmentatnion (by sorki)
* InlineToBreak is now InlineToNewline
* InlineToMultiline is now InlineToNewlineToMultiline

- 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
20 changes: 16 additions & 4 deletions data/stylish-haskell.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,26 @@ steps:
#
# - inline: This option will put as much specs on same line as possible.
#
# - new_line: Import list will start on new line.
# - new_line: Import list will start on new line when it wouldn't fit
# to single line. (deprecated, renamed to inline_to_new_line)
#
# - new_line_multiline: Import list will start on new line when it's
# short enough to fit to single line. Otherwise it'll be multiline.
# - inline_to_new_line: Import list will start on new line when it
# wouldn't fit to single line.
#
# - multiline: One line per import list entry.
# - new_line_multiline: Import list will be put inline if it fits
# or put on new line when it's short enough to fit to single
# line. Otherwise it'll be multiline.
# (deprecated, renamed to inline_to_new_line_to_multiline)
#
# - inline_to_new_line_to_multiline: Import list will be put inline if
# it fits or put on new line when it's short enough to fit to single
# line. Otherwise it'll be multiline.
#
# - multiline: Inline if import list is short enough to fit, otherwise
# one line per import list entry.
# Type with constructor list acts like single import.
#
# > import Data.Map (Map)
# > import qualified Data.Map as M
# > ( empty
# > , singleton
Expand Down
12 changes: 8 additions & 4 deletions lib/Language/Haskell/Stylish/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -311,10 +311,14 @@ parseImports config o = fmap (Imports.step columns) $ Imports.Options
]

longListAligns =
[ ("inline", Imports.Inline)
, ("new_line", Imports.InlineWithBreak)
, ("new_line_multiline", Imports.InlineToMultiline)
, ("multiline", Imports.Multiline)
[ ("inline", Imports.Inline)
, ("new_line", Imports.InlineToNewline)
-- ^ deprecated
, ("inline_to_new_line", Imports.InlineToNewline)
, ("new_line_multiline", Imports.InlineToNewlineToMultiline)
-- ^ deprecated
, ("inline_to_new_line_to_multiline", Imports.InlineToNewlineToMultiline)
, ("multiline", Imports.Multiline)
]

emptyListAligns =
Expand Down
8 changes: 4 additions & 4 deletions lib/Language/Haskell/Stylish/Step/Imports.hs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ data EmptyListAlign

data LongListAlign
= Inline -- inline
| InlineWithBreak -- new_line
| InlineToMultiline -- new_line_multiline
| InlineToNewline -- inline_to_new_line (or deprecated new_line)
| InlineToNewlineToMultiline -- inline_to_new_line_to_multiline (or deprecated new_line_multiline)
| Multiline -- multiline
deriving (Eq, Show)

Expand Down Expand Up @@ -483,12 +483,12 @@ printQualified Options{..} padNames stats ldecl = do
modifyCurrentLine trimRight
newline >> putOffset >> printAsInlineWrapping (putText wrapPrefix)
Inline -> space >> printAsInlineWrapping (putText wrapPrefix)
InlineWithBreak -> wrapping
InlineToNewline -> wrapping
(space >> printAsSingleLine)
(do
modifyCurrentLine trimRight
newline >> putOffset >> printAsInlineWrapping putOffset)
InlineToMultiline -> wrapping
InlineToNewlineToMultiline -> wrapping
(space >> printAsSingleLine)
(wrapping
(do
Expand Down
18 changes: 9 additions & 9 deletions tests/Language/Haskell/Stylish/Step/Imports/Tests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ case13 =
options = defaultOptions
{ importAlign = None
, listAlign = WithAlias
, longListAlign = InlineWithBreak
, longListAlign = InlineToNewline
}
in
assertSnippet (step (Just 80) options)
Expand All @@ -438,7 +438,7 @@ case13b =
options = defaultOptions
{ importAlign = None
, listAlign = WithModuleName
, longListAlign = InlineWithBreak
, longListAlign = InlineToNewline
}
in
assertSnippet (step (Just 80) options)
Expand All @@ -458,7 +458,7 @@ case14 =
options = defaultOptions
{ importAlign = None
, listAlign = WithAlias
, longListAlign = InlineWithBreak
, longListAlign = InlineToNewline
, listPadding = LPConstant 10
}
in
Expand Down Expand Up @@ -542,7 +542,7 @@ case17 =
case18 :: Assertion
case18 =
let
options = defaultOptions { importAlign = None, longListAlign = InlineToMultiline }
options = defaultOptions { importAlign = None, longListAlign = InlineToNewlineToMultiline }
in
assertSnippet (step (Just 40) options)
[ "import Data.Foo as Foo (Bar, Baz, Foo)"
Expand Down Expand Up @@ -571,7 +571,7 @@ case19 =
let
options = defaultOptions
{ listAlign = NewLine
, longListAlign = InlineWithBreak
, longListAlign = InlineToNewline
, emptyListAlign = RightAfter
, listPadding = LPConstant 17
}
Expand All @@ -593,7 +593,7 @@ case19b =
options = defaultOptions
{ importAlign = File
, listAlign = NewLine
, longListAlign = InlineWithBreak
, longListAlign = InlineToNewline
, emptyListAlign = RightAfter
, listPadding = LPConstant 17
}
Expand All @@ -614,7 +614,7 @@ case19c =
options = defaultOptions
{ importAlign = File
, listAlign = NewLine
, longListAlign = InlineWithBreak
, longListAlign = InlineToNewline
, emptyListAlign = RightAfter
, listPadding = LPModuleName
}
Expand All @@ -634,7 +634,7 @@ case19d =
let
options = defaultOptions
{ listAlign = NewLine
, longListAlign = InlineWithBreak
, longListAlign = InlineToNewline
, emptyListAlign = RightAfter
, listPadding = LPModuleName
}
Expand Down Expand Up @@ -792,7 +792,7 @@ case24 =
options = defaultOptions
{ importAlign = None
, padModuleNames = False
, longListAlign = InlineWithBreak
, longListAlign = InlineToNewline
, spaceSurround = True
}
in
Expand Down