Fork me on GitHub
#clj-kondo
<
2022-09-29
>
vemv00:09:45

:discouraged-var rocks! I give it a couple creative usages: 1) fostering an abstraction (vs. a rawer naive approach). Sooner or later every codebase needs this. 2) avoiding functions that aren't dangerous per se, but happen to be incorrect in a certain context (in my case spit - I often spit in the middle of a deftest to update my expectation that is a resource )

šŸŽ‰ 1
robert-stuttaford07:09:56

carve finds unused vars, as does lsp (if you visit the file and see the annotation). how does one list all the namespaces that haven't been required?

robert-stuttaford07:09:46

i guess i have to learn clj-kondo analysis don't i šŸ˜†

borkdude08:09:44

@robert-stuttaford there are some examples at the end of the document

borkdude08:09:59

it's basically: collect all defined namespaces and subtract all used namespaces

robert-stuttaford08:09:04

lol 82mb edn file. not editing THAT with emacs

robert-stuttaford08:09:17

nice, got it:

;; clj-kondo --lint dev src test --config '{:output {:format :edn}, :analysis true :var-usages false :var-definitions {:shallow true}}' | jet --func '#(-> % :analysis (select-keys [:namespace-definitions :namespace-usages]))' > kondo.edn

  (def ka (-> "kondo.edn" slurp edn/read-string))

  (set/difference (into (sorted-set) (map :name) (:namespace-definitions ka))
                  (into (sorted-set) (comp (map :to) (remove string?)) (:namespace-usages ka)))

šŸŽ‰ 2
souenzzo09:10:13

Sometimes I create a test namespace where I import kondo and do a few assertions about analisys, to ensure project wide things.

šŸ‘ 2
Noah Bogart15:09:01

I've run into an oddity I didn't expect. unused-binding {:exclude-destructured-as true} warns on vector :as bindings

Noah Bogart15:09:11

$ echo '(let [{a :a :as b} {:a 2} [c :as d] (range 2)] (prn [a c]))' | clj-kondo --config '{:linters {:unused-binding {:level :error :exclude-destructured-as true}}}' --lint -
<stdin>:1:34: error: unused binding d
linting took 5ms, errors: 1, warnings: 0

borkdude15:09:21

Issue welcome

šŸ‘ 1
lilactown16:09:11

I'm trying to look for ways to speed up analysis of a very large codebase. currently, analysis takes ~90s on my fancy m1 MBP. what i've tried so far: ā€¢ skip linting ā€¢ parallel true ā€¢ skipping var definitions here's how i'm running the analysis

(kondo/run!
 {:lint src-files
  :parallel true
  :skip-lint true
  :config {:output {:analysis {:var-definitions false}}}})
I do need var usages. However, I only need var usages of specific namespaces. Is it possible to speed up analysis by customizing what data it actually looks for? I was previously doing this with grasp, where each ns I was looking for took ~30s to find all usages. clj-kondo scales much better than this obviously, but I'm writing a tool that people might use at the CLI, so I want it to be as fast as possible.

lilactown16:09:54

for reference, it's about 4500 clojure files it's analyzing. so i'm not like, appalled at the perf here. just want to make it better šŸ˜„

Noah Bogart16:09:18

4500 files??? šŸ‘€

lilactown16:09:50

close

$ find . -type f -name '*.clj' | wc -l
3534
$ find . -type f -name '*.cljs' | wc -l
668
$ find . -type f -name '*.cljc' | wc -l
306

borkdude18:09:19

@U4YGF4NGM There could be a faster way, possibly, but with more false positives

borkdude18:09:51

So if you're interested in inaccurate results with better performance, I'm sure that can be done, but so far the tools that use clj-kondo don't want inaccurate results

borkdude19:09:36

@U4YGF4NGM Another thought: have you tried tools.analyzer? Not sure what the performance of that is for this use case, could be better or worse. Curious

lilactown20:09:27

l havent tried tools.analyzer

lilactown20:09:57

i do want accuracy

lilactown22:09:30

I wonder if we could the analysis along with the linting info?

borkdude06:09:43

This is already the case: :findings and :analysis

lilactown15:09:24

if I have a script that runs clj-kondo, can I ensure that it stores and uses the cache? it doesn't seem to be

lilactown15:09:55

each run of the script re-analyzes the repo (taking 90+ seconds), destroying my brain šŸ§ 

borkdude15:09:36

@U4YGF4NGM This requires the existence of a .clj-kondo directory or an explicit :cache argument. The cache is only read for information from other namespace, it doesn't skip analysis for things it has already seen before (as it might have changed)

borkdude15:09:05

Are you linting any .jar files?

lilactown15:09:21

i'm not trying to, but there are probably jars on disk

borkdude15:09:06

it might be good to do some caching yourself: skip linting this and that file / dir if you don't have any changes

borkdude15:09:26

clj-kondo doesn't contain a lot of magic, it just analyzes/lints whatever you throw at it

lilactown15:09:40

yeah, was wondering of kondo might already handle that for me

lilactown15:09:12

ultimately it doesn't matter so much, this is going to run in CI for the most part where if it takes a few minutes it's ok. just the development loop sucks šŸ˜„

lilactown15:09:20

trying to solve MY problem not THE problem rn

borkdude15:09:03

I would say: save your analysis on disk under a content hash and content hash the analyzed file too

borkdude15:09:09

and then it becomes obvious what to skip

borkdude15:09:37

or work with a smaller input in dev