Format pattern matching with purty

Hi! If I open a purs source code file purty adds an empty line between different cases, for example:

input:

module Test.MySolutions where

import Prelude
import Data.Maybe (Maybe(..))

safeDivide::Int -> Int->Maybe Int
safeDivide _ 0 = Nothing
safeDivide a b = Just (a/b)

output of > purty MySolutions.purs:

module Test.MySolutions where

import Prelude
import Data.Maybe (Maybe(..))

safeDivide :: Int -> Int -> Maybe Int
safeDivide _ 0 = Nothing

safeDivide a b = Just (a / b)

The same is happening for other files like in Ch8 Validation.purs. I have tried with purty 6.3.0 and 6.2.1 and there is nothing to configure with this tool, is there?
Any help would be appreciated.

Yep, this is a common gripe with purty.

Tracked in https://gitlab.com/joneshf/purty/-/issues/77

ok, “Opened 2 years ago”, no workaround was provided in this ticket. I don’t know how other people have solved this. My workaround was adding Regex-post-processing to the purty call script with:

const purty = childProcess.spawn(purtyPath, args, { stdio: ['inherit', 'pipe', 'inherit'] });

purty.stdout.on('data', (data) => {
    let text = `${data}`;
    let wordWord = /^(\s*\w+[']* )(.+)\n\n\1/gm
    /* matches 
     *word something 
     *
     *word 
    */
    while (text.match(wordWord)) {
        text = text.replace(wordWord, "$1$2\n$1");
    }
    text = text.replace(/^([ ]+_)\n[ ]+(\| )/gm, "$1 $2");
    /* matches
     * _
     *  | 
    */
    console.log(text);
});
3 Likes