Fork me on GitHub
#clj-kondo
<
2022-01-18
>
dpsutton03:01:45

I’m parsing the output of clj-kondo to make a dashboard. One thing I’ve noticed is the message for unused binding and unresolved var are close but slightly different, missing a ::

warning: Unresolved var: Metric
warning: unused binding query
It would make it easier to parse if this was consistent and was Unused binding: query I think

dpsutton03:01:56

or another way is if there was an argument that would have clj-kondo --lint --print-lint src and the output would be

src/metabase/util/urls.clj:22:20: warning: unresolved-var: Unresolved var: public-settings/site-url
and unresolved-var the linter is included in the output. Would make some dashboarding a bit easier to categorize how many errors of each type there are.

borkdude06:01:32

Why not use the JSON or EDN output?

1
borkdude06:01:55

And feel free to report the missing location issue with a repro

borkdude06:01:18

We could make linter messages more consistent. Feel free to make a separate issue for that

dpsutton06:01:26

i was checking clj-kondo --help and didn't see those options for JSON or EDN

borkdude07:01:33

Those options are available under output in config, see config.md

👍 1
borkdude07:01:23

Perhaps we should support those command line flags though

borkdude07:01:31

Issue welcome as well

dpsutton07:01:08

i was able to work around it. I'll wait until we chat more in depth. was just trying to get a dashboard up with some metrics around all of our warnings

dpsutton07:01:24

it came out pretty well. Have a dashboard in metabase about warnings in metabase 🙂

borkdude07:01:41

Awesome 👏

Michaël Salihi14:01:58

Hello, I get this error error: update-in with single key with this function for the second arity %2:

(defn update-vals [m v f]
  (reduce #(update-in % [%2] f) m v))

mynomoto14:01:58

The message is saying that you could use (update % %2 f) instead.

Michaël Salihi14:01:42

Yes I understand that, but in my case I use only this function with multiple keys so I want to avoid any condition here. Thanks.

borkdude14:01:12

If others are reading: this not an error by default, but a warning, just to be clear. the linter is also optional (off by default). The way you write it above, update-in is always called with a single key, the %2 argument is the key, not multiple keys, no matter what the value of %2 is.

borkdude15:01:41

You can ignore any error with #_:clj-kondo/ignore but it doesn't make sense to ignore this, clj-kondo is correct in this case.

borkdude15:01:18

The %2 isn't spliced into your vector.

Michaël Salihi15:01:50

Yes understand, thanks @U04V15CAJ So to pass the CI tests for my current project, I have no choice to update my function and use condition against the argument to use either update or update-in, right?

Michaël Salihi15:01:44

> You can ignore any error with #_:clj-kondo/ignore but it doesn't make sense to ignore this, clj-kondo is correct in this case. Agree. I don't want to do that and affect all devs of the project just for this function 🙂

borkdude15:01:54

(update-in %1 [%2] ...) is the same as (update %1 %2 ...) always

borkdude15:01:11

no matter what the values of those arguments are

borkdude15:01:17

this is what clj-kondo is trying to say to you :)

Michaël Salihi15:01:23

Alright! 👍 Thanks to you and clj-kondo!

borkdude15:01:18

so yes, you should update your function, but no, you don't have to introduce conditions against the arguments

Michaël Salihi15:01:42

Yes perfect, I end up with this function:

(defn update-vals [m v f]
  (reduce #(update %1 %2 f) m v))
And thanks to clj-kondo, now it's clean.

🎉 1
Michaël Salihi14:01:25

Can we ignore this error only for this case? Without changing Kondo config file?

Noah Bogart14:01:04

What happens if you change % to %1?

Michaël Salihi14:01:26

Thanks for the suggestion. Same error.

Noah Bogart14:01:39

cool, sorry it didn’t help

borkdude15:01:27

Closed due to inactivity, but feel free to respond and I'll re-open

borkdude15:01:53

Just a message like "I'm still interested" suffices

serioga15:01:56

Michiel, what about this (not mine) ticked? Is it OK that it is automatically closed? https://github.com/clj-kondo/clj-kondo/issues/1179

borkdude15:01:09

Feel free to respond the same way

jumar17:01:57

I'm thinking about making an automated test that would check if no namespaces outside of a particular package use namespaces inside that package. I'm looking at clj-kondo's :namespace-usage for this. Does it make sense to you? What about the performance? Note: I haven't used clj-kondo programatically yet, only (sporadically) as a command line tool and in Emacs

borkdude18:01:38

@jumar Yes, you can do this using the analysis data. Performance: just lint your own sources, should not take too long (depending on the size of your project of course...). If you lint all dependencies then it will take longer.

jumar18:01:08

Perfect, thanks!

jumar10:01:31

@U04V15CAJ This takes about 4 seconds on my project (30K lines of Clojure code, 300 files)

;; this can take about 4 seconds
  (time (def analysis (clj-kondo/run! {:lint ["src"]
                                       :config {:output {:analysis true}}})))
Would you say that's expected running time?

borkdude10:01:12

I would say so, are you disappointed? ;)

jumar10:01:45

Not that much - I wish it was even faster but I think this is good enough for me right now 🙂

borkdude10:01:55

You can also use tools.namespace directly if you're only interested in namespace dependencies. That will be much faster since it only reads the top level ns form

👍 1