clj-kondo

https://github.com/clj-kondo/clj-kondo
Elso 2021-03-16T11:20:25.002Z

I'm having a problem with clj-kondo integration in emacs, where it sometimes does not lint functions defined in the project but only those defined in required libs. I'm not really certain about how to start debugging that - anybody got a hint maybe?

Elso 2021-03-16T11:20:57.002200Z

(it's about number of required args)

borkdude 2021-03-16T11:22:26.002500Z

how are you using clj-kondo, via which plugins

2021-03-16T11:25:17.003100Z

Getting odd false warnings from clj-kondo

(ns witan.small-test
  (:require [tablecloth.api :as tc]))

(defn add-series-name [ds series-name]
  (if (contains? (set (tc/column-names ds)) :series-name)
    ds
    (tc/add-column ds :series-name series-name)))

Elso 2021-03-16T11:25:43.003500Z

spacemacs clojure layer

2021-03-16T11:25:50.003800Z

all the tc/* things are getting squigglies with the warning Unresolved var:...

Elso 2021-03-16T11:25:54.004Z

should be using flycheck/lsp afaik

2021-03-16T11:26:04.004500Z

not sure if it is something odd about tablecloth or something in kondo

2021-03-16T11:26:11.004800Z

I'm on the latest kondo release

borkdude 2021-03-16T11:26:13.004900Z

Doth tablecloth define these vars using some custom macro?

borkdude 2021-03-16T11:26:34.005400Z

If so, then you should either add a config for this custom macro, or add the tc namespace to :exclude in the unresolved-var linter

2021-03-16T11:26:36.005500Z

(defn add-column
  "Add or update (modify) column under `column-name`.

  `column` can be sequence of values or generator function (which gets `ds` as input)."
  ([ds column-name column] (add-column ds column-name column nil))
  ([ds column-name column size-strategy]
   (let [process-fn (prepare-add-column-fn column-name column (or size-strategy :cycle))]

     (if (grouped? ds)
       (process-group-data ds process-fn)
       (process-fn ds)))))

Elso 2021-03-16T11:26:52.005700Z

weird thing is, it works fine with fns defined in the same namespace, but not in those defined in other namespaces in the same project

borkdude 2021-03-16T11:27:22.006300Z

and defn = clojure.core/defn? this is not always the case, but I assume it is?

2021-03-16T11:27:34.006500Z

I believe so, but I'm looking

2021-03-16T11:28:45.007Z

yeah, looks like normal defn (I know potemkin is used in other places, but it doesn't look like in this place)

borkdude 2021-03-16T11:29:41.007400Z

@otfrom Maybe re-lint your tablecloth dependency?

borkdude 2021-03-16T11:30:01.008100Z

If you have some same-named namespace somewhere else it could be that the definitions are overwritten

2021-03-16T11:30:02.008200Z

never done that before

borkdude 2021-03-16T11:30:37.008700Z

@otfrom rm -rf .clj-kondo/.cache should then solve it, but I assume clojure-lsp is linting your deps

2021-03-16T11:31:00.009100Z

it was, but I removed it as that was showing even more weirdness

borkdude 2021-03-16T11:33:05.009600Z

repro welcome, need more details

borkdude 2021-03-16T11:33:41.010100Z

Workaround is {:linters {:unresolved-var {:exclude [<http://your.tc|your.tc>.namespace]}}}

borkdude 2021-03-16T11:35:06.010200Z

if you can make a repro using a minimal project + command line examples, I can take a look. Hard to say anything without more details

👍 1
2021-03-16T11:35:24.010600Z

seems good now. Not sure how the cache got messed up

borkdude 2021-03-16T11:35:44.011Z

Could be an issue with lsp + clj-kondo

Elso 2021-03-16T11:36:19.011300Z

ok

2021-03-16T11:40:25.011600Z

possibly

2021-03-16T11:40:45.012100Z

the cache getting messed up over a number of updates sounds like a reasonable culprit until it happens again

2021-03-16T11:40:51.012300Z

I just had no idea about the cache

2021-03-16T11:40:59.012600Z

(caches have been the bane of my life recently)

2021-03-16T11:41:06.012800Z

thx for pointing me in the right direction

borkdude 2021-03-16T11:41:25.013200Z

clojure-lsp tries to lint all of your deps automatically. clj-kondo doesn't do this, unless you tell it to

borkdude 2021-03-16T11:41:52.013800Z

also clojure-lsp using an incremental diff when you edit files, which might go wrong - there were some discussions about this in the lsp channel

borkdude 2021-03-16T11:42:03.014100Z

is tablecloth your dep, or your project?

2021-03-16T11:43:40.014400Z

as in did I create tablecloth? I'm just using it

borkdude 2021-03-16T11:44:33.014900Z

you can try clj-kondo --lint $(clojure -Spath) (assuming deps.edn) and see if you get the issue again

2021-03-16T12:58:24.015200Z

I've run that and I am getting the same issue

2021-03-16T12:58:52.015400Z

(ns witan.small-test
  (:require [tablecloth.api :as tc]))

(defn col-wrapper [ds]
  (tc/column-names ds))

2021-03-16T12:59:14.015800Z

Unresolved var: tc/column-names

borkdude 2021-03-16T13:02:18.016700Z

ok, that's what I suspected. taking a look at that api ns: https://github.com/scicloj/tablecloth/blob/master/src/tablecloth/api.clj so these vars are all defined using some custom machinery. you must either configure clj-kondo to make it understand this machinery, or to ignore this

borkdude 2021-03-16T13:03:47.017400Z

it looks an awful lot like potemkin/import-vars but not quite, so you cannot simply use :lint-as for this

borkdude 2021-03-16T13:04:03.017800Z

you can either write a hook, or use the workaround I suggested. this is expected behavior

2021-03-16T14:07:16.018400Z

thx. sorry for snitch tagging you on zulip, but I was wondering if someone else had already solved it

borkdude 2021-03-16T14:10:24.019400Z

fwiw @lee has a nice way to generate the potemkin-like-code using a couple of functions instead of using a macro, this makes all the tooling understand it

borkdude 2021-03-16T14:10:31.019600Z

but writing a hook for this isn't too hard

2021-03-16T14:13:14.019900Z

any examples of other hooks I could crib from?

borkdude 2021-03-16T14:15:27.020100Z

https://github.com/clj-kondo/config

borkdude 2021-03-16T14:15:39.020500Z

more docs are here: https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md

lread 2021-03-16T14:32:48.022200Z

Referenced in hooks.md, but https://github.com/lread/rewrite-cljc-playground/commit/09882e1244a8c12879ef8c1e6872724748e7914b when I needed it (I no longer do because I abandoned import-vars - too many headaches!).

👍 1