Skip to content

cabal init generates badly formatted file #5555

Open

Description

@osa1

(tried with cabal installed from master branch)

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.

Activity

  1. 23Skidoo commented on Aug 31, 2018

    @23Skidoo
    Member
  2. chshersh commented on Sep 1, 2018

    @chshersh
    Member

    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.

  3. osa1 commented on Sep 1, 2018

    @osa1
    Author

    Just to clarify, this is what cabal init generates:

    build-depends:       base >=4.11 && <4.12, QuickCheck >=2.11 && <2.12, hashable >=1.2 && <1.3, containers >=0.5 && <0.6, fingertree >=0.1 && <0.2, stm >=2.4 && <2.5, random >=1.1 && <1.2, text >=1.2 && <1.3, bytestring >=0.10 && <0.11, async >=2.2 && <2.3, transformers >=0.5 && <0.6, directory >=1.3 && <1.4, filepath >=1.4 && <1.5, free >=5.1 && <5.2
    

    This is unusable without formatting first. Compare with cabal format output:

        build-depends:
            base >=4.11 && <4.12,
            QuickCheck >=2.11 && <2.12,
            hashable >=1.2 && <1.3,
            containers >=0.5 && <0.6,
            fingertree >=0.1 && <0.2,
            stm >=2.4 && <2.5,
            random >=1.1 && <1.2,
            text >=1.2 && <1.3,
            bytestring >=0.10 && <0.11,
            async >=2.2 && <2.3,
            transformers >=0.5 && <0.6,
            directory >=1.3 && <1.4,
            filepath >=1.4 && <1.5,
            free >=5.1 && <5.2
    
  4. chshersh commented on Sep 2, 2018

    @chshersh
    Member

    @osa1 My bad, I haven't understand your ticket good enough. Yeah, I don't like long lists with dependencies as well.

  5. byorgey commented on Feb 3, 2019

    @byorgey
    Member

    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.

  6. byorgey commented on Feb 3, 2019

    @byorgey
    Member

    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...

  7. 23Skidoo commented on Feb 4, 2019

    @23Skidoo
    Member

    Correct, we don't have exactprint yet.

  8. self-assigned this
    on Apr 4, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions