You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
cabal init generates .cabal file with very long lines for fields like other-extensions, exposed-modules and build-depends. Fixing this by hand is tedious. Cabal format helps, but that's hard to discover (#2460). Ideally I think cabal should format the file before automatically.
I personally prefer formatting of cabal init command so I wouldn't call it a badly formatted file. And in all my projects I format .cabal files in the style of cabal init (with alignment). I never heard of cabal format command before but after I tried this command now I see that there's no benefit in the cabal format formatting for me and I don't like the style of cabal format. So I'm voting for leaving cabal init formatting as it is.
The format command simply calls readGenericPackageDescription followed by writeGenericPackageDescription. I don't think those existed when I first wrote cabal init. Right now, cabal init does its own pretty-printing; I think the correct solution would be to instead create a GenericPackageDescription and then call writeGenericPackageDescription, so it uses the same code path as cabal format.
Hmm, actually, how do read/writeGenericPackageDescription deal with comments? As far as I can see the answer seems to be "they don't", which seems problematic from the point of view of cabal init...
Activity
23Skidoo commentedon Aug 31, 2018
/cc @byorgey
chshersh commentedon Sep 1, 2018
I personally prefer formatting of
cabal initcommand so I wouldn't call it a badly formatted file. And in all my projects I format.cabalfiles in the style ofcabal init(with alignment). I never heard ofcabal formatcommand before but after I tried this command now I see that there's no benefit in thecabal formatformatting for me and I don't like the style ofcabal format. So I'm voting for leavingcabal initformatting as it is.osa1 commentedon Sep 1, 2018
Just to clarify, this is what
cabal initgenerates:This is unusable without formatting first. Compare with
cabal formatoutput:chshersh commentedon Sep 2, 2018
@osa1 My bad, I haven't understand your ticket good enough. Yeah, I don't like long lists with dependencies as well.
byorgey commentedon Feb 3, 2019
The
formatcommand simply callsreadGenericPackageDescriptionfollowed bywriteGenericPackageDescription. I don't think those existed when I first wrotecabal init. Right now,cabal initdoes its own pretty-printing; I think the correct solution would be to instead create aGenericPackageDescriptionand then callwriteGenericPackageDescription, so it uses the same code path ascabal format.byorgey commentedon Feb 3, 2019
Hmm, actually, how do
read/writeGenericPackageDescriptiondeal with comments? As far as I can see the answer seems to be "they don't", which seems problematic from the point of view ofcabal init...23Skidoo commentedon Feb 4, 2019
Correct, we don't have exactprint yet.
phadej commentedon Feb 4, 2019
One could extend https://github.com/haskell/cabal/blob/master/Cabal/Distribution/Fields/Pretty.hs with annotations, it's how I did in https://github.com/phadej/cabal-fmt/blob/master/src/CabalFmt/PrettyField.hs to add comments.