lspitzner / brittany

haskell source code formatter
GNU Affero General Public License v3.0
692 stars 72 forks source link

Indents on `where` clauses don't always follow the brittany.yaml settings (4-spaces) #336

Closed j127 closed 3 years ago

j127 commented 3 years ago

What I expect to happen: 4-space indentation

What actually happens: 2-space indentation for multi-line where clauses (while everything else has 4 spaces, including single-line where clauses)

Versions:

My brittany.yaml file contains the line:

lconfig_indentAmount: 4

Everything works great so far, except in one case. When I run brittany on this code:

solveRPN :: (Num a, Read a) => String -> a
solveRPN = head . foldl foldingFunction [] . words
    where
        foldingFunction (x : y : ys) "*"          = (x * y) : ys
        foldingFunction (x : y : ys) "+"          = (x + y) : ys
        foldingFunction (x : y : ys) "-"          = (y - x) : ys
        foldingFunction xs           numberString = read numberString : xs

brittany changes it to 2-space indentation:

solveRPN :: (Num a, Read a) => String -> a
solveRPN = head . foldl foldingFunction [] . words
  where
    foldingFunction (x : y : ys) "*"          = (x * y) : ys
    foldingFunction (x : y : ys) "+"          = (x + y) : ys
    foldingFunction (x : y : ys) "-"          = (y - x) : ys
    foldingFunction xs           numberString = read numberString : xs

It looks like it only happens for where clauses when there are multiple lines. When there is just one line, it correctly indents by 4 spaces:

calcBmis :: (RealFloat a) => [(a, a)] -> [a]
calcBmis xs = [ bmi w h | (w, h) <- xs ]
    where bmi weight height = weight / height ^ 2

If I change that code to 2 spaces and run brittany on it, it correctly re-indents it with 4 spaces (based on my config file).

tfausak commented 3 years ago

I think you can avoid this by setting lconfig_indentWhereSpecial: false. See #39 and #188.

j127 commented 3 years ago

Thanks, that fixed it.

(Sorry, I had searched through the issues before posting but didn't see those.)