Skip to content

Commit

Permalink
Use clj-kondo :seqable for :+, :*, and :? not {:op :rest}
Browse files Browse the repository at this point in the history
Update clj-kondo type generation. `{:op :rest}` should be used only for varargs.

```
This can be used to match remaining arguments in vararg signatures.

https://github.com/clj-kondo/clj-kondo/blob/master/doc/types.md
```
  • Loading branch information
tvaisanen committed Sep 10, 2023
1 parent 38d77ea commit 852d7c3
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/malli/clj_kondo.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@
(defmethod accept :qualified-symbol [_ _ _ _] :symbol)
(defmethod accept :uuid [_ _ _ _] :any) ;;??

(defmethod accept :+ [_ _ [child] _] {:op :rest, :spec child})
(defmethod accept :* [_ _ [child] _] {:op :rest, :spec child})
(defmethod accept :? [_ _ [child] _] {:op :rest, :spec child})
(defmethod accept :+ [_ _ _ _] :seqable)
(defmethod accept :* [_ _ _ _] :seqable)
(defmethod accept :? [_ _ _ _] :seqable)
(defmethod accept :repeat [_ _ [child] _] {:op :rest, :spec child})
(defmethod accept :cat [_ _ children _] children)
(defmethod accept :catn [_ _ children _] (mapv last children))
Expand Down
32 changes: 30 additions & 2 deletions test/malli/clj_kondo_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,18 @@

(m/=> siren [:=> [:cat ifn? coll?] map?])

(defn clj-kondo-issue-1922-1 [_x])
(m/=> clj-kondo-issue-1922-1
[:=> [:cat [:map [:keys [:+ :keyword]]]] :nil])

(defn clj-kondo-issue-1922-2 [_x])
(m/=> clj-kondo-issue-1922-2
[:=> [:cat [:map [:keys [:* :int]]]] :nil])

(defn clj-kondo-issue-1922-3 [_x])
(m/=> clj-kondo-issue-1922-3
[:=> [:cat [:map [:keys [:? :string]]]] :nil])

(deftest clj-kondo-integration-test

(is (= {:op :keys,
Expand All @@ -63,11 +75,27 @@
{'kikka
{:arities {1 {:args [:int],
:ret :int},
:varargs {:args [:int :int {:op :rest, :spec :int}],
:varargs {:args [:int :int :seqable],
:ret :int,
:min-arity 2}}}
'siren
{:arities {2 {:args [:ifn :coll], :ret :map}}}}}]
{:arities {2 {:args [:ifn :coll], :ret :map}}}

'clj-kondo-issue-1922-1
{:arities {1 {:args [{:op :keys
:req {:keys :seqable}}]
:ret :nil}}}

'clj-kondo-issue-1922-2
{:arities {1 {:args [{:op :keys
:req {:keys :seqable}}]
:ret :nil}}}

'clj-kondo-issue-1922-3
{:arities {1 {:args [{:op :keys
:req {:keys :seqable}}]
:ret :nil}}}}}]

#?(:clj
(is (= expected-out
(-> 'malli.clj-kondo-test
Expand Down

0 comments on commit 852d7c3

Please sign in to comment.