From b270b09a9ead242d9e4c5cd7374dd58d703c9e36 Mon Sep 17 00:00:00 2001 From: Steve Losh Date: Tue, 10 Jul 2012 17:25:27 -0400 Subject: [PATCH] Add update-in suggestions. I often forget that update-in exists. This change adds a rule to remind people of it for a few simple cases. --- src/kibit/rules/collections.clj | 3 +++ test/kibit/test/collections.clj | 8 +++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/kibit/rules/collections.clj b/src/kibit/rules/collections.clj index 4df4650..17e10f1 100644 --- a/src/kibit/rules/collections.clj +++ b/src/kibit/rules/collections.clj @@ -5,6 +5,9 @@ ;;vector [(conj [] . ?x) (vector . ?x)] [(into [] ?coll) (vec ?coll)] + [(assoc ?coll ?key (?fn (?key ?coll) . ?args)) (update-in ?coll [?key] ?fn . ?args)] + [(assoc ?coll ?key (?fn (?coll ?key) . ?args)) (update-in ?coll [?key] ?fn . ?args)] + [(assoc ?coll ?key (?fn (get ?coll ?key) . ?args)) (update-in ?coll [?key] ?fn . ?args)] ;; empty? [(not (empty? ?x)) (seq ?x)] diff --git a/test/kibit/test/collections.clj b/test/kibit/test/collections.clj index f7171e6..a855086 100644 --- a/test/kibit/test/collections.clj +++ b/test/kibit/test/collections.clj @@ -11,4 +11,10 @@ '(vector a) '(conj [] a) '(vector a b) '(conj [] a b) '(vec coll) '(into [] coll) - '(set coll) '(into #{} coll))) + '(set coll) '(into #{} coll) + '(update-in coll [k] f) '(assoc coll k (f (k coll))) + '(update-in coll [k] f) '(assoc coll k (f (coll k))) + '(update-in coll [k] f) '(assoc coll k (f (get coll k))) + '(update-in coll [k] f a b c) '(assoc coll k (f (k coll) a b c)) + '(update-in coll [k] f a b c) '(assoc coll k (f (coll k) a b c)) + '(update-in coll [k] f a b c) '(assoc coll k (f (get coll k) a b c))))