From 3a5ec324a426f0207ae895471b5c52d21f893859 Mon Sep 17 00:00:00 2001 From: Matthew Kennerly Date: Tue, 28 Nov 2017 06:44:43 -0500 Subject: Avoid unpaired parenthesis when import doesn't specify any items Fix #185 --- lib/Language/Haskell/Stylish/Step/Imports.hs | 6 +++++- tests/Language/Haskell/Stylish/Step/Imports/Tests.hs | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/Language/Haskell/Stylish/Step/Imports.hs b/lib/Language/Haskell/Stylish/Step/Imports.hs index 2284f3d..927719c 100644 --- a/lib/Language/Haskell/Stylish/Step/Imports.hs +++ b/lib/Language/Haskell/Stylish/Step/Imports.hs @@ -311,7 +311,11 @@ prettyImport columns Options{..} padQualified padName longest imp ( mapSpecs ( withHead ("( " ++) . withTail (", " ++)) - ++ [")"]) + ++ closer) + where + closer = if null importSpecs + then [] + else [")"] paddedBase = base $ padImport $ compoundImportName imp diff --git a/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs b/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs index bc6772c..67c7c5a 100644 --- a/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs +++ b/tests/Language/Haskell/Stylish/Step/Imports/Tests.hs @@ -52,6 +52,7 @@ tests = testGroup "Language.Haskell.Stylish.Step.Imports.Tests" , testCase "case 23" case23 , testCase "case 24" case24 , testCase "case 25" case25 + , testCase "case 26 (issue 185)" case26 ] @@ -663,3 +664,17 @@ case25 = expected , "" , "import Data.Foo (Foo (Foo,Bar), Goo(Goo))" ] + + +-------------------------------------------------------------------------------- +case26 :: Assertion +case26 = expected + @=? testStep (step 80 options ) input' + where + options = defaultOptions { listAlign = NewLine, longListAlign = Multiline } + input' = unlines + [ "import Data.List" + ] + expected = unlines + [ "import Data.List" + ] -- cgit v1.2.3