Skip to content

Commit

Permalink
linter: recursive missing :key check
Browse files Browse the repository at this point in the history
  • Loading branch information
roman01la committed Jul 19, 2022
1 parent 4e47fef commit 1ee076b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
10 changes: 7 additions & 3 deletions core/src/uix/linter.clj
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,14 @@
:iter-fn #{map mapv map-indexed reduce reduce-kv
keep keep-indexed mapcat}})

(defn- lint-missing-key!* [expr]
(cond
(uix-element? expr) (missing-key? expr)
(list? expr) (recur (last expr))))

(defn- lint-missing-key! [kv sym body]
(when (and (contains? (get mapping-forms kv) sym)
(uix-element? (last body)))
(missing-key? (last body))))
(when (contains? (get mapping-forms kv) sym)
(lint-missing-key!* (last body))))

(declare lint-body!*)

Expand Down
3 changes: 2 additions & 1 deletion core/test/uix/linter_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -258,4 +258,5 @@
(is (str/includes? out-str (str :uix.linter/missing-key)))
(is (str/includes? out-str "UIx element is missing :key attribute, which is required"))
(is (str/includes? out-str "($ :div.test-missing-key {} x)"))
(is (str/includes? out-str "($ :div.test-missing-key ($ x))")))))
(is (str/includes? out-str "($ :div.test-missing-key ($ x))"))
(is (str/includes? out-str "($ :div.test-missing-key-nested ($ x))")))))
7 changes: 6 additions & 1 deletion core/test/uix/linter_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,9 @@
(for [x []]
($ :div.test-missing-key {} x))
(for [x []]
($ :div.test-missing-key ($ x))))
($ :div.test-missing-key ($ x)))
(for [x []]
(let [x x]
(do
($ :div.test-missing-key ($ x))
($ :div.test-missing-key-nested ($ x))))))

0 comments on commit 1ee076b

Please sign in to comment.