lint-hints.hs 1.01 KB
Newer Older
Iustin Pop's avatar
Iustin Pop committed
1
{-| Custom hint lints for Ganeti.
Iustin Pop's avatar
Iustin Pop committed
2

Iustin Pop's avatar
Iustin Pop committed
3 4 5
Since passing --hint to hlint will override, not extend the built-in
hints, we need to import the existing hints so that we get full
coverage.
Iustin Pop's avatar
Iustin Pop committed
6 7 8

-}

Iustin Pop's avatar
Iustin Pop committed
9
import "hint" HLint.HLint
Iustin Pop's avatar
Iustin Pop committed
10 11
import "hint" HLint.Dollar

12 13 14 15 16 17
-- The following two hints warn to simplify e.g. "map (\v -> (v,
-- True)) lst" to "zip lst (repeat True)", which is more abstract
warn = map (\v -> (v, x)) y ==> zip y (repeat x)
  where _ = notIn v x
warn = map (\v -> (x, v)) ==> zip (repeat x)
  where _ = notIn v x
18 19 20 21 22

-- The following warn on use of length instead of null
warn = length x > 0 ==> not (null x)
warn = length x /= 0 ==> not (null x)
warn = length x == 0 ==> null x
23 24 25 26 27 28

-- Never use head, use 'case' which covers all possibilities
warn = head x ==> case x of { y:_ -> y } where note = "Head is unsafe, please use case and handle the empty list as well"

-- Never use tail, use 'case' which covers all possibilities
warn = tail x ==> case x of { _:y -> y } where note = "Tail is unsafe, please use case and handle the empty list as well"