Skip to content

cabal format adds empty lines with trailing whitespace #1966

Closed

Description

@tibbe

If you run cabal format on e.g. in the cabal-install/ directory, you'll see that cabal format adds empty lines with trailing whitespace (i.e. 4 spaces). It shouldn't do that.

Activity

  1. ddssff commented on Jun 26, 2014

    @ddssff
    Contributor

    I think this might be the same as #1921

  2. 23Skidoo commented on Aug 2, 2014

    @23Skidoo
    Member

    The Text.PrettyPrint module may be the cause of the problem - it doesn't do a very good job of avoiding trailing whitespace. Which can be annoying - one example is cabal init.

  3. osa1 commented on Mar 9, 2015

    @osa1

    Cabal file generators(cabal format, cabal init, probably some other commands?) always do this. As also pointed out by @23Skidoo this is related with pretty library, which generates trailing space if we have a code like nest 4 (text "" $+$ ...).

    I can think several solutions:

    1. We can modify pretty library and add a new EmptyLine constructor to Doc, then handle that in vertical composition functions specially to not generate any whitespace, only generate a "\n". Then we can use emptyLine instead of text "".
    2. We can make significant refactoring in Cabal pretty printer to not have any text "" inside nest. (this is probably very hard to do, and resulting code may not be very good)
    3. We can wrap writeCabalFile and writeGenericPackageDescription with a function that removes trailing white space with the cost of an extra copy.

    (3) seems to be the easiest solution, however I think (1) is the best, because as far as I can understand from the API docs of pretty, it doesn't provide a way to insert newlines, without having them indented and this seems to be a limitation of the library.

    What do you think? Should we go with (3) for now?

  4. 23Skidoo commented on Mar 9, 2015

    @23Skidoo
    Member

    I like option (1) best, (3) could be a temporary workaround.

  5. osa1 commented on Mar 14, 2015

    @osa1

    I implemented (1), but I need some reviewers. I'm trying to get in contact with pretty maintainers, hopefully we can fix this in a principled way.

  6. 23Skidoo commented on Mar 14, 2015

    @23Skidoo
    Member

    @osa1 Great, thank you for working on this.

  7. byorgey commented on Mar 30, 2015

    @byorgey
    Member

    What's the status of this? @osa1 , can you post here a link to your implementation of (1)?

  8. osa1 commented on Mar 30, 2015

    @osa1

    I feel like it's trivial to implement for someone who knows internals of pretty, and I asked for help here haskell/pretty#26 because I don't know the internals, and lack of documentation is a problem. Main problem is that even though it's possible to do without adding any new Doc constructor, some internals, documentation and maybe even invariants need to be changed, and it's not trivial for me to figure out what to change. I think I can spare some time for this after tomorrow.

  9. added this to the milestone on Apr 24, 2015
  10. modified the milestones: cabal-install 1.24, on Feb 21, 2016
  11. modified the milestone: cabal-install 2.0 on Sep 6, 2016
  12. gbaz commented on Nov 27, 2018

    @gbaz
    Collaborator

    Is this resolved?

  13. phadej commented on Nov 27, 2018

    @phadej
    Collaborator

    Not yet. #5737 resolve this though.

  14. jneira commented on Jul 15, 2021

    @jneira
    Member

    #5737 is merged so I am gonna close it, @tibbe feel free to reopen if it is not resolved for you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions