Fork me on GitHub
#clj-kondo
<
2022-10-17
>
onetom05:10:02

is there a place, which collects recommended :lint-as definitions for popular clojure libraries?

borkdude07:10:44

The best place is in that library itself

onetom08:10:21

i saw that page, but on 1st skimming i missed the link to https://github.com/clj-kondo/config btw, this is the config i needed:

❯ cat ~/.config/clj-kondo/config.edn 
{:lint-as {; 
           clojure.test.check.properties/for-all clojure.core/let
           clojure.test.check.clojure-test/defspec clojure.core/def #_clj-kondo.lint-as/def-catch-all}}
so i guess this config should go into clj-kondo/config for reusability.

borkdude08:10:04

Yes. I won't get my hopes up to get this config into a core library so maybe it's best to create another library with just that config which you can then add to your deps. I've been considering this for a while

👌 1
vlad_poh15:10:29

Everytime i use org.httpkit client in calva i get “Unresolved var” for each function. Any idea on what i’m doing wrong?

org.httpkit.client/get
[url & [opts callback]]
[url & [callback]]
Issues an async HTTP GET request. See request for details.

Unresolved var: c/getclj-kondo(unresolved-var)

borkdude15:10:16

@U06GMV0B0 The issue is that these vars have been created via a custom macro. https://github.com/http-kit/http-kit/blob/cf1365167c5a2447f66ea2c0f4541a81114d2f74/src/org/httpkit/client.clj#L308 you can solve this by adding {:lint-as {org.httpkit.client/defreq clojure.core/def}} to your config and the restart your workspace

👍 2
sheluchin12:10:39

Would a :consistently-aliased flag for the :consistent-alias linter be helpful? Setting it to true would show warnings on usages of a fully qualified namespace symbol (and keyword, ideally) when that same ns has a :consistent-alias configuration.

agorgl13:10:38

I'm trying to fix an Unresolved var warning in clojure-lsp that comes from clj-kondo. I'm generating a project from the re-frame-template using this:

clojure -Tclj-new create :template re-frame :name sample/playground :output sample-playground :args '[+kondo +garden +routes "+10x"]'
The generated file styles.cljs has lots of clj-kondo errors/warnings by default, most of them that I managed to fix in this PR: https://github.com/day8/re-frame-template/pull/174 I'm trying to solve the last one, an Unresolved var: deg which is referred from garden.units namespace. I tried adding garden.units/defunit clojure.core/def to :lint-as of .clj-kondo/config.edn, seeing deg is defined as (defunit deg), without much success. Any ideas?

borkdude13:10:19

You need to re-lint your dependencies with this configuration in place

agorgl13:10:27

First of all, honored 🙂

🙇 1
agorgl13:10:05

I'm kind of now transitioning into the clojure ecosystem, could you explain what do you mean by re-linting?

borkdude13:10:34

It might also be a good idea to submit those configurations to the libraries themselves rather than just the templates. https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md#exporting-and-importing-configuration See here for examples: https://github.com/clj-kondo/clj-kondo/discussions/1528

borkdude13:10:51

Re-linting just means: analyze the code again with clj-kondo

borkdude13:10:20

So on the command line for example:

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

borkdude13:10:40

and then the garden namespace is seen again by clj-kondo, but this time with your new lint-as configuration

borkdude13:10:49

and then clj-kondo sees there is a var deg being defined

borkdude13:10:54

What also might help is blow the clj-kondo and lsp cache:

rm -rf .lsp/.cache
rm -rf .clj-kondo/.cache

borkdude13:10:57

and then restart your editor

borkdude13:10:25

Normally clojure-lsp should notice that the clj-kondo config has changed though

borkdude13:10:31

and re-lint the code automatically

agorgl13:10:39

I tried rm -rf .lsp .clj-kondo/* (except config.edn), running the clj-kondo command above, and again opening my editor

agorgl13:10:44

Still the same

borkdude13:10:19

can you check out the repo in another directory and open it there?

borkdude13:10:30

and is it possible to make a repro that I can download locally?

agorgl13:10:01

I believe it is!

agorgl13:10:25

Let me make you an oneliner

borkdude13:10:46

Back in 30 minutes

agorgl13:10:11

Generate a sample re-frame project using:

clojure -Tclj-new create :template re-frame :name sample.playground :output sample-playground :args '[+kondo +garden +routes "+10x"]'
and then just replace the .clj-kondo/config.edn with the patched one from my PR:
{:lint-as {day8.re-frame.tracing/defn-traced clojure.core/defn
           day8.re-frame.tracing/fn-traced clojure.core/fn
           garden.def/defcssfn clojure.core/defn
           garden.def/defkeyframes clojure.core/def
           garden.def/defrule clojure.core/def
           garden.def/defstyles clojure.core/def
           garden.def/defstylesheet clojure.core/def
           spade.core/defglobal clojure.core/def
           spade.core/defclass clojure.core/def}
 :linters {:unresolved-symbol {:exclude [goog.DEBUG]}
           :unused-namespace {:exclude [cljs.repl]}
           :unused-referred-var {:exclude {cljs.repl [Error->map
                                                      apropos
                                                      dir
                                                      doc
                                                      error->str
                                                      ex-str
                                                      ex-triage
                                                      find-doc
                                                      print-doc
                                                      pst
                                                      source]}}}}
Then just cd into sample-playground, open your editor to styles.cljs and see!

agorgl13:10:30

(Description for PoC practically lives in the above PR too)

borkdude14:10:29

Is it possible to prepare a repro which I can directly clone?

borkdude14:10:40

I don't have the clj-new alias readily available etc

agorgl14:10:52

Ofc, give me a minute

🙏 1
agorgl14:10:57

Here you go

borkdude14:10:41

Thanks, I can repro now, checking into it

borkdude14:10:49

So if I go into the garden unit project itself and configure it, it does work correctly

borkdude14:10:23

So when I add these deps:

$ cat deps.edn
{:deps {garden/garden {:mvn/version "1.3.10"}
        garden/garden-units {:mvn/version "1.0.0-RC2"}}}

borkdude14:10:35

and then run:

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

borkdude14:10:47

and then run:

clj-kondo --lint src/clj_kondo/poc/styles.cljs

borkdude14:10:51

I see no warnings anymore

borkdude14:10:15

So this must be a problem with #CPABC1H61 and perhaps the shadow-cljs.edn deps / cc @UKFSJSM38

borkdude14:10:44

I don't see the garden-units library appear when doing this:

npx shadow-cljs classpath

borkdude14:10:49

could that be part of the issue?

ericdallo14:10:13

probably, clojure-lsp just do programatically those clj-kondo calls you pasted

👍 1
ericdallo14:10:38

actually, clojure-lsp merges the classpath of both deps.edn + npx

ericdallo14:10:53

the lsp-clojure-server-info should show the classpath

borkdude14:10:38

rm -rf .clj-kondo/.cache
clj-kondo --lint $(npx shadow-cljs classpath) --dependencies
clj-kondo --lint src/clj_kondo/poc/styles.cljs
src/clj_kondo/poc/styles.cljs:6:6: warning: Unsorted namespace: garden.units

borkdude14:10:46

(that unsorted warning comes from my home config)

borkdude14:10:52

So this sequence of commands seems to work

ericdallo14:10:11

and that warning is expected, right?

ericdallo14:10:39

let me try the repro

borkdude14:10:44

and now I also get no warning when deleting the caches again and restarting the project

borkdude14:10:04

@U03PYN9FG77 Could it be that you just need to run npm install in this project first?

ericdallo14:10:48

@U04V15CAJ what is the repro exactly on that repo?

borkdude14:10:25

@UKFSJSM38

src/clj_kondo/poc/styles.cljs:6:27: warning: Unresolved var: deg

borkdude14:10:08

but I can't repro that anymore

borkdude14:10:14

oh wait, maybe remove my deps.edn again

ericdallo15:10:41

I can repro the warning. The project doesn't have any deps.edn right? so the only classpath option is from npx

ericdallo15:10:46

and npx shadow-cljs classpath returns "~/.m2/repository/garden/garden/1.3.10/garden-1.3.10.jar , is the hook inside that version?

borkdude15:10:50

I can only repro it from a clean state

agorgl15:10:35

I tried fresh clone -> npm i -> clj-kondo --lint $(npx shadow-cljs classpath) --dependencies , opening my editor in styles.cljs and I can still repro it

ericdallo15:10:14

I did the same without calling clj-kondo, just opening with clojure-lsp, which should end in the same

borkdude15:10:20

The fact that npx shadow-cljs classpath isn't showing this units library is weird right?

ericdallo15:10:37

oh if the hook is inside that units library, that's the problem indeed.

ericdallo15:10:27

I only see garden on shadow-cljs.edn, shouldn't you include garden/garden-units as well?

agorgl15:10:57

I don't think it is a separate library / dependency

borkdude15:10:12

This is confusing since there is also a library with that namespace

☝️ 1
borkdude15:10:47

but ok, that mystery is solved

ericdallo15:10:23

so, no bugs anywhere right? :) just confusing deps/ns

agorgl15:10:14

Well there is still a confusing warning

ericdallo15:10:42

AFAICS that happens because npx classpath doesn't include garden/garden-units which has the hook, only garden/garden

borkdude15:10:13

I also needed to add garden.units/defunit clojure.core/def to the config

agorgl15:10:25

What hook?

ericdallo15:10:38

yeah, my bad, @U04V15CAJ is correct, adding that config is enough to solve since the problem is the defunit not being recognized as a macro that defines a var

agorgl15:10:11

Ah damn, I literally tried this before as I described at first message

agorgl15:10:17

In a clean clone works

agorgl15:10:25

Cache was not my friend

agorgl15:10:59

@U04V15CAJ any good tip to make defglobal Unused public var disappear too?

borkdude15:10:47

unused public var is @UKFSJSM38’s department ;)

agorgl15:10:23

I just have to say

agorgl15:10:38

You are probably the best community I've ever encountered in my whole career

❤️ 2
agorgl15:10:56

Thanks guys, you inspire me to become a Clojurist

gratitude 1
agorgl15:10:08

Updated re-frame template fix PR, I hope the maintainer accepts it soon

agorgl15:10:13

Have a nice day!