stylish-haskell
stylish-haskell copied to clipboard
Trailing whitespace is trimmed inside quasiquotes
The meaning of this program is changed by running stylish-haskell
over it. Note the trailing space character in the first line of the quasiquote.
{-# LANGUAGE QuasiQuotes #-}
import Acme.Missiles
import Text.RawString.QQ
main = do
let -- Space based nuclear defense.
l = length [r|
|]
if l == 1
then launchMissiles
else putStrLn "Phew..."
I'm not sure if this issue is severe enough to be fixed. Most people who rely on whitespace usually have sort of highlighting in their editor, and so they would notice the removal. You can turn of removing redundant whitespace by tweaking your .stylish-haskell.yaml
.
It seems a shame to have to disable that useful feature in projects which do rely on whitespace in quasiquotes though.
Too be honest, the only use case I can think of is having a whitespace quasiquoter, and even that's very esoteric. I suspect that, in fact, if you are embedding whitespace code into your haskell, not having your imports/data structures formatted is the least of your worries.
That being said, I wouldn't mind having this fixed for the sake of having the property that running stylish-haskell does not change semantics, since that is an extremely powerful property.
I imagine the whitespace remover would run through the haskell-src-exts
AST and, by using the source location annotations, "mark" all the lines that have multiline quasiquoters. Then, the whitespace remover would only take the unmarked lines into account.
I think there are issues with higher priority though, unless it turns out I vastly underestimate the number of quasiquoters that rely on trailing whitespace.
Sure, I don't think it's a high priority, in fact I only bumped into this when stylish-haskell removed whitespace in a qq which I didn't want anyway :).
It might be easier to do this without involving HSE, I think it would be as simple as parsing nested block comments and the quote markers themselves.