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
{{ message }}
Repository navigation
cabal format adds empty lines with trailing whitespace #1966
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.
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.
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:
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 "".
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)
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.
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.
Activity
ddssff commentedon Jun 26, 2014
I think this might be the same as #1921
23Skidoo commentedon Aug 2, 2014
The
Text.PrettyPrintmodule 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 iscabal init.osa1 commentedon Mar 9, 2015
Cabal file generators(
cabal format,cabal init, probably some other commands?) always do this. As also pointed out by @23Skidoo this is related withprettylibrary, which generates trailing space if we have a code likenest 4 (text "" $+$ ...).I can think several solutions:
prettylibrary and add a newEmptyLineconstructor toDoc, then handle that in vertical composition functions specially to not generate any whitespace, only generate a "\n". Then we can useemptyLineinstead oftext "".text ""insidenest. (this is probably very hard to do, and resulting code may not be very good)writeCabalFileandwriteGenericPackageDescriptionwith 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?
23Skidoo commentedon Mar 9, 2015
I like option (1) best, (3) could be a temporary workaround.
osa1 commentedon Mar 14, 2015
I implemented (1), but I need some reviewers. I'm trying to get in contact with
prettymaintainers, hopefully we can fix this in a principled way.23Skidoo commentedon Mar 14, 2015
@osa1 Great, thank you for working on this.
byorgey commentedon Mar 30, 2015
What's the status of this? @osa1 , can you post here a link to your implementation of (1)?
osa1 commentedon Mar 30, 2015
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 newDocconstructor, 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.gbaz commentedon Nov 27, 2018
Is this resolved?
phadej commentedon Nov 27, 2018
Not yet. #5737 resolve this though.
jneira commentedon Jul 15, 2021
#5737 is merged so I am gonna close it, @tibbe feel free to reopen if it is not resolved for you