The balance we choose impacts our code comprehension (hence correctness) and time spent onboarding/maintaining/iterating/reviewing/etc.
steps:
- simple_align:
cases: true
top_level_patterns: true
records: true
- imports:
align: none
list_align: after_alias
long_list_align: new_line_multiline
empty_list_align: inherit
list_padding: 2
separate_lists: true
- language_pragmas:
style: vertical
align: true
remove_redundant: true
- trailing_whitespace: {}
Datatype Alignment
, in fields is always aligned with {
data User = User
{ name :: String
, homeAddress :: Address
, age :: Int
, cell :: PhoneNumber
}
data User = User
{ name :: String
, homeAddress :: Address
, age :: Int
, dob :: Date
}
Alignment can also be done on case statements and imports
Import Sorting within manual groupings
import Control.Applicative ((<$>), liftA2, liftA3))
import System.Directory (doesFileExist)
import Data.Map (Map, keys, (!))
import qualified Data.Map as M
import System.Directory (doesFileExist)
import Control.Applicative (liftA3, (<$>), liftA2)
import qualified Data.Map as M
import Data.Map ((!), keys, Map)
# hindent.yaml
tab-size: 2
line-length: 80
force-trailing-newline: true
Custom errors can be added in order to match and suggest custom changes of code from the left hand side match to the right hand side replacement
- error: {lhs: fmap, rhs: map}
- error: {lhs: mconcat, rhs: concat}
- error: {lhs: mapM, rhs: traverse}
- error:
{ lhs: getCurrentTime
, rhs: getCurrentTimeMicroseconds}
# Everywhere
- ignore: {name: Use let}
# In specific module
- ignore: {name: Use let, within: MyModule}
$ hlint some-haskell-package
some-haskell-package/src/Main.hs:13:3-44: Warning: Functor law
Found:
id <$> pure . someFunction
Perhaps:
pure . someFunction
some-haskell-package/src/Main.hs:34:42: Suggestion: Redundant $
Found:
$
Perhaps you should remove it.
Command line tool or editor configuration
hlint src/Main.hs --refactor \
--refactor-options="--inplace"