Fork me on GitHub
#clj-kondo
<
2021-03-16
>
Elso11:03:25

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?

Elso11:03:57

(it's about number of required args)

borkdude11:03:26

how are you using clj-kondo, via which plugins

Elso11:03:43

spacemacs clojure layer

Elso11:03:54

should be using flycheck/lsp afaik

Elso11:03:52

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

borkdude11:03:06

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

๐Ÿ‘ 3
otfrom11:03:17

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)))

otfrom11:03:50

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

otfrom11:03:04

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

otfrom11:03:11

I'm on the latest kondo release

borkdude11:03:13

Doth tablecloth define these vars using some custom macro?

borkdude11:03:34

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

otfrom11:03:36

(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)))))

borkdude11:03:22

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

otfrom11:03:34

I believe so, but I'm looking

otfrom11:03:45

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

borkdude11:03:41

@otfrom Maybe re-lint your tablecloth dependency?

borkdude11:03:01

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

otfrom11:03:02

never done that before

borkdude11:03:37

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

otfrom11:03:00

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

borkdude11:03:05

repro welcome, need more details

borkdude11:03:41

Workaround is {:linters {:unresolved-var {:exclude [.namespace]}}}

otfrom11:03:24

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

borkdude11:03:44

Could be an issue with lsp + clj-kondo

otfrom11:03:45

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

otfrom11:03:51

I just had no idea about the cache

otfrom11:03:59

(caches have been the bane of my life recently)

otfrom11:03:06

thx for pointing me in the right direction

borkdude11:03:25

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

borkdude11:03:52

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

borkdude11:03:03

is tablecloth your dep, or your project?

otfrom11:03:40

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

borkdude11:03:33

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

otfrom12:03:24

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

otfrom12:03:52

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

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

otfrom12:03:14

Unresolved var: tc/column-names

borkdude13:03:18

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

borkdude13:03:47

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

borkdude13:03:03

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

otfrom14:03:16

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

borkdude14:03:24

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

borkdude14:03:31

but writing a hook for this isn't too hard

otfrom14:03:14

any examples of other hooks I could crib from?

lread14:03:48

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!).

๐Ÿ‘ 3