summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorOndřej Janošík <j.ondra14@gmail.com>2015-09-21 00:25:10 +0200
committerOndřej Janošík <j.ondra14@gmail.com>2015-09-21 00:25:10 +0200
commit1637b47a9c773b870ac39c773c72d9dd6e01412b (patch)
tree86d568f269a24ccc4dcd7b8f909d3a37c0d6c263 /src
parent96a1d05eb0738042c771d4b2ac7fd1f2801d2935 (diff)
downloadstylish-haskell-1637b47a9c773b870ac39c773c72d9dd6e01412b.tar.gz
Fixed some hlint warnings
Diffstat (limited to 'src')
-rw-r--r--src/Language/Haskell/Stylish/Step/Imports.hs21
-rw-r--r--src/Language/Haskell/Stylish/Util.hs6
2 files changed, 15 insertions, 12 deletions
diff --git a/src/Language/Haskell/Stylish/Step/Imports.hs b/src/Language/Haskell/Stylish/Step/Imports.hs
index 17bc746..db4e63e 100644
--- a/src/Language/Haskell/Stylish/Step/Imports.hs
+++ b/src/Language/Haskell/Stylish/Step/Imports.hs
@@ -10,8 +10,10 @@ module Language.Haskell.Stylish.Step.Imports
--------------------------------------------------------------------------------
+
import Control.Arrow ((&&&))
import Data.Char (toLower)
+import Data.Functor ((<$>))
import Data.List (intercalate, sortBy)
import Data.Maybe (isJust, maybeToList)
import Data.Ord (comparing)
@@ -91,7 +93,7 @@ compareImportSpecs = comparing key
--------------------------------------------------------------------------------
-- | Sort the input spec list inside an 'H.ImportDecl'
sortImportSpecs :: H.ImportDecl l -> H.ImportDecl l
-sortImportSpecs imp = imp {H.importSpecs = fmap sort' $ H.importSpecs imp}
+sortImportSpecs imp = imp {H.importSpecs = sort' <$> H.importSpecs imp}
where
sort' (H.ImportSpecList l h specs) = H.ImportSpecList l h $
sortBy compareImportSpecs specs
@@ -161,16 +163,16 @@ prettyImport columns Align{..} padQualified padName longest imp =
AfterAlias -> withTail (' ' :)
. wrap columns paddedBase (afterAliasBaseLength + 1)
- inlineWithBreakWrap = paddedNoSpecBase : (wrapRest columns listPadding
- $ mapSpecs
+ inlineWithBreakWrap = paddedNoSpecBase : wrapRest columns listPadding
+ ( mapSpecs
$ withInit (++ ",")
. withHead ("(" ++)
. withLast (++ ")"))
-- 'wrapRest 0' ensures that every item of spec list is on new line.
- multilineWrap = paddedNoSpecBase : (wrapRest 0 listPadding
- $ (mapSpecs
- $ withHead ("( " ++)
+ multilineWrap = paddedNoSpecBase : wrapRest 0 listPadding
+ ( mapSpecs
+ ( withHead ("( " ++)
. withTail (", " ++))
++ [")"])
@@ -189,7 +191,7 @@ prettyImport columns Align{..} padQualified padName longest imp =
base' baseName importAs hasHiding' = unwords $ concat $ filter (not . null)
[ ["import"]
, qualified
- , (fmap show $ maybeToList $ H.importPkg imp)
+ , show <$> maybeToList (H.importPkg imp)
, [baseName]
, importAs
, hasHiding'
@@ -197,7 +199,7 @@ prettyImport columns Align{..} padQualified padName longest imp =
base baseName = base' baseName
["as " ++ as | H.ModuleName _ as <- maybeToList $ H.importAs imp]
- (if hasHiding then (["hiding"]) else [])
+ ["hiding" | hasHiding]
inlineBaseLength = length $ base' (padImport $ importName imp) [] []
@@ -251,11 +253,12 @@ step columns = makeStep "Imports" . step' columns
--------------------------------------------------------------------------------
step' :: Int -> Align -> Lines -> Module -> Lines
-step' columns align ls (module', _) = flip applyChanges ls
+step' columns align ls (module', _) = applyChanges
[ change block $ const $
prettyImportGroup columns align fileAlign longest importGroup
| (block, importGroup) <- groups
]
+ ls
where
imps = map sortImportSpecs $ imports $ fmap linesFromSrcSpan module'
longest = longestImport imps
diff --git a/src/Language/Haskell/Stylish/Util.hs b/src/Language/Haskell/Stylish/Util.hs
index 39add70..ed5de91 100644
--- a/src/Language/Haskell/Stylish/Util.hs
+++ b/src/Language/Haskell/Stylish/Util.hs
@@ -73,7 +73,7 @@ wrap :: Int -- ^ Maximum line width
-> Int -- ^ Indentation
-> [String] -- ^ Strings to add/wrap
-> Lines -- ^ Resulting lines
-wrap maxWidth leading ind strs' = wrap' leading strs'
+wrap maxWidth leading ind = wrap' leading
where
wrap' ss [] = [ss]
wrap' ss (str:strs)
@@ -112,14 +112,14 @@ withHead f (x : xs) = f x : xs
--------------------------------------------------------------------------------
withLast :: (a -> a) -> [a] -> [a]
withLast _ [] = []
-withLast f (x : []) = [f x]
+withLast f [x] = [f x]
withLast f (x : xs) = x : withLast f xs
--------------------------------------------------------------------------------
withInit :: (a -> a) -> [a] -> [a]
withInit _ [] = []
-withInit _ (x : []) = [x]
+withInit _ [x] = [x]
withInit f (x : xs) = f x : withInit f xs
--------------------------------------------------------------------------------