This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-29
Channels
- # announcements (6)
- # babashka (23)
- # beginners (15)
- # biff (15)
- # calva (17)
- # clara (5)
- # clj-kondo (41)
- # cljdoc (2)
- # cljs-dev (67)
- # cljsrn (18)
- # clojure (19)
- # clojure-europe (25)
- # clojure-nl (2)
- # clojure-norway (9)
- # clojure-uk (2)
- # clojurescript (26)
- # core-typed (6)
- # cursive (15)
- # data-science (30)
- # datahike (1)
- # datomic (18)
- # docker (6)
- # emacs (10)
- # events (2)
- # graalvm (15)
- # graphql (5)
- # hugsql (4)
- # jobs-discuss (1)
- # joker (7)
- # lsp (36)
- # malli (28)
- # off-topic (46)
- # other-languages (1)
- # pathom (5)
- # pedestal (6)
- # polylith (5)
- # reitit (2)
- # releases (1)
- # rewrite-clj (63)
- # shadow-cljs (7)
- # spacemacs (16)
- # squint (6)
- # tools-deps (6)
- # xtdb (13)
: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
)
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?
takes long drag on joint @robert-stuttaford it's just data dude_:_ https://github.com/clj-kondo/clj-kondo/blob/master/analysis/README.md
i guess i have to learn clj-kondo analysis don't i š
@robert-stuttaford there are some examples at the end of the document
thank you sir!
lol 82mb edn file. not editing THAT with emacs
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)))
Sometimes I create a test namespace where I import kondo and do a few assertions about analisys, to ensure project wide things.
I've run into an oddity I didn't expect. unused-binding {:exclude-destructured-as true}
warns on vector :as
bindings
$ 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
https://github.com/clj-kondo/clj-kondo/issues/1821 and https://github.com/clj-kondo/clj-kondo/pull/1822
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.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 š
4500 files??? š
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
@U4YGF4NGM There could be a faster way, possibly, but with more false positives
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
@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
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
each run of the script re-analyzes the repo (taking 90+ seconds), destroying my brain š§
@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)
it might be good to do some caching yourself: skip linting this and that file / dir if you don't have any changes
clj-kondo doesn't contain a lot of magic, it just analyzes/lints whatever you throw at it
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 š