Fork me on GitHub
#clj-kondo
<
2021-08-25
>
mafcocinco02:08:07

Is there a place to track enhancement requests for clj-kondo? I noticed that clj-kondo stops warning about a private function which is not used if that function is overloaded.

mafcocinco02:08:33

Would be nice to not only retain the warning but perhaps highlight the specific functions which are not called.

seancorfield02:08:34

@mafcocinco Do you mean, e.g., warning about the 2-arity not being used if there's a 1-arity version and it is used?

seancorfield02:08:48

(trying to figure out what you mean by "overloaded")

mafcocinco02:08:30

yes, overloaded on arity. And yes to your first comment, though it seems like it also a bug as the warning never shows up for any arity.

seancorfield02:08:58

Interesting. I hadn't noticed that. I'll keep an eye out for that.

👍 4
Joshua Suskalo02:08:50

That might be a little hard to track effectively since apply exists.

Joshua Suskalo02:08:16

That is, you can't just track places the symbol is used anymore if you want to track which arity is being used.

Joshua Suskalo02:08:03

(defn some-func
  ([a] [a])
  ([a b] [a b]))

(map some-func data-1 data-2)
In order for this to know that the 2-arity is being used but not the 1-arity, it has to know what map does, which means we have to have special casing or do much more advanced static analysis. Special casing breaks down on user-defined functions, and advanced static analysis is probably outside the scope of clj-kondo.

Joshua Suskalo02:08:47

The only relatively easy way to solve this issue as far as I can tell would be to only use this linter if the only place the var is used is directly as a function call with a fixed number of arguments, but then the linter isn't very useful imo.

Joshua Suskalo02:08:09

But whether or not that use is enough to warrant the implementation is up to the people who would implement it I guess.

seancorfield03:08:45

Good points, yeah.

Jakub Holý (HolyJak)13:08:48

Hello! Do I need to do something special to enable Schema support in kondo? Currently it complains about "Unresolved symbol: User" here:

(require '[my.schemas :refer [User]] '[schema.core :as s])
(s/defn admin-user?
  [user :- User]
  ...)
Update: This is weird, running clj-kondo manually works just fine. The error is shown in Cursive via LSP

borkdude13:08:47

Schema support is built into clj-kondo. Your example works in my emacs + vanilla clj-kondo: Are you perhaps using clojure-lsp?

3
Jakub Holý (HolyJak)13:08:19

exactly, clojure-lsp in Cursive

borkdude13:08:51

interesting. are you sure the warning in your case is coming from clj-kondo?

borkdude13:08:10

and not from cursive for example

borkdude13:08:10

Very interesting. Could you make a zip of .clj-kondo/.cache and send it to me, if it doesn't contain any sensitive info? @UKFSJSM38 and me are trying to solve this issue for some time now

👍 3
borkdude13:08:14

The workaround is to remove .clj-kondo/.cache and .lsp/sqlite.db and then restart your workspace, but we would love to have some data to debug

ericdallo13:08:42

Is that the same issue of cache removals? The User seems to be a schema from the project itself, not external deps

3
ericdallo13:08:56

anyway, a zip would help confirm it indeed 🙂

borkdude13:08:32

yes, it would help if the screenshot also showed where User is coming from

borkdude13:08:40

more details = more better...

☝️ 3
borkdude13:08:23

btw, it's interesting you're using Cursive. I think it would be useful to have some docs around how to use clojure-lsp in cursive

ericdallo13:08:56

Yeah, actually I didn't know both would work fine together :thinking_face:

Jakub Holý (HolyJak)14:08:47

I will send the zip later today. Do y have Keybase or what do you prefer? The schema is defined in another ns and required with :refer :all

Jakub Holý (HolyJak)14:08:31

But how goes kondo cache help? I've run kondo from CLI and that was just fine, I assume it used the cache. Since the problem only appears in kondo via lsp, you perhaps need (also).lsp (or, in the case of IntelliJ, there is also lsp (without dot))

ericdallo14:08:00

.lsp/sqlite.db is the folder used by clojure-lsp just for caching external analysis, when we remove it, clojure-lsp re scan the whole classpath again using clj-kondo (which should cache that on .clj-kondo/.cache as well)

borkdude14:08:50

@U0522TWDA the command line version only uses the cache created by the editor if both clj-kondo versions are exactly the same

ericdallo14:08:21

good point, probably your clj-kondo cli version is different from the one used by clojure-lsp

Jakub Holý (HolyJak)14:08:26

No, both versions are the same

borkdude14:08:07

you can check is to see if there is only one recent .clj-kondo/.cache/* dir in there

borkdude14:08:15

and not two different ones, I mean inside the .cache dir

Jakub Holý (HolyJak)15:08:21

Sorry 😢 I have restarted LSP from Cursive and it does not show the error anymore.

Jakub Holý (HolyJak)15:08:13

Good news! I deleted kondo cache and restarted LSP and re-opened the file and see the error again

Jakub Holý (HolyJak)15:08:01

interestingly, I do NOT have .clj-kondo/.cache/ in the project dir now

Jakub Holý (HolyJak)15:08:46

the only relevant thing I seem to have is ./lsp/

borkdude15:08:45

restart cursive itself perhaps

borkdude15:08:00

now I'm really confused ;)

ericdallo15:08:08

hum, even if your classpath is cached on .lsp/sqlite.db , clojure-lsp calls clj-kondo to lint the project paths at every startup, then it should create a .clj-kondo/.cache (only if you have a .clj-kondo folder)

Jakub Holý (HolyJak)15:08:34

Me too. Now the problem is there even in CLI:

❯ java -jar ~/Downloads/clj-kondo-2021.08.06-standalone.jar --lint src/mine/core.clj
src/mine/core.clj:4:35: warning: use alias or :refer
src/mine/core.clj:38:12: error: Unresolved symbol: User

ericdallo15:08:57

what makes sense because there is no cache, right @U04V15CAJ?

borkdude15:08:13

@U0522TWDA Please provide more details. The complete source.

☝️ 3
borkdude15:08:00

it looks like you're using :refer :all or something (from the linter warning I can see that)

borkdude15:08:07

and that's expected not work with without a cache

👍 3
Jakub Holý (HolyJak)15:08:23

Correct, the .clj-kondo/ dir that I deleted recently has not been recreated by running the CLI. @U04V15CAJ I'd love to but it is company property so I cannot really share more than snippets 😿

Jakub Holý (HolyJak)15:08:41

Yes, I am using refer all, I think I mentioned it above

borkdude15:08:03

you need to make LSP re-index your project

ericdallo15:08:10

@U0522TWDA probably you will be able to repro if create a new sample project with schema.core dep?

👍 3
borkdude15:08:14

don't know how to do that in Cursive

Jakub Holý (HolyJak)15:08:51

(ns
  (:require [company.schemas :refer :all] ; User lives here
            [schema.core :as s]))
(s/defn backoffice-user?
  [user :- User]
  ...)

ericdallo15:08:57

> you need to make LSP re-index your project for clojure-lsp, removing .lsp/sqlite.db or changing anything in your project.clj/deps.edn should work

Jakub Holý (HolyJak)15:08:26

ok, will try to make a repro repo later today. Thank you for all the support!

Jakub Holý (HolyJak)17:08:46

Ok, so if I have (:require [kondo-lsp-cursive-schema-problem.core :refer [User]]) then kondo is happy but if I change it to ...:refer :all then it says "Unresolved symbol: User" @U04V15CAJ do you want a .tbz of the whole project repo or is this a known problem?

ericdallo17:08:40

a public repo on Github would be the best, otherwise a zip/tar.gz is enough as well

borkdude17:08:21

@U0522TWDA That example is expected to work like that, if you don't have a .clj-kondo/.cache with the namespace kondo-lsp-cursive-schema-problem.core linted

borkdude17:08:04

but if you do have .clj-kondo/.cache dir and then you lint that namespace, after that, it should work

Jakub Holý (HolyJak)17:08:13

Ah, I expected that if I open a new project, LSP would index it automatically. Obviously it did not

borkdude17:08:15

so lint the other namespac

borkdude17:08:26

yes, I would expect that too, but I'm not sure why it doesn't

Jakub Holý (HolyJak)17:08:39

How do I get LSP to index anything? I changed a comment in project.clj but still not .clj-kondo ...

borkdude17:08:10

you must create the .clj-kondo dir yourself

3
borkdude17:08:20

only remove the .cache dir from it, not the dir itself

👍 3
borkdude17:08:32

you're expected to host some configuration in that directory

borkdude17:08:38

.clj-kondo/config.edn

borkdude17:08:16

and when you have a .clj-kondo dir, only then will clj-kondo store cache info there

👍 3
ericdallo17:08:37

I wonder if clojure-lsp should always create the .clj-kondo dir in the project. what do you think @U04V15CAJ?

🙏 3
borkdude17:08:47

yes, I'm fine with that

ericdallo17:08:48

otherwise projects without that folder always will have that issue

borkdude17:08:59

just at the same position as .lsp

👍 3
borkdude17:08:27

perhaps also put a config.edn there automatically with just an empty map

borkdude17:08:45

if it doesn't exist

ericdallo17:08:06

> perhaps also put a `config.edn` there automatically with just an empty map I suppose people would think that .clj-kondo/config.edn should not be commited if we do that automatically 😕

ericdallo17:08:32

@U0522TWDA I'll try to repro with clojure-lsp later today, thanks

❤️ 3
Jakub Holý (HolyJak)17:08:33

Added the config there , cache created, problem persists. Both ns are indexed: kondo-lsp-cursive-schema-problem.core.transit.json kondo-lsp-cursive-schema-problem.schemas.transit.json

3
borkdude17:08:50

@U0522TWDA I don't think this repro makes sense. You are referring the same namespace with :refer :all from the namespace itself

borkdude17:08:02

(ns kondo-lsp-cursive-schema-problem.core
  (:require
    ;[kondo-lsp-cursive-schema-problem.core :refer [User]]
    [kondo-lsp-cursive-schema-problem.core :refer :all]
    [schema.core :as s]))

Jakub Holý (HolyJak)17:08:06

> I suppose people would think that `.clj-kondo/config.edn` should not be commited if we do that automatically That is much less of a risk/inconvenience than the current state when linting does not work fully out of the box. (Of course we can blame the user - me - for not reading kondo docs and expecting stuff to just magically do what I want :))

borkdude17:08:31

When I change it to [kondo-lsp-cursive-schema-problem.schemas :refer :all] then it works for me

Jakub Holý (HolyJak)17:08:41

Right, when I fix the require, it works at once

ericdallo17:08:26

> That is much less of a risk/inconvenience than the current state when linting does not work fully out of the box. (Of course we can blame the user - me - for not reading kondo docs and expecting stuff to just magically do what I want :)) But not creating that would not cause the issue, it was just a suggestion, the issue here is the .clj-kondo folder creation

ericdallo17:08:12

so, in the end the issue was the .clj-kondo folder that didn't exists, right?

borkdude17:08:57

I think creating the config.edn is a nice addition: it suggests where people should store their config

💯 3
borkdude17:08:15

perhaps with links to the config page :)

🙏 3
Jakub Holý (HolyJak)17:08:40

In the repro, yes. At work it did/does exist. But when I open it, the cache has only files for very few namespaces, not including the .schemas one. Why could that be?

ericdallo17:08:16

> I think creating the config.edn is a nice addition: it suggests where people should store their config we can do that I think, and re-think if anyone complains

ericdallo17:08:53

> Why could that be? Probably removing both .lsp/sqlite.db and .clj-kondo/.cache would solve

Jakub Holý (HolyJak)17:08:56

No, sorry, missed it, .schemas as well as .core are there

3
borkdude17:08:28

perhaps the indexing broke off with an error?

borkdude17:08:10

I do see this:

$ ls .clj-kondo/.cache/2021.08.07-SNAPSHOT/clj
kondo-lsp-cursive-schema-problem.core.transit.json    kondo-lsp-cursive-schema-problem.schemas.transit.json
which is what I would expect

borkdude17:08:39

well I would also expect some for clojure itself and schema

borkdude17:08:46

so it seems it didn't index deps

☝️ 3
ericdallo17:08:08

I think what happened was:

borkdude17:08:27

oh wait, I have 2 cache dirs:

$ ls .clj-kondo/.cache/2021.07.28/
clj  cljc cljs lock

borkdude17:08:31

so that's the one with all the deps

borkdude17:08:46

but this is using an older clj-kondo it seems

borkdude17:08:00

` $ clojure-lsp --version clojure-lsp 2021.07.28-14.24.06 clj-kondo 2021.07.28

borkdude17:08:04

ah, that makes sense

Jakub Holý (HolyJak)17:08:09

the .schemas transit file does contain the User (thanks, jet !)

ericdallo17:08:40

there was no .clj-kondo dir, clojure-lsp called clj-kondo that linted classpath and lsp saved .lsp/sqlite.db , but nothing saved on .clj-kondo/.cache as the did was not there. After creating the .clj-kondo folder we need to re-scan the classpath to fulfill the clj-kondo cache folder, that's why removing .lsp/sqlite.db should fixes it, WDYT?

borkdude17:08:14

yeah. always ensuring a .clj-kondo dir would fix that problem as well

ericdallo17:08:57

maybe that would solve a lot of headache

borkdude17:08:05

I can see one edge case with this

borkdude17:08:23

what if people have a mono-repo and only one .clj-kondo dir at the top level

borkdude17:08:34

and a shared config for all projects inside the mono repo

borkdude17:08:46

I don't know if this happens a lot

Jakub Holý (HolyJak)17:08:11

not sure where the sqlite is in Cursive+LSP, I have no .lsp, only lsp/ that contains log/ and conf/clojure.json

borkdude17:08:30

that lsp folder is created by the IntelliJ LSP plugin

☝️ 3
ericdallo17:08:00

yeah, ATM it's suggested that you use clojure-lsp at the mono root, not sure if clj-kondo caches would conflict from subproject to subproject though

borkdude17:08:09

The .lsp folder is created by clojure-lsp though. Perhaps it should be called .clojure-lsp? ;)

borkdude17:08:43

ok, let's ignore the mono-repo situation for now, I'm not using that myself in that way, perhaps an edge case to consider later

ericdallo17:08:50

> The .lsp folder is created by clojure-lsp though. Perhaps it should be called .clojure-lsp? 😉 Yeah, there is a issue about that, we would need avoid the breaking changes, but it'd be the ideal indeed

Jakub Holý (HolyJak)17:08:38

Any idea why I do not have that repo created? Is it because the IntelliJ LSP plugin runs clojure-lsp in some other dir or something?

borkdude17:08:23

perhaps the lsp/logs tells something about whether / how its doing stuff?

Jakub Holý (HolyJak)17:08:49

both lsp/log/clojure_out_20210825.log and _err_ are empty though

Jakub Holý (HolyJak)17:08:30

according to https://github.com/gtache/intellij-lsp#faq those files have, I assume, stdout and stderr from clojure-lsp. I will study clojure-lsp docs to figure out where its actual logs are.

ericdallo17:08:17

I think the _err_ is the stderr from the clojure-lsp process, which unless a huge bug prints to that

ericdallo17:08:31

what we want is the custom log from the server, which the plugin (since it's a generic intellij LSP plugin) doesn't know about it, unless the plugin explicitly integrates with, which is what Calva does

👍 3
Jakub Holý (HolyJak)18:08:54

hm, the newest log I found was <.tmpdir>/clojure-lsp.11604520859388497386.out which is from yesterday and has last log from 2021-08-24T13:01:27.545Z

ericdallo18:08:56

you can easily add {:log-path "/tmp/clojure-lsp.out"} in your .lsp/sqlite.db , this will help get the log from the sample place

Jakub Holý (HolyJak)18:08:28

Will do. I have killed the processes and a new clj-kondo-lsp-server-standalone.jar was started but no new logfile

Jakub Holý (HolyJak)18:08:40

Hm, I've created

❯ cat .lsp/config.edn                                                                                                  
{ :log-path "/tmp/clojure-lsp-myapi.out"}
in the [project dir and LSP plugin - restart server, which started a new kondo-lsp-server process, but the log file did not get created (and there is no sqlite.db in the freshly created .lsp dir)

ericdallo18:08:50

Can you use a different folder than tmp? (that's why it's not the default to use tmp, but java tmp folder, for persmisions issues, specially on macos)

Jakub Holý (HolyJak)18:08:35

I have done that now and restarted, still no log

Jakub Holý (HolyJak)18:08:57

Interesting, According to Activity Monitor's Open Files, it does not have any log file open. Also, its CWD is wrong (I have 4 projects open in IntelliJ and it is one of them but not the one which I am actively using now)

ericdallo18:08:26

are you really using clojure-lsp? Can you check if there is a clojure-lsp process running?

Jakub Holý (HolyJak)18:08:30

No, it is not, only clj-kondo-lsp-server-standalone.jar Does it not include clojure-lsp?

ericdallo18:08:30

oh, you are using the clj-kondo LSP project, not clojure-lsp 😅

Jakub Holý (HolyJak)18:08:12

I am sorry, I am new to all this and do not distinguish properly between what is what 🤯

ericdallo18:08:16

they both are LSP servers for clojure and both use clj-kondo, but they do things different

ericdallo18:08:14

even so, it seems that the clj-kondo.lsp has the cache issue as well @U04V15CAJ 😂

Jakub Holý (HolyJak)18:08:08

I see now. Which one of the two should I use? I picked the one b/c that is what clj-kondo pointed me to...

ericdallo18:08:22

I think clojure-lsp is the closest to Cursive, I'd suggest giving it a try https://clojure-lsp.github.io/clojure-lsp/installation/

👍 3
borkdude18:08:10

Yeah, clj-kondo lsp is not clojure-lsp :)

borkdude18:08:16

I can see how that is confusing :)

borkdude18:08:27

the clj-kondo lsp doesn't index your project at all

borkdude18:08:38

you still have to do it manually, clj-kondo is very lazy

borkdude18:08:54

but clojure-lsp is pro-active 💪

😂 3
Jakub Holý (HolyJak)08:08:44

Ok, thx! Then I will switch to clojure-lsp and see how that works. Still, I do not understand why it fails to resolve User in my case because I see the transit file for the schemas ns, which I would believe means that kondo has indexed it. Or?

borkdude08:08:59

It indexes it if you lint it manually on the command line in the presence of a .clj-kondo directory, or if you edit the file in your editor and it gets linted then (also in the presence of a .clj-kondo dir)

borkdude08:08:11

And then it should indeed work. Your repro did work for me.

Jakub Holý (HolyJak)08:08:38

Ah, somehow it works here now as well. I guess it was some timing issue, with kondo's updated info not being propagated all the way via LSP to Cursive.

borkdude13:08:47

@mafcocinco @seancorfield about the private self-referring var that is not considered being unused: this warrants an issue I think, please make one

mafcocinco13:08:47

I think I figured out what is going on. Not sure if it is exactly a bug, but seems like it should be. Posting code in a moment

borkdude13:08:46

yes, that's what I mean, I think self-references should not count as usages for the unused private var linter

👍 3
mafcocinco13:08:48

Given that using one arity of a multi-arity function as an implementation of another is as fairly common pattern, perhaps clj-kondo should ignore the internal usages within the definition of the function?

mafcocinco13:08:50

I will add an issue.

mafcocinco13:08:04

seems like this should apply for all functions, not just private ones, no?

mafcocinco13:08:58

nvm, I suppose you don’t get the warning for public functions. 🐶

borkdude13:08:56

well, clojure-lsp does that but perhaps @UKFSJSM38 already took that into account

ericdallo13:08:16

yeah, that's something to improve/fix on both unused-private-var and clojure-lsp/unused-public-var linters IMO, they consider the function internal usage

borkdude13:08:57

ok, I'll first improve the private one and perhaps the same logic can be applied to the public one. perhaps by adding a :self-ref true or so on the usage

ericdallo13:08:29

LSP code lens are affected by that as well

ericdallo14:08:05

I just wonder if we should just fix the lint, but references and code lenses should still show those usages

borkdude09:08:53

Fixed on master.

gratitude 3
Karol Wójcik13:08:24

Does anybody have the valid hook for shadow.markup.css/defstyled macro? 😄 Example:

(css/defstyled Container :div
  [env]
  {:position "absolute"
   :bottom "24px"
   :right "24px"})

borkdude13:08:37

Probably {:lint-as {... clj-kondo.lint-as/def-catch-all}} works here

Karol Wójcik13:08:35

Yep! It works! Thanks @U04V15CAJ ❤️