Skip to content

Commit

Permalink
Merge pull request #987 from juszczakn/836-fix-fn-kondo-gen
Browse files Browse the repository at this point in the history
Fix #836 clj-kondo linter generation when using pred :fn's
  • Loading branch information
ikitommi authored Jan 7, 2024
2 parents 24495f6 + 2caabf1 commit 7f07add
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/malli/clj_kondo.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
(defmethod accept :tuple [_ _ _ _] :seqable)
(defmethod accept :multi [_ _ _ _] :any) ;;??
(defmethod accept :re [_ _ _ _] :string)
(defmethod accept :fn [_ _ _ _] :fn)
(defmethod accept :fn [_ _ _ _] :any)
(defmethod accept :ref [_ _ _ _] :any) ;;??
(defmethod accept :=> [_ _ _ _] :fn)
(defmethod accept :function [_ _ _ _] :fn)
Expand Down
34 changes: 20 additions & 14 deletions test/malli/clj_kondo_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,21 @@
[:=> [:cat :int :int] :nil]
[:=> [:cat :int :int [:repeat :int]] :nil]])

(deftest clj-kondo-integration-test
(defn clj-kondo-issue-836-1
"Predicate `:fn` schema's should be type-checked as expecting to be passed `:any`, not a fn."
[x y z] (* x y z))
(m/=> clj-kondo-issue-836-1 [:=> [:cat int? [:fn #(int? %)] int?] [:fn #(int? %)]])

(defn- cljk-collect-for-test
"Collect up all of the clj-kondo linters generated for fn's in this test ns."
[]
(-> 'malli.clj-kondo-test
#?(:clj (clj-kondo/collect))
#?(:cljs (clj-kondo/collect-cljs))
(clj-kondo/linter-config)
(get-in [:linters :type-mismatch :namespaces])))

(deftest clj-kondo-integration-test
(is (= {:op :keys,
:opt {::price :double, :tags :set, ::y :boolean},
:req {::id :string,
Expand Down Expand Up @@ -109,21 +122,14 @@
:ret :nil}
:varargs {:args [:int :int {:op :rest :spec :int}]
:ret :nil
:min-arity 2}}}}}]

:min-arity 2}}}
;; should output `:any` for `:fn` predicate schema's, not `:fn`
'clj-kondo-issue-836-1
{:arities {3 {:args [:int :any :int], :ret :any}}}}}]
#?(:clj
(is (= expected-out
(-> 'malli.clj-kondo-test
(clj-kondo/collect)
(clj-kondo/linter-config)
(get-in [:linters :type-mismatch :namespaces])))))

(is (= expected-out (cljk-collect-for-test))))
#?(:cljs
(is (= expected-out
(-> 'malli.clj-kondo-test
(clj-kondo/collect-cljs)
(clj-kondo/linter-config)
(get-in [:linters :type-mismatch :namespaces]))))))
(is (= expected-out (cljk-collect-for-test)))))
(testing "sequential elements"
(is (= :seqable
(clj-kondo/transform [:repeat :int])))
Expand Down
5 changes: 5 additions & 0 deletions test/malli/instrument_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@
(mi/-schema #'f2)))
(is (= nil (mi/-schema #'f3))))

(deftest check-test
(testing "all registered function schemas in this namespace"
(let [results (mi/check {:filters [(mi/-filter-ns 'malli.instrument-test)]})]
(is (map? results)))))

(deftest instrument-external-test

(testing "Without instrumentation"
Expand Down
5 changes: 3 additions & 2 deletions test/malli/instrument_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@
(is (= 9 (minus-small-int 10)))))

(deftest ^:simple check-test
(let [results (mi/check)]
(is (map? results))))
(testing "all registered function schemas in this namespace"
(let [results (mi/check {:filters [(mi/-filter-ns 'malli.instrument-test)]})]
(is (map? results)))))

(deftest ^:simple instrument-external-test

Expand Down

0 comments on commit 7f07add

Please sign in to comment.