hfmt icon indicating copy to clipboard operation
hfmt copied to clipboard

Take Cabal default-extensions into account

Open eschnett opened this issue 7 years ago • 1 comments

I just received this error message from hfmt:

$ hfmt lib/Category.hs
"Error reformatting lib/Category.hs: Error in stylish-haskell: Language.Haskell.Stylish.Parse.parseModule: could not parse lib/Category.hs: ParseFailed (SrcLoc \"<unknown>.hs\" 19 27) \"DataKinds language extension is not enabled. Please add {-# LANGUAGE DataKinds #-} pragma at the top of your module.\""

I have a .cabal file in my project that lists a large number of extensions

  default-extensions: ApplicativeDo BangPatterns BinaryLiterals ConstraintKinds DataKinds DefaultSignatures DeriveFoldable DeriveFunctor DeriveGeneric DeriveLift DeriveTraversable DerivingStrategies EmptyCase ExistentialQuantification FlexibleContexts FlexibleInstances FunctionalDependencies GADTs GeneralizedNewtypeDeriving InstanceSigs KindSignatures LambdaCase MultiParamTypeClasses MultiWayIf NamedFieldPuns OverloadedLists OverloadedStrings ParallelListComp PatternSynonyms RankNTypes ScopedTypeVariables StandaloneDeriving TupleSections TypeApplications TypeFamilies TypeFamilyDependencies TypeOperators TypeSynonymInstances UnicodeSyntax AllowAmbiguousTypes MonadComprehensions PackageImports PolyKinds TypeInType

It would be convenient if hfmt was taking these into account.

eschnett avatar Jan 01 '19 19:01 eschnett

Agreed that would be convenient. However hfmt is just a wrapper of some existing libraries, so I depend on them having support for this kind of thing. In this case I believe there is already an open issue about adding support for hpack's default-extensions field to stylish-haskell: https://github.com/jaspervdj/stylish-haskell/issues/138

If that gets solves in stylish-haskell it will also fix hfmt. I haven't been doing much Haskell lately so I probably won't take the lead on that, but I'm sure stylish-haskell would be open to a contribution!

danstiner avatar Feb 18 '19 00:02 danstiner