Skip to content

Commit

Permalink
fix invalid-hooks for hooks that appear inside of literals
Browse files Browse the repository at this point in the history
  • Loading branch information
lilactown committed Sep 18, 2021
1 parent 4cfe185 commit 27371f0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/helix/impl/analyzer.clj
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,14 @@ Example: ($ %s %s ...)"
(not (and (seqable? form) (seq form)))
nil

(or (vector? form) (set? form))
(map #(invalid-hooks-usage ctx %) form)

(map? form)
(concat
(map #(invalid-hooks-usage ctx %) (keys form))
(map #(invalid-hooks-usage ctx %) (vals form)))

:else
(let [hd (first form)]
(->> (cond
Expand Down
13 changes: 12 additions & 1 deletion test/helix/impl/analyzer_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,18 @@
true (bar)
(use-foo) (baz))
'(condp #(use-foo %) asdf
123 (baz))))
123 (baz))
'(when x
[(hooks/use-foo)])
'(when x
{:a (hooks/use-foo)})
'{:a (when x (hooks/use-foo))}
'[(when x
(hooks/use-foo))]
'(when x
#{(hooks/use-foo)})
'#{(when x
(hooks/use-foo))}))

(t/testing "correct hooks usage in loop"
(t/are [form] (nil? (hana/invalid-hooks-usage form))
Expand Down

0 comments on commit 27371f0

Please sign in to comment.