Fork me on GitHub
#clj-kondo
<
2022-04-27
>
jacob.maine00:04:09

It takes 713ms (measured by criterium) to analyze (and lint) src/clj_kondo/impl/analyzer.clj itself, with a more-or-less default config. With var-usages disabled, it takes 550ms. It takes 2740ms to analyze all of src/clj_kondo/, and 1955ms with var-usages disabled. That’s 23% and 29% faster, respectively, a modest but somewhat surprising amount. I didn’t expect it to change that much since it’s still doing all the work to find var-usages, just skipping the call to reg-var-usage!. Skipping analysis of def(n) bodies is a more dramatic improvement. 107ms for analyzer.clj and 514ms for src/clj_kondo/, 85% and 81% faster than baseline. I didn’t go to the trouble of turning off any of the linters, though many of them don’t make sense if you don’t analyze var-usages. In quick tests, turning off linters reduces the size of the :findings, but doesn’t decrease overall time much.

2
borkdude07:04:34

@U07M2C8TT That's quite significant. Let's talk in #clj-kondo-dev for further details

Hukka05:04:55

Is there a way to make kondo use namespace aliases as the key for sorting the requires?

borkdude07:04:56

I'm not sure what you mean with this

Hukka07:04:27

So for example

(ns mynamespace
  (:require
    [cljs-http.client :as http]
    [com.fulcrologic.fulcro.dom :as fulcro.dom]
    ))
is how kondo would like them to be, since cljs-http comes before com. But in longer lists that makes it harder to see where the alias is coming from, have to use search. So the option would be to have it sorted by the alias; fulcro before http.

borkdude07:04:33

The reason this isn't supported is that tooling like clj-refactor and clojure-lsp do not respect custom sorting rules

dpsutton20:04:45

I’m seeing cljs.core/clj->js is called with 3 args but expects 1 [invalid arity] in emacs. I tried to reproduce this with clj-kondo from the command line and cannot reproduce though.

❯ echo "(clj->js [1 2] :keyword-fn name)" | clj-kondo --lang cljs --lint -
linting took 115ms, errors: 0, warnings: 0
I’m confused about this discrepancy as i don’t think clojure-lsp would falsely say this because it relies on clj-kondo’s analysis?

borkdude20:04:56

are you running that in the same project?

dpsutton20:04:13

no from /tmp didn’t think project would matter. let me check

dpsutton20:04:29

interesting!

metabase on  master [$?] via :coffee: v17.30 on :cloud:  metabase-query
❯ echo "(clj->js [1 2] :keyword-fn name)" | clj-kondo --lang cljs --lint -
<stdin>:1:1: error: cljs.core/clj->js is called with 3 args but expects 1
linting took 175ms, errors: 1, warnings: 0

borkdude20:04:47

yes, that matters, if there is some other version of clojurescript in your dependencies, then it may have picked up on that

dpsutton20:04:59

we don’t declare a version of clojurescript. we run shadow-cljs from the command line which brings in its own version

borkdude20:04:59

it could be that clojurescript is being brought in via one of your dependencies, an ancient one

dpsutton20:04:29

pattern not found in clj -X:deps tree Is there some fallback version kondo uses?

dpsutton20:04:58

we have lots of exclusions in deps.edn. and nothing brings it in. the version depends on the ambient shadow-cljs used

dpsutton20:04:53

specified in package.json: “shadow-cljs”: “2.11.20",

borkdude20:04:54

clj-kondo uses a fairly recent version of clojurescript as the built in one

borkdude20:04:22

you could try to wipe your .clj-kondo/.cache and .clojure-lsp/.cache

borkdude20:04:29

and then see if it comes back

borkdude20:04:48

be sure to execute lsp-workspace-restart

borkdude20:04:13

if it comes back, my only logical explanation would be that there is an ancient CLJS version on your lsp classpath somewhere

dpsutton20:04:32

killed the cache and its now reporting fine

dpsutton20:04:40

weird. i don’t know how it would have gotten into this state

borkdude20:04:56

do you have any .lsp/config.edn config in this project?

borkdude20:04:31

yes you have

borkdude20:04:37

it uses this classpath:

"clojure" "-A:dev:ee:ee-dev:drivers:drivers-dev" "-Spath

borkdude20:04:41

so I'd take a look in there

dpsutton20:04:44

yes. its just the metabase repo. It was reporting the errors from hsql. not sure how that state got there

dpsutton20:04:55

i’m still not clear on when clj-kondo is aware of deps and not

borkdude20:04:28

well, it is aware of dependencies that it has linted

borkdude20:04:42

and lsp calls clj-kondo on your project dependencies

borkdude20:04:51

or the classpath you have configured in .lsp/config.edn

borkdude20:04:02

"reporting the errors from hsql"?

dpsutton20:04:17

yeah. i can’t recreate it after deleting the cache. sometimes it is aware of honeysql and complains about some macros from there

ericdallo00:04:49

I already say this behavior, but never managed to reproduce, it's pretty rare and usually happens on complex projects, but I have a guess it's related to kondo cache, erasing LSP cache just make we re-scan everything which makes clj-kondo repopulate cache, next time, we can try removing kondo cache first

nottmey21:04:39

Hi, clj-kondo doesn’t seem to understand deftest- :thinking_face:

nottmey21:04:22

Note: Maybe it is confused, because I have this under the src folder

nottmey21:04:29

How do I resolve this?

borkdude21:04:06

That's interesting. I've never heard of deftest- but you can solve it with:

{:lint-as {clojure.test/deftest-i clojure.test/deftest}}

borkdude21:04:15

And an issue is also welcome

nottmey21:04:34

Ok, thanks, will do ☺️

Noah Bogart21:04:04

Opened this feature request issue: https://github.com/clj-kondo/clj-kondo/issues/1671. As I said in it, I would be willing to write the lint.

borkdude21:04:40

This has never happened to me before, but probably because I don't use a lot of pre/post :)

😂 3
Noah Bogart22:04:19

It’s never happened to me either but I've now found it in 3 places in my job's codebase so it seemed worthwhile to add

😮 1
borkdude22:04:55

I always wonder with issues like this if they can be more general

borkdude22:04:21

e.g. (and (number? x) (odd? x) (number? x)) seems a similar case

Noah Bogart22:04:27

That’s a great point. If you're interested I'm willing to write it up, but no worries if you're not

ericdallo00:04:39

redundant-check lint

👍 1
1
borkdude07:04:57

yes, or redundant-condition or so

dominicm09:04:16

What if the check is non-pure?

borkdude09:04:57

@U09LZR36F that is a very good point

😊 1
borkdude09:04:17

so I'm reluctant to support this linter as it doesn't seem that important to me and it could possibly lead to false positives

ericdallo12:04:58

maybe support it for just core stuff or things that should not have side effect?

borkdude12:04:56

I reacted on the issue. I don't think this is important enough to justify the effort

👍 1
borkdude12:04:48

if you really still want to find duplicates in your code, you can use grasp. I'll give a link later today

dominicm12:04:30

Grasp-powered custom linters?

borkdude12:04:28

you could also implement a hook on defn to implement the linter yourself

borkdude12:04:01

No is temporary though, if more users request this, might change.

👍 1
borkdude12:04:53

you can leave the issue open if you want

👍 1
Noah Bogart12:04:25

Will do! I like writing these things so if others end up wanting it, I’ll still be willing to do it