This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-03
Channels
- # babashka (12)
- # beginners (15)
- # biff (2)
- # calva (17)
- # clj-kondo (19)
- # clj-on-windows (3)
- # clj-otel (1)
- # clojure (3)
- # clojure-europe (5)
- # conjure (2)
- # graalvm (2)
- # helix (5)
- # introduce-yourself (1)
- # nbb (24)
- # off-topic (32)
- # polylith (3)
- # reitit (21)
- # releases (1)
- # reveal (3)
- # scittle (1)
- # squint (56)
- # tools-deps (4)
- # xtdb (6)
I am getting a expected symbol
from clj-kondo for Clojure spec used with test.check
(example below).
I can't figure out if I am doing it wrong or if I found a sharp edge of clj-kondo.
This works fine:
(spec/def ::a-fn fn?)
(spec/def ::name string?)
(spec/def ::hey
(spec/keys :req [::a-fn ::name]))
(spec/valid? ::hey {::a-fn identity ::name "Hello"}) => true
Now I want to generate test data, for no particular reason other than "I can" (or should be able to) with (gen/generate (spec/gen ::hey))
But it gives me:
; Execution error (ExceptionInfo) at user/eval9271 (form-init5066133147658145143.clj:81).
; Unable to construct gen at: [:user/a-fn] for: :user/a-fn
Then I add:
(spec/fdef ::a-fn
:args (spec/cat)
:ret int?)
Which makes test.check
happy... now I can generate test data.
But now clj-kondo complains about expected symbol
:
(spec/fdef ::a-fn
^^^^^^
What if you make that a symbol? I didn't know function specs could be made with keywords or if it's maybe accidentally supported
I don't understand how. If I use anything but ::a-fn
then how does spec know what I am defining?
Perhaps you should use fspec instead of fdef? :thinking_face:
I'll look into fspec
but I think it may accidentally work for a keyword. So if you try: my-namespace.a-fn
it will work per the docstring
I could not figure out how to make spec, like my quoted symbol, but the following seems to work:
(spec/def ::a-fn
(spec/fspec :args (spec/cat)
:ret nil?))
;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^
;; NOTICE THIS
(spec/def ::name string?)
(spec/def ::hey
(spec/keys :req [::a-fn ::name]))
(spec/valid? ::hey {::a-fn println ::name "Hello"})
(spec/explain ::hey {::a-fn println ::name "Hello"})
(gen/generate (spec/gen ::hey))
This is probably a RTFM, but still: I’ve written a macro like
(defmacro with-foo [foo & body]
`(let [~foo ...]
~@body))
to be used as:
(with-foo lol
(println lol)
What kind of lint-as
magic do I need to invoke to let clj-kondo understand that lol
is in fact defined in the call to println
?