Fork me on GitHub
#clj-kondo
<
2022-05-16
>
pinkfrog14:05:47

For

:unused-private-var 
  {:exclude [user]}}
cljkondo errs with:
Expected fully qualified symbol, got: user {:type :clj-kondo/config}

borkdude14:05:56

yes, you need to specify the fully qualified symbol of the var

pinkfrog14:05:41

for the user namespace, what’s the qualfied version?

borkdude14:05:24

That is not how it works. It expects fully qualified var names there for which you want to suppress the usage warning.

(ns foo) 
(defn- foo [])
(ns bar (:require [foo]))
(foo/foo) ;; warning
:exclude [foo/foo]

pinkfrog14:05:27

Possible to exclude for all vars in a namespace?

pinkfrog14:05:02

Some use cases, the user.clj namespace, and also the public vars in bb task.clj files.

borkdude14:05:27

Oh sorry, unused-private-var

borkdude14:05:46

I mixed it up with private-call facepalm

borkdude14:05:41

If you want to suppress warnings inside of the namespace you can do two things:

(ns foo {:clj-kondo/config '{:linters {:unused-private-var {:level :off}}})
or:
:config-in-ns {user {:linters ...}}

thanks3 1
pinkfrog14:05:34

Is it valid for unused-public-var.? Not working on my side

:config-in-ns
 {task.deps {:linters {:clojure-lsp/unused-public-var
                       {:level :off}}}}

pinkfrog14:05:42

Where task.deps is the namespace in question.

borkdude14:05:10

oh I see, I thought you were asking about unused-private-var

borkdude14:05:16

this is a different linter

borkdude14:05:35

which is implemented by clojure-lsp

borkdude14:05:48

I always turn this linter off to be honest ;)

borkdude14:05:17

since I already get the number of usages on my screen, I find the "unused" bit a bit redundant

pinkfrog14:05:27

So the config-in-ns only for internal linters?

borkdude14:05:56

It works for clj-kondo's own linters, but I don't think clojure-lsp looks at that config

borkdude14:05:16

Maybe @UKFSJSM38 could fix that

borkdude14:05:29

since he was actually one of the people requesting :config-in-ns ;)

pinkfrog14:05:59

I got it. It’s the linter that actively looks at the config file.

borkdude14:05:10

in case of clj-kondo's own linters this is automatic, but for "external" linters they have to implement this themselves

ericdallo14:05:30

Oh, I think we need to fix on clojure-lsp to check config-in-ns indeed, will create a issue about that

ericdallo14:05:23

@U04V15CAJ I think we would need to re-write lot of clj-kondo logic already has to check the ns and things like that, do you see any function we could expose on clj-kondo to make that easier for clojure-lsp?

ericdallo14:05:07

well, I'll create the issue first on clojure-lsp

borkdude14:05:33

@UKFSJSM38 For unused-public-var you'd only have to merge the config in :config-in-ns for the namespace the unused public var occurred in

borkdude14:05:49

clj-kondo already exposes a merge function, not sure what more it should expose

ericdallo14:05:00

right, will check that merge function

ericdallo16:05:21

@UGC0NEP4Y fixed, available on next release or via #clojure-lsp-builds

👍 1
plins15:05:59

Im trying to use a lib that defines some functions dynamically using macros like

(defmacro log
  "Log an event and optional data structure at the supplied severity level
  using a logger that implements the Logger protocol."
  ([logger level event]      (log-form logger level event nil &form))
  ([logger level event data] (log-form logger level event data &form)))

(doseq [level '(report fatal error warn info debug)]
  (eval
   `(defmacro ~level
      ~(format "Log an event with %s logging level. See [[log]]." level)
      (~'[logger event]
       (log-form ~'logger ~(keyword level) ~'event nil ~'&form))
      (~'[logger event data]
       (log-form ~'logger ~(keyword level) ~'event ~'data ~'&form)))))
and of course clj-kondo is complaining.. is there a way of telling it on the config that these functions actually are defined?

imre15:05:15

That's what should be used for advanced macros like this

plins15:05:33

given that I know that this will generate fns named [report fatal error warn info debug] cant I “declare” them somehow on cfg file?

borkdude15:05:31

@U3QUAHZJ6 You can even just write

(declare report fata error warn info debug)
in your clojure code and clj-kondo will get it :)

plins15:05:21

the thing is that this snippet lives in the lib namespace

borkdude16:05:24

you can exclude warnings for all unresolved vars from namespace foo using:

{:linters {:unresolved-var {:exclude [foo]}}}
or exclude a selection of unresolved vars using qualified symbols:
{:linters {:unresolved-var {:exclude [foo/x]}}}

imre17:05:59

While that works, I was wondering if it would be possible to create a linter or some config that says "wherever this macro is called, these n symbols will be defined" (provide list of symbols)

borkdude17:05:11

Yes, that is possible, using hooks, but those vars aren't created through a macro, but rather a global doseq

imre17:05:26

Oh true. Damn lisp curse

borkdude17:05:02

Damn eval ;)

cldwalker19:05:26

Has anyone tried linting with a cljs 1.11.X project? On a .cljs file with latest clj-kondo, I see update-keys and parse-long reported as unresolved symbols

borkdude19:05:01

@cldwalker if you lint your cljs dependency then (in theory) it should work

cldwalker19:05:40

Not sure I understand the suggestion. The invocation I'm using is clj-kondo --lint /path/to/cljs/file . Should I be adding the cljs version as a dep?

cldwalker19:05:26

I tried the following as an alias but still get same error:

{:replace-deps {clj-kondo/clj-kondo {:mvn/version "2022.04.25"}
                                      org.clojure/clojurescript        {:mvn/version "1.11.54"}}
                       :main-opts  ["-m" "clj-kondo.main"]}

borkdude20:05:32

What I mean is, you should lint your dependencies with:

clj-kondo --lint $(clojure -Spath) --dependencies --parallel

borkdude20:05:41

with clojurescript on the classpath

borkdude20:05:56

so clj-kondo will actually analyze clojurescript and see those new functions

cldwalker20:05:50

Ah. I guess my clj-kondo uses have been basic. I see I missed docs in https://github.com/clj-kondo/clj-kondo/blob/master/README.md#project-setup. Thanks for the help!

borkdude20:05:32

@cldwalker Could you post an issue as a reminder to update the built-in cljs cache?

1