Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use clj-kondo :seqable for :+, :*, and :? not {:op :rest} #952

Merged
merged 3 commits into from
Sep 23, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:repeat is also one of the sequence schemas that can present more than 1 values.

(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}],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a real varargs case and should generate :rest definition instead :seqable. From clj-kondo:

{:op :rest, :spec :int}. This can be used to match remaining arguments in vararg signatures. 

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see! Thanks.

:varargs {:args [:int :int :seqable],
:ret :int,
:min-arity 2}}}
'siren
{:arities {2 {:args [:ifn :coll], :ret :map}}}}}]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good tests 💪.

{: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