floskell 0.10.3 → 0.10.4
raw patch · 8 files changed
+83/−42 lines, 8 filesdep ~aesonPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: aeson
API changes (from Hackage documentation)
Files
- CHANGELOG.md +6/−0
- TEST.md +20/−0
- floskell.cabal +3/−3
- src/Floskell.hs +1/−1
- src/Floskell/Config.hs +18/−9
- src/Floskell/Pretty.hs +24/−21
- src/Floskell/Styles.hs +8/−5
- stack.yaml +3/−3
CHANGELOG.md view
@@ -1,3 +1,9 @@+# Floskell 0.10.4 (2020-08-05)++* Fix formatting of type applications+* Fix for comments hopping over 'where' keyword+* Add safety whitespace override for @ in patterns+ # Floskell 0.10.3 (2020-05-17) * Updated to haskell-src-exts-1.23.0, with support for Block Arguments
TEST.md view
@@ -706,6 +706,16 @@ some expression ``` +## Types++Long types allow linebreaks.++``` haskell+newtype MyMonadT a b m =+ MyMonad { runMyMonad :: StateT ([(a, a -> b)]) (ReaderT a (ExceptT [IM.IntMap b]) (WriterT [IS.IntSet x] m))+ }+```+ ## Patterns Long function pattern matches allow linebreaks.@@ -834,6 +844,16 @@ -- comment 2 %~ -- comment 3 argument -- comment 4+```++Comments after `where` stay there.++``` haskell+consM :: Monad m => m a -> Stream m a -> Stream m a+consM m (Stream step state) = Stream step1 Nothing+ where+ {-# INLINE_LATE step1 #-}+ step1 _ _ = undefined ``` ## Indentation and Line Prefixes
floskell.cabal view
@@ -1,5 +1,5 @@ name: floskell-version: 0.10.3+version: 0.10.4 synopsis: A flexible Haskell source code pretty printer description: A flexible Haskell source code pretty printer. .@@ -13,7 +13,7 @@ category: Development build-type: Simple cabal-version: >=1.10-homepage: https://www.github.com/ennocramer/floskell+homepage: https://github.com/ennocramer/floskell bug-reports: https://github.com/ennocramer/floskell/issues data-files: contrib/floskell.el contrib/floskell.coffee@@ -44,7 +44,7 @@ Floskell.Styles Floskell.Types build-depends: base >=4.9 && <4.15- , aeson >=0.11.3.0 && <1.5+ , aeson >=0.11.3.0 && <1.6 , attoparsec >=0.13.1.0 && <0.14 , bytestring >=0.10.8.1 && <0.11 , containers >=0.5.7.1 && <0.7
src/Floskell.hs view
@@ -149,7 +149,7 @@ Just $ appFixities config ++ builtinFixities } - cfg = styleConfig $ appStyle config+ cfg = safeConfig . styleConfig $ appStyle config reformatLines :: ParseMode -> Config -> Int -> [ByteString] -> Either String [ByteString]
src/Floskell/Config.hs view
@@ -265,9 +265,12 @@ defaultConfig :: Config defaultConfig =- def { cfgOp = OpConfig ((unOpConfig def) { cfgMapOverrides =- Map.fromList opWsOverrides- })+ def { cfgOp = OpConfig ((unOpConfig def) { cfgMapOverrides =+ Map.fromList opWsOverrides+ })+ , cfgGroup = GroupConfig ((unGroupConfig def) { cfgMapOverrides =+ Map.fromList groupWsOverrides+ }) } where opWsOverrides =@@ -280,25 +283,31 @@ ) ] + groupWsOverrides =+ [ (ConfigMapKey (Just "[") (Just Type), Whitespace WsBoth WsNone False)+ ]+ safeConfig :: Config -> Config safeConfig cfg = cfg { cfgGroup = group, cfgOp = op } where group = GroupConfig $ updateOverrides (unGroupConfig $ cfgGroup cfg)- [ ("(#", Expression), ("(#", Pattern) ]+ [ ("(#", Expression, WsBoth), ("(#", Pattern, WsBoth) ] op = OpConfig $- updateOverrides (unOpConfig $ cfgOp cfg) [ (".", Expression) ]+ updateOverrides (unOpConfig $ cfgOp cfg)+ [ (".", Expression, WsBoth), ("@", Pattern, WsNone) ] updateOverrides config overrides = config { cfgMapOverrides = foldl (updateWs config) (cfgMapOverrides config) overrides } - updateWs config m (key, ctx) =- Map.insert (ConfigMapKey (Just key) (Just ctx))- (cfgMapFind ctx key config) { wsSpaces = WsBoth }- m+ updateWs config m (key, ctx, ws) =+ Map.insertWith (flip const)+ (ConfigMapKey (Just key) (Just ctx))+ (cfgMapFind ctx key config) { wsSpaces = ws }+ m cfgMapFind :: LayoutContext -> ByteString -> ConfigMap a -> a cfgMapFind ctx key ConfigMap{..} =
src/Floskell/Pretty.hs view
@@ -143,8 +143,8 @@ to -- | Pretty print a comment.-printComment :: Int -> Comment -> Printer ()-printComment correction Comment{..} = do+printComment :: Int -> (Comment, SrcSpan) -> Printer ()+printComment correction (Comment{..}, nextSpan) = do col <- getNextColumn let padding = max 0 $ srcSpanStartColumn commentSpan + correction - col - 1 case commentType of@@ -158,7 +158,7 @@ write "{-" string commentText write "-}"- when (1 == srcSpanStartColumn commentSpan) $+ when (srcSpanEndLine commentSpan /= srcSpanStartLine nextSpan) $ modify (\s -> s { psEolComment = True }) LineComment -> do write $ BS.replicate padding 32@@ -189,7 +189,7 @@ let correction = case loc of Before -> col - srcSpanStartColumn ssi + 1 After -> col - srcSpanEndColumn ssi + 1- forM_ comments $ printComment correction+ forM_ (zip comments (tail (map commentSpan comments ++ [ssi]))) $ printComment correction -- Write newline before restoring onside indent. eol <- gets psEolComment@@ -715,6 +715,11 @@ mayM_ mp $ withPrefix space aligned write " #-}" +prettyBinds :: Binds NodeInfo -> Printer ()+prettyBinds binds = withIndentBy cfgIndentWhere $ do+ write "where"+ withIndent cfgIndentWhereBinds $ pretty binds+ instance Pretty Module where prettyPrint (Module _ mhead pragmas imports decls) = inter blankline $ catMaybes [ ifNotEmpty prettyPragmas pragmas@@ -963,12 +968,12 @@ pretty pat atTabStop stopRhs pretty rhs- mapM_ pretty mbinds+ mapM_ prettyBinds mbinds prettyPrint (PatSyn _ pat pat' patternsyndirection) = do depend "pattern" $ prettySimpleDecl pat sep pat' case patternsyndirection of- ExplicitBidirectional _ decls -> pretty (BDecls noNodeInfo decls)+ ExplicitBidirectional _ decls -> prettyBinds (BDecls noNodeInfo decls) _ -> return () where sep = case patternsyndirection of@@ -1087,15 +1092,11 @@ prettyPrint (IHApp _ insthead ty) = depend' (pretty insthead) $ pretty ty instance Pretty Binds where- prettyPrint (BDecls _ decls) = withIndentBy cfgIndentWhere $ do- write "where"- withIndent cfgIndentWhereBinds $- withComputedTabStop stopRhs cfgAlignWhere measureDecl decls $- prettyDecls skipBlankDecl DeclWhere decls+ prettyPrint (BDecls _ decls) =+ withComputedTabStop stopRhs cfgAlignWhere measureDecl decls $+ prettyDecls skipBlankDecl DeclWhere decls - prettyPrint (IPBinds _ ipbinds) = withIndentBy cfgIndentWhere $ do- write "where"- withIndent cfgIndentWhereBinds $ linedOnside ipbinds+ prettyPrint (IPBinds _ ipbinds) = linedOnside ipbinds instance Pretty IPBind where prettyPrint (IPBind _ ipname expr) = prettySimpleDecl ipname "=" expr@@ -1256,14 +1257,14 @@ prettyApp name pats atTabStop stopRhs pretty rhs- mapM_ pretty mbinds+ mapM_ prettyBinds mbinds prettyPrint (InfixMatch _ pat name pats rhs mbinds) = do onside $ do withLayout cfgLayoutInfixApp flex vertical atTabStop stopRhs pretty rhs- mapM_ pretty mbinds+ mapM_ prettyBinds mbinds where flex = do pretty pat@@ -1411,10 +1412,12 @@ prettyF (TyParArray _ ty) = group Type "[:" ":]" $ pretty ty - prettyF (TyApp _ ty ty') = do- pretty ty- space- pretty ty'+ prettyF ty@TyApp{} = case flattenApp flatten ty of+ ctor : args -> prettyApp ctor args+ [] -> error "impossible"+ where+ flatten (TyApp _ a b) = Just (a, b)+ flatten _ = Nothing prettyF (TyVar _ name) = pretty name @@ -1893,7 +1896,7 @@ pretty pat atTabStop stopRhs pretty $ GuardedAlts rhs- mapM_ pretty mbinds+ mapM_ prettyBinds mbinds instance Pretty XAttr where prettyPrint (XAttr _ xname expr) = do
src/Floskell/Styles.hs view
@@ -18,7 +18,7 @@ } chrisDoneCfg :: Config-chrisDoneCfg = safeConfig $+chrisDoneCfg = defaultConfig { cfgIndent, cfgLayout, cfgOp, cfgGroup, cfgOptions } where cfgIndent =@@ -90,7 +90,7 @@ } cramerCfg :: Config-cramerCfg = safeConfig $+cramerCfg = defaultConfig { cfgAlign , cfgIndent , cfgLayout@@ -189,6 +189,9 @@ , ( ConfigMapKey (Just "[") (Just Pattern) , Whitespace WsBoth WsAfter False )+ , ( ConfigMapKey (Just "[") (Just Type)+ , Whitespace WsNone WsNone False+ ) ] cfgOptions =@@ -203,7 +206,7 @@ } gibianskyCfg :: Config-gibianskyCfg = safeConfig $+gibianskyCfg = defaultConfig { cfgAlign , cfgIndent , cfgLayout@@ -292,7 +295,7 @@ } johanTibellCfg :: Config-johanTibellCfg = safeConfig $+johanTibellCfg = defaultConfig { cfgIndent, cfgLayout, cfgOp, cfgGroup, cfgOptions } where cfgIndent =@@ -383,7 +386,7 @@ base = Style { styleName = "base" , styleAuthor = "Enno Cramer" , styleDescription = "Configurable formatting style"- , styleConfig = safeConfig defaultConfig+ , styleConfig = defaultConfig } chrisDone :: Style
stack.yaml view
@@ -1,6 +1,6 @@-resolver: lts-14.22+resolver: lts-16.3 packages: - '.' extra-deps:-- haskell-src-exts-1.23.0-- monad-dijkstra-0.1.1.2+- haskell-src-exts-1.23.1+- monad-dijkstra-0.1.1.3