This formater is a fork of stylish-haskell. It has been adapted to strictly apply Smart-Chain Haskell team style. It is therefore not as flexible as stylish-haskell and does not aim to be.
-
Install Nix by going to the Nix download page.
-
Enable Flakes by following this instructions.
-
Enter the Nix shell:
nhenin@ubuntu ~/d/hasklean (main)> nix develop
- Build the project
[nix-shell:~/dev/hasklean]$ cabal build all
- Install for current user:
[nix-shell:~/dev/hasklean]$ install -D $(cabal list-bin hasklean) $HOME/.local/bin/hasklean
-
Open a new terminal or source your .profile file to have the executable in your PATH.
-
Apply formatting on some file:
nhenin@ubuntu ~/d/hasklean (main)> hasklean -- ./test/Test.hs
- Aligns and sorts
import
statements - Groups and wraps
{-# LANGUAGE #-}
pragmas, can remove (some) redundant pragmas - Aligns and sorts
module
statement - Replaces tabs by eight spaces (turned off by default)
- Removes trailing whitespace
For now, we only have guidelines for module header, that is pragma
list, module
statement and import
statements.
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
-- ^
module Hasklean.Step.ModuleHeader -- |
( Config (..) -- |
, BreakWhere (..) -- |
, OpenBracket (..) -- | end of pragma and start of module list are aligned
, defaultConfig -- | with a customizable padding
, step -- |
) where -- |
-- |
-- v
import Control.Applicative ((<|>))
import Control.Monad as M
-- ^ alias follows module name when import list is empty
-- we use ImportQualifiedPost
-- v
import Data.Aeson qualified
as Aeson ( Value(..) )
-- ^ alias are on new line with
-- module name and alias aligned when
-- import list is not empty
import Plutus.Contract
( Contract
, EmptySchema
, logInfo
, ownAddress
, utxosAt
)
-- ^ long import list are on new lines on the left with leading comas
Note: Rules for grouping import
statements are on a per-project basis using
POSIX extended regular expressions patterns. Those rules are specified in a configuration file.
The tool is customizable to some extent:
- You can pass a file to the tool using the
-c/--config
argument - Otherwise the default settings will be used.
Use hasklean --defaults > .hasklean.yaml
to dump a
well-documented default configuration to a file, this way you can get started
quickly.
Since it works as a filter it is pretty easy to integrate this with VIM.
You can call
:%!hasklean
and add a keybinding for it.
Or you can define formatprg
:set formatprg=hasklean
and then use gq
.