Fork me on GitHub
#clj-kondo
<
2022-02-08
>
donavan10:02:00

Am I correct in assuming that :unsorted-required-namespaces checks ordering of splicing reader conditionals as if they were already spliced. I guess that makes sense...

donavan10:02:48

Is there a way to currently support having one splicing conditional at the end of the require block and have each part of it sorted? E.g.:

(ns some.ns
  (:require
   [com.fulcrologic.fulcro.components :as comp :refer [defsc]]
   #?@(:cljs [[com.fulcrologic.fulcro.dom :as dom]]
       :clj [[com.fulcrologic.fulcro.dom-server :as dom]])))

donavan10:02:41

That currently fails the linter because (I think) after splicing it would be out of order

borkdude10:02:06

I'm not sure, it might just ignore these special cases to not cause false positives

donavan10:02:16

It currently raises warnings for us on clj-kondo v2022.01.15 . I wanted to post the above as an arg to the clj-kondo command but I get an error saying it’s an unparsable ns form (I think because there is no file?)

borkdude10:02:20

you can lint from stdin using --lint -

👍 1
donavan11:02:47

The unparsable ns form error occurs even if there is a file. This is what I get…

clj-kondo-repro on  main [?]
❯ clj-kondo --lint src
src/myname/myapp.clj:0:0: error: Can't parse src/myname/myapp.clj, Unparsable namespace form
linting took 166ms, errors: 1, warnings: 0
…in this repro https://github.com/dcostaras/clj-kondo-repro

borkdude11:02:03

you cannot use reader conditionals in .clj files

donavan11:02:17

oof, sorry!

borkdude11:02:43

maybe clj-kondo should warn about this :)

borkdude11:02:59

there might already be an issue about this, but if not, feel free to make one

borkdude11:02:09

(about reader conditionals in .clj)

donavan11:02:26

Will do, weirdly enough I could jack-in and execute forms!

borkdude11:02:44

the REPL might accept it

borkdude11:02:00

$ clj
Clojure 1.11.0-alpha3
user=> #?(:clj 1)
1

donavan12:02:23

There was an issue about reader conditionals awhile back https://github.com/clj-kondo/clj-kondo/issues/80 it could be reopened?

borkdude12:02:58

thanks for finding that

donavan12:02:42

I’ve updated the repro project https://github.com/dcostaras/clj-kondo-repro The behaviour is now:

❯ clj-kondo --lint src
src/myname/myapp.cljc:5:16: warning: Unsorted namespace: com.fulcrologic.fulcro.dom
src/myname/myapp.cljc:6:15: warning: Unsorted namespace: com.fulcrologic.fulcro.dom-server
linting took 215ms, errors: 0, warnings: 2
Could this be configured to not warn in that case… or ideally check the sorting of the parts?

borkdude12:02:17

@U0VP19K6K if you write:

(ns myname.myapp
  (:require
   [com.fulcrologic.fulcro.components :refer [defsc]]
   [taoensso.timbre :as timbre]
   #?(:clj [com.fulcrologic.fulcro.dom-server :as dom])
   #?(:cljs [com.fulcrologic.fulcro.dom :as dom])))
then the order doesn't matter, but somehow in the splice that's not been accounted for yet, it seems. we should just fix that to not warn

borkdude12:02:26

issue welcome. for now you can use a non-splice perhaps

donavan12:02:11

thanks, I’ll open the issue. We’re attempting to turn it on in an existing project so probably wont change all NSs just yet! Thanks borkdude

imre12:02:59

Is there an established good approach to testing my custom hooks in my library?

borkdude12:02:19

@imre testing while developing or testing as in QA?

imre12:02:23

Well, both. For developer feedback I used lots of (prn (api/sexpr node)) as suggested at https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md

imre12:02:50

This is less than ideal but it worked for now

imre12:02:03

I haven't had time to figure out a cleaner way

borkdude12:02:15

For testing as in QA I would just lint your sources and make sure your macros are used in such a way that should be covered by the linting

imre12:02:21

But it would be nice to be able to persist a few tests so I don't break the hook later on

borkdude12:02:39

and then put that linting in a test or CI job

borkdude12:02:03

As for dev, I'm thinking of improving that

imre12:02:08

That works to some extent but I also want to write tests that would fail the linter for specific reasons

borkdude12:02:37

do you mean, you do validation in the linter and would like to test for that?

borkdude13:02:14

You can test for the linter output?

borkdude13:02:48

you can use clj-kondo as a JVM library and make assertions on the findings

borkdude13:02:14

(:findings (clj-kondo.core/run! {:lint ["input-file.clj"]}))

imre13:02:32

ooh, that would work I guess!

imre13:02:55

let me have a go at it

imre13:02:25

Is there a way to pass file contents in there as a string?

borkdude13:02:13

you can lint from stdin like this:

(with-in-str "(+ 1 2 3)" (run! {:lint ["-"]}))

imre13:02:48

Perfect, thank you very much

imre14:02:20

https://github.com/fulcrologic/guardrails/pull/30 in case you're interested what I needed this for. Thanks again for the help!

imre20:02:39

One more question regarding the dev workflow: using the JVM method you shared above, how can I reload the hook code I'm testing after I make changes without having to restart my repl?

imre20:02:50

test uses the project's .clj-kondo/config which references another config which sets up the hook via analyze-call

borkdude21:02:10

I think (require '[clj-kondo.impl.hooks] :reload) will work

imre21:02:51

And indeed it does! Thank you very much again!