Fork me on GitHub
#clj-kondo
<
2022-10-10
>
JR00:10:31

Is there a way to use the repl to launch the clj-kondo? When I use Calva to Jack-in, and then evaluate main.clj, I get

clj꞉clj-kondo.main꞉> 
; Evaluating file: main.clj
; Syntax error (ClassNotFoundException) compiling at (src/clj_kondo/main.clj:1:1).
; clj-kondo.main
; Evaluation of file main.clj failed: class clojure.lang.Compiler$CompilerException
I've been looking into https://github.com/clj-kondo/clj-kondo/issues/1824 and it would be great to either use the REPL when making code changes, or to debug the code with something like flow-storm. I can do builds as they are described on https://github.com/clj-kondo/clj-kondo/blob/master/doc/build.md, but doing a full build is slow.

borkdude09:10:50

Yes, of course, you can use clj-kondo from the REPL:

$ clj
Clojure 1.11.0
user=> (require '[clj-kondo.main])
nil
user=> (require '[clj-kondo.core :as clj-kondo])
nil
user=> (:findings (with-in-str "(+ :foo)" (clj-kondo/run! {:lint ["-"]})))
[{:filename "<stdin>", :row 1, :col 4, :end-row 1, :end-col 8, :type :type-mismatch, :message "Expected: number, received: keyword.", :level :warning}]

borkdude09:10:07

Thanks for looking into the issue. Let me know if you need more info.

borkdude09:10:31

Oh, let me also try the jack-in in Calva

borkdude09:10:05

Works fine over here. I chose jack-in, deps.edn, alias clj-kondo/dev

JR13:10:52

Thanks! This is among my first dive into a real-world clojure project, so I appreciate the guidance

nonrecursive15:10:26

hey y’all, I’ve added this to my config.edn yet I’m still getting a warning:

{:linters
 {:unresolved-symbol
  {:exclude [(clojure.test/is [match?])]}}}
Any idea what might be going on here? One place I’m getting a warning is https://github.com/donut-power/datapotato/blob/main/datapotato/test/donut/datapotato/atom_test.cljc#L74

🥔 1
🎉 1
imre16:10:16

[matcher-combinators.test :refer [match?]] is how I solve this

borkdude16:10:51

you might also have to add cljs.test in the config

nonrecursive16:10:55

adding cljs.test fixed it! thank you

tedcushman16:10:34

I have been trying to figure out how to resolve an unexpected inline def warning related clojure.spec. The :inline-def occurs when using inline keys specs inside a def or defn, for example:

(require '[clojure.spec.alpha :as s])
;; Simplified case
(def foo (s/keys :req-un [::abc] :opt-un [::xyz]))
;; Basic use case
(defn gen-my-map [] (s/gen (s/keys :req-un [::abc] :opt-un [::xyz])))
I get warnings for these using version 2022.10.05 and other recent versions. I know the specs are macro driven, but I don't see any signs that keys generates any defs.

1
borkdude17:10:46

I can't reproduce this locally. Can you make a standalone file including extension and upload it here? Back in an hour.

tedcushman17:10:22

Ugh, I created a test file and get the warning in one project, but not in another, even with the config.edn moved out of the way. Looks like I need to work a little more on reproducing this.

tedcushman17:10:55

Here is the example as a file. Sometimes I get warnings, sometimes I don't, still trying to figure out what triggers the different results. (cache, configuration, copied configurations, etc.)

tedcushman17:10:58

Usually I get the following output when checking the file above, but sometimes I don't. Haven't found a clear pattern yet.

$ clj-kondo --version
clj-kondo v2022.10.05

$ clj-kondo --lint inline_spec.clj
inline_spec.clj:4:10: warning: inline def
inline_spec.clj:7:28: warning: inline def
linting took 12ms, errors: 0, warnings: 2

tedcushman17:10:59

Nevermind, I found the following nonsense in my global config.edn file.

{:lint-as {clojure.spec.alpha/keys clojure.core/def}}
Don't know how that got there. Thanks for looking into this.

borkdude17:10:24

Ah, glad it's solved now :)

sheluchin19:10:00

Fulcro has a large collection of generated DOM element factory https://github.com/fulcrologic/fulcro/blob/d9f6090219900798fb2f6640cf44d6c319a4f99f/src/main/com/fulcrologic/fulcro/dom.cljs#L17 with server and client support. clj-kondo doesn't provide arglists or docstrings for these factories in the :var-definition analysis. Is there a recommended way of dealing with things like this?

sheluchin19:10:51

Here is the definition for it:

[{:end-row 30
     :meta nil
     :name-end-col 11
     :name-end-row 17
     :name-row 17
     :ns com.fulcrologic.fulcro.dom
     :name a
     :defined-by cljs.core/declare
     :filename "fulcrologic/fulcro/src/main/com/fulcrologic/fulcro/dom.cljs"
     :col 1
     :name-col 10
     :end-col 45
     :row 17}

sheluchin19:10:30

Whereas the generated docstring for all of them is like this:

*com.fulcrologic.fulcro.dom/div*
  [& args]
  Returns a React DOM element. Can be invoked in several ways

These two are made equivalent at compile time
(div "hello")
(div nil "hello")

These two are made equivalent at compile time
(div {:onClick f} "hello")
(div #js {:onClick f} "hello")

There is also a shorthand for CSS id and class names
(div :#the-id.klass.other-klass "hello")
(div :#the-id.klass.other-klass {:onClick f} "hello"))

sheluchin19:10:43

The :var-usages info also does not include :arity:

{:end-row 6
     :name-end-col 51
     :name-end-row 6
     :name-row 6
     :name div
     :filename "ui/reports/function_profile.cljs"
     :from ui.reports.function-profile
     :col 48
     :name-col 48
     :end-col 51
     :refer true
     :row 6
     :to com.fulcrologic.fulcro.dom}
That is produced from this code:
(div :.sixteen.wide.column.segment "test")

borkdude20:10:33

To make this more tooling friendly, one could choose to generate the code to disk instead of only via a macro at compile time

borkdude20:10:59

Or write a hook which expands this call into stuff that clj-kondo understands better

sheluchin20:10:20

Is there a way to write a single hook that would cover all of those generated items? They essentially expand to the same kind of form and all have the same (almost) docstring.

borkdude20:10:54

a single hook yes, but you would need to have a mapping for all of those vars in the config currently

borkdude20:10:07

so {foo/a hook foo/b hook foo/c hook} etc

sheluchin20:10:26

That would only help with the :var-usage data and not the :var-definition, right?

sheluchin20:10:40

Haven't written any hooks myself yet..

borkdude20:10:39

that would help with var-definition since you can expand this into a hook which generates the right var definition

sheluchin20:10:49

Alright, thank you. I will do it for these Fulcro items. Are you otherwise interested in receiving reports about such analysis peculiarities? I'm running clj-kondo analysis on many libraries and trying to fit the results into a normalized SQL schema. In most cases things work just as they should but there are quite a number of mismatches across the ecosystem. By mismatches I mean cases where a var usage doesn't match up to some expected var definition foreign key.

borkdude20:10:40

Yeah, sure, anything that can improve the quality of the analysis is surely welcome

borkdude20:10:55

And I appreciate your work on this so far

sheluchin21:10:44

Happy to help! I'm thinking if I create a mismatch report it could help identify the libraries that need the most help or have the biggest ecosystem impact.

👍 1