Fork me on GitHub
#clj-kondo
<
2022-07-12
>
sheluchin14:07:00

I'd like to store the analysis data in a sql db. Is this already being done somewhere? I'd like to use a standard/common schema for it, if there is one.

borkdude15:07:52

There is no sql stuff yet. I'm playing around with some SQL stuff where you can store analysis of multiple projects, but there's nothing finished about it. If you've got something useful to share at some point, please do :)

sheluchin17:07:46

Thanks @U04V15CAJ, will do :)

Max16:07:53

I recently wrote this macro:

(defmacro when->
  "If bool is true, return (-> x form). Otherwise, return x unchanged.
   Useful in threading, e.g. (-> {:a 1} (when-> something (assoc :b 2)))"
  [x bool form]
  `(if ~bool
     (-> ~x ~form)
     ~x))
When I try to use it though, clj-kondo complains. For example:
(-> m
    (when-> (some-test (:k1 m)) (assoc :k2 5)))
;; clojure.core/assoc is called with 2 args but expects 3 or more - clj-kondo (invalid-arity)
How do I get clj-kondo to stop complaining?

borkdude16:07:52

Are you familiar with lint-as?

Max16:07:32

A little, what would I lint when-> as though? It takes different args from ->

borkdude16:07:19

You can basically copy / paste your macro in the config. If you have loss of too many locations, then the :analyze-call hooks is the best option (which isn't too hard for this macro)

Cora (she/her)16:07:25

definitely what @U04V15CAJ said 😅

Max17:07:35

Is there a way to do it inline, like with metadata or a comment? This is a huge monolith so it feels a little icky to change the entire thing's kondo file for my one local helper macro

Joshua Suskalo17:07:25

Potentially you could lint it as as-> if it isn't too strict about the argument being a symbol

borkdude17:07:51

> Is there a way to do it inline, like with metadata or a comment? No. But perhaps if it's only used very locally, then you can just suppress the linting in it

Joshua Suskalo17:07:26

no ns-local config to add the lint-as?

borkdude17:07:23

for lint-as yes, but not for the hook

Max17:07:28

TIL about #_{:clj-kondo/ignore [:invalid-arity]}, thanks!

ingesol19:07:55

I think cond-> would give you the same as your when->

☝️ 1
sheluchin18:07:01

Is there a way to get function call argument information? The way I can think of is to look up the var usage in var definitions and try to match the arity count in case of a variadic, then check the definition's :arglists.

Joshua Suskalo19:07:11

What's the actual data you're trying to get? Which arity is being invoked by any given invocation of the function?

sheluchin20:07:20

I'd like to be able to get the argument names being used in a function call.

Joshua Suskalo20:07:45

Then yes, you should be able to look at the arglists metadata from kondo's analysis, but I do want to ask @U04V15CAJ if arglist metadata is automatically populated in analysis. I expect not, in which case you'll have to look at the different arity's argument vectors manually if arglists is not provided.

sheluchin20:07:03

Yes, saw that part. In my case I'm looking for the arglists on function invocations, not just definitions. I'll make the connections manually if there isn't some convenience flag or function for it.

borkdude20:07:47

Ah right, you want the join on the definition

borkdude20:07:12

Yeah, right now some things are "joined" automatically, like arity info

borkdude20:07:26

But not all of it, to save some data size

sheluchin20:07:46

Yep, join on definition sounds like what I'm after. So in some cases it is already joined? Could you please mpoint me to the function which does the joining so I can get the full list in case of omissions?

sheluchin22:07:09

@U04V15CAJ thanks very much.