-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Strip trailing whitespace #1422
Conversation
e3df29c
to
bb39d0b
Compare
Prettyprinter 1.4 is released! |
For the update to |
There's no compatible |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! 🙂
I just noticed that we can have trailing whitespace in multi-line strings, which this patch would remove. What would be the best way to preserve that whitespace? We could put it into interpolations, like this:
|
@sjakobi: I think the simplest way to fix this is to change this pull request to have My reasoning is that However, I could see In fact, I actually think we could treat it as a feature if |
@sjakobi: Note that there is a downside of my proposal which is:
... so I'm still not sure what's the best way to fix that. However, I still think that |
Right, I agree that Since it is the pretty-printing that usually adds the trailing whitespace in the first place, I also believe that any fix to #183 must involve stripping whitespace as a part of But changing e.g. Whether we change |
@sjakobi: It isn't a semantic change, but it is a syntactic change. Up until now |
I see. I thought that
I don't see many options though:
My preference is (3) – a semantic change would be bad, but a purely syntactic change in rather rare circumstances, that doesn't affect the hash, should be fine. |
@sjakobi: I still have reservations about putting trailing whitespace in string interpolations. That seems even worse than trailing whitespace outside of them and a regression compared to the status quo. I think the status quo is the least bad option until we can figure out how to fix this properly |
Oh, I'm wondering whether we're talking about the same thing here! I'm definitely not arguing for the whitespace accidentally added by
I'm arguing that this should be formatted as
Do you still see a problem with this? |
@sjakobi: Yeah, I understand. I just think it's going to be very jarring for users to see trailing whitespace preserved in that way |
Ah, ok – I'm a bit surprised though, because I wouldn't expect users to actually want that whitespace in the first place. Once the interpolations make it more visible, I'd expect them to usually just remove it. What do you think about option 1 then:
I also wonder whether we should change the standard to disallow trailing whitespace in multi-line text literals. |
@sjakobi: I don't think we should modify the standard just to work around a limitation specification the Haskell implementation. This seems like something that we should be able to fix with a bit more work on our end. For example, the |
Well, that sounds like a very good idea! 👍 |
Oh, boy! I had completely forgotten that text literals are already annotated with I'll just try to tweak this so if we have an empty line in a multi-line text literal, the whitespace added by prettyprinter up to the indentation level is removed. I'll also add a test. |
@sjakobi: No worries! 🙂 |
@@ -0,0 +1,7 @@ | |||
{ x = | |||
'' | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's trailing whitespace on this line, but GitHub doesn't seem to display it unlike the trailing whitespace after foo
on line 5.
nix/shared.nix
Outdated
@@ -393,6 +393,10 @@ let | |||
haskellPackagesNew.semigroups | |||
]; | |||
|
|||
hnix = | |||
pkgsNew.haskell.lib.doJailbreak | |||
haskellPackagesOld.hnix; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I thought that this would allow hnix
to be built with prettyprinter-1.5.1
, but Hydra seems to disagree:
Configuring hnix-0.6.1...
CallStack (from HasCallStack):
die', called at libraries/Cabal/Cabal/Distribution/Simple/Configure.hs:958:20 in Cabal-2.2.0.1:Distribution.Simple.Configure
configureFinalizedPackage, called at libraries/Cabal/Cabal/Distribution/Simple/Configure.hs:462:12 in Cabal-2.2.0.1:Distribution.Simple.Configure
configure, called at libraries/Cabal/Cabal/Distribution/Simple.hs:596:20 in Cabal-2.2.0.1:Distribution.Simple
confHook, called at libraries/Cabal/Cabal/Distribution/Simple/UserHooks.hs:67:5 in Cabal-2.2.0.1:Distribution.Simple.UserHooks
configureAction, called at libraries/Cabal/Cabal/Distribution/Simple.hs:178:19 in Cabal-2.2.0.1:Distribution.Simple
defaultMainHelper, called at libraries/Cabal/Cabal/Distribution/Simple.hs:115:27 in Cabal-2.2.0.1:Distribution.Simple
defaultMain, called at Setup.hs:2:8 in main:Main
Setup: Encountered missing dependencies:
prettyprinter >=1.2.1 && <1.3
Could you take a look @Gabriel439?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sjakobi: I pushed a change to fix the Nix build
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @Gabriel439! :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sjakobi: You're welcome! 🙂
Fixes #183.
This supersedes #955.
TODO:
layoutSmart
.dhall diff
handles trailing whitespace in multi-line strings correctly.