Skip to content

Commit f33b6fb

Browse files
committed
Add containers group for redundant toList rewrites (fixes #1570)
New hint group `containers` with rewrites that bypass the intermediate list produced by `Data.IntMap.toList`, `Data.IntSet.toList`, `Data.Map.toList` and `Data.Set.toList` in favour of the container's own fold and predicate primitives. Adds a matching `package: containers` declaration so the group's `imports:` can reference it. All rewrite targets are fully qualified (`Data.Map.null`, `Data.IntSet.member`, etc.), so the group is safe to enable by default: it only fires when the qualified containers API is already in use.
1 parent 086bf44 commit f33b6fb

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

data/hlint.yaml

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@
6565
modules:
6666
- import CodeWorld
6767

68+
- package:
69+
name: containers
70+
modules:
71+
- import Data.IntMap
72+
- import Data.IntMap.Lazy
73+
- import Data.IntMap.Strict
74+
- import Data.IntSet
75+
- import Data.Map
76+
- import Data.Map.Lazy
77+
- import Data.Map.Strict
78+
- import Data.Set
79+
6880
- group:
6981
name: default
7082
enabled: true
@@ -1133,6 +1145,43 @@
11331145
rules:
11341146
- hint: {lhs: "TH.varE 'a", rhs: "[|a|]", name: Use TH quotation brackets}
11351147

1148+
- group:
1149+
name: containers
1150+
enabled: true
1151+
imports:
1152+
- package base
1153+
- package containers
1154+
rules:
1155+
- warn: {lhs: foldMap f (Data.IntMap.toList x), rhs: Data.IntMap.foldMapWithKey (curry f) x}
1156+
- warn: {lhs: foldr f z (Data.IntMap.toList x), rhs: Data.IntMap.foldrWithKey (curry f) z x}
1157+
- warn: {lhs: foldr' f z (Data.IntMap.toList x), rhs: Data.IntMap.foldrWithKey' (curry f) z x}
1158+
- warn: {lhs: foldl f z (Data.IntMap.toList x), rhs: Data.IntMap.foldlWithKey (curry . f) z x}
1159+
- warn: {lhs: foldl' f z (Data.IntMap.toList x), rhs: Data.IntMap.foldlWithKey' (curry . f) z x}
1160+
- warn: {lhs: null (Data.IntMap.toList x), rhs: Data.IntMap.null x}
1161+
- warn: {lhs: length (Data.IntMap.toList x), rhs: Data.IntMap.size x}
1162+
1163+
- warn: {lhs: foldr f z (Data.IntSet.toList x), rhs: Data.IntSet.foldr f z x}
1164+
- warn: {lhs: foldr' f z (Data.IntSet.toList x), rhs: Data.IntSet.foldr' f z x}
1165+
- warn: {lhs: foldl f z (Data.IntSet.toList x), rhs: Data.IntSet.foldl f z x}
1166+
- warn: {lhs: foldl' f z (Data.IntSet.toList x), rhs: Data.IntSet.foldl' f z x}
1167+
- warn: {lhs: null (Data.IntSet.toList x), rhs: Data.IntSet.null x}
1168+
- warn: {lhs: length (Data.IntSet.toList x), rhs: Data.IntSet.size x}
1169+
- warn: {lhs: elem y (Data.IntSet.toList x), rhs: Data.IntSet.member y x}
1170+
- warn: {lhs: notElem y (Data.IntSet.toList x), rhs: Data.IntSet.notMember y x}
1171+
1172+
- warn: {lhs: foldMap f (Data.Map.toList x), rhs: Data.Map.foldMapWithKey (curry f) x}
1173+
- warn: {lhs: foldr f z (Data.Map.toList x), rhs: Data.Map.foldrWithKey (curry f) z x}
1174+
- warn: {lhs: foldr' f z (Data.Map.toList x), rhs: Data.Map.foldrWithKey' (curry f) z x}
1175+
- warn: {lhs: foldl f z (Data.Map.toList x), rhs: Data.Map.foldlWithKey (curry . f) z x}
1176+
- warn: {lhs: foldl' f z (Data.Map.toList x), rhs: Data.Map.foldlWithKey' (curry . f) z x}
1177+
- warn: {lhs: null (Data.Map.toList x), rhs: Data.Map.null x}
1178+
- warn: {lhs: length (Data.Map.toList x), rhs: Data.Map.size x}
1179+
1180+
- warn: {lhs: null (Data.Set.toList x), rhs: Data.Set.null x}
1181+
- warn: {lhs: length (Data.Set.toList x), rhs: Data.Set.size x}
1182+
- warn: {lhs: elem y (Data.Set.toList x), rhs: Data.Set.member y x}
1183+
- warn: {lhs: notElem y (Data.Set.toList x), rhs: Data.Set.notMember y x}
1184+
11361185
- group:
11371186
name: attoparsec
11381187
enabled: true

0 commit comments

Comments
 (0)