This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-11-03
Channels
- # announcements (17)
- # asami (17)
- # babashka (20)
- # beginners (110)
- # calva (1)
- # cherry (3)
- # cider (1)
- # clj-kondo (21)
- # clj-on-windows (1)
- # cljsrn (5)
- # clojure (142)
- # clojure-austin (1)
- # clojure-europe (72)
- # clojure-france (28)
- # clojure-hungary (2)
- # clojure-nl (2)
- # clojure-norway (38)
- # clojure-poland (2)
- # clojure-uk (3)
- # clojurescript (4)
- # cursive (33)
- # data-science (3)
- # datahike (5)
- # datomic (1)
- # emacs (27)
- # events (3)
- # fulcro (15)
- # graalvm (4)
- # gratitude (2)
- # honeysql (7)
- # humbleui (8)
- # introduce-yourself (11)
- # jobs-discuss (9)
- # lambdaisland (3)
- # lsp (18)
- # malli (62)
- # music (1)
- # nbb (3)
- # off-topic (10)
- # pathom (3)
- # pedestal (6)
- # polylith (5)
- # re-frame (7)
- # releases (2)
- # shadow-cljs (33)
- # sql (1)
- # test-check (23)
- # vim (20)
- # xtdb (9)
Did someone already use rewrite-cljc
to point out malli
validation errors inline? I believe it is possible and I’m thinking of doing this
All little bit how expound underlines invalid values with ^^^
(see https://github.com/bhb/expound#expound-1), so a little different than
i think. More like the output of babashka with for instance:
echo '(/ 100 0)' > foo.clj; bb foo.clj
....
----- Context ------------------------------------------------------------------
1: (/ 100 0)
^--- Divide by zero
I would also like to see those. Also, paiting the errors with pretty, like expound does it.
drafted mx/def
on the way to ClojureDays, which could have a clj-kondo hook to highlight the errors in the editor: https://twitter.com/ikitommi/status/1585995979748409345. ping @borkdude
ah yeah made a mistake rewrite-clj
indeed
However just found that I can probably do what I want with edamame as well
Needed this https://github.com/borkdude/edamame#postprocess for detailed location info
did a test with edamame a while back: https://gist.github.com/ikitommi/0e5c4e48d8aeb7dd176128856ecdacb5
Ah useful thank you!
@ikitommi I think we could add "type checking" for def
- this is what you need right?
another try would be use use malli for the validation and just emit errors. But that’s way more work I think (all the relevant schemas should be loaded, e.g. should need to run the whole program to figure our what is the schema)
@ikitommi when clj-kondo supports this yes, but currently I don't think it supports it yet
ah yes, a very old one :rolling_on_the_floor_laughing: https://github.com/clj-kondo/clj-kondo/issues/609
but, would that work here? the mx/def
says “here’s a var which should have a value of type XYZ”
FYI @ikitommi, I have something that I’m happy with (@borkdude also thanks to edamame), see https://gist.github.com/jeroenvandijk/080370966fadb7e65601931c3de47ed5#file-malli_inline_output-clj-L129. Here is some example output:
1: {:b :z
^------- should be an integer
2:
3: :c {:c0 2}
^------- missing required key :x
4:
5: }
^------- missing required key :a
Oh that's pretty neat @U0FT7SRLP. I might experiment with this strategy for reporting errors in cljdoc.edn
files.
@U0FT7SRLP Cool stuff, I think it's worth a blog post or maybe an article in the malli or edamame repo :)
Thanks @borkdude! Yeah I guess it can be useful for others, or in other contexts. Also it is combining some funny techniques together. Will think about an article. Do you have an example format you are thinking of?
Btw, I have created a similar mechanism for giving feedback on invalid edn input, also using Edamame. Maybe can include this in the same article
I'm open to having an examples/malli/README.md
thing in edamame for example, or similar, or doc/postprocess.md
or so
If you don't have a blog, you can quickly create one with ... https://github.com/borkdude/quickblog :)
haha good one, let me think about it for a bit. No blog at the moment. I’ll come back to it
Thanks @ikitommi a raw version is already here https://gist.github.com/jeroenvandijk/080370966fadb7e65601931c3de47ed5#file-malli_inline_output-clj-L129 (for the Malli feedback)
(Need to fix a few test...
Ran 366 tests containing 3188 assertions.
80 failures, 8 errors.
)oh, super! that was fast. I’ll emit the clj-kondo types when this ships. So, this would work with complex types like maps too and also for defining the values? e.g. “this var should hold a map of :age key with int value” and saying (def mything {:age "1"})
would be a failure?
It's funny, I'm getting errors from dynamic vars which are initialized to nil
and then later called with swap!
- I guess I'll have to ignore dynamic vars
Another nice edge case...
https://github.com/clojure/clojurescript/blob/961807166c8cf4d45a225d63416f06464fb27eaf/src/main/cljs/cljs/core.cljs#L10803-L10816
It thinks gensym_counter
is nil (since it was initialized to nil
)
@ikitommi Now got this working:
$ clojure -M:clj-kondo/dev --lint - --config '{:linters {:type-mismatch {:namespaces {user {x {:tag {:op :keys :req {:x :any}} }}}}}}' <<< "(def x) (inc x)"
<stdin>:1:14: warning: Expected: number, received: map.
but this is probably the reverse of what you were proposing. the config in clj-kondo is to override types that have been inferred, possibly incorrectly
Perhaps clj-kondo should both check the type and take the config as the source of truth...?
Not sure if it exists, but maybe the lite syntax can help you convert your plumatic schema https://github.com/metosin/malli#lite
FYI @ikitommi, I have something that I’m happy with (@borkdude also thanks to edamame), see https://gist.github.com/jeroenvandijk/080370966fadb7e65601931c3de47ed5#file-malli_inline_output-clj-L129. Here is some example output:
1: {:b :z
^------- should be an integer
2:
3: :c {:c0 2}
^------- missing required key :x
4:
5: }
^------- missing required key :a