This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-24
Channels
- # announcements (8)
- # aws (12)
- # babashka (84)
- # beginners (380)
- # calva (56)
- # clj-kondo (52)
- # cljdoc (4)
- # cljs-dev (327)
- # cljsrn (4)
- # clojure (154)
- # clojure-italy (5)
- # clojure-nl (3)
- # clojure-uk (21)
- # clojurescript (52)
- # conjure (133)
- # cursive (64)
- # datomic (33)
- # emacs (22)
- # fulcro (35)
- # graalvm (24)
- # graphql (1)
- # kaocha (1)
- # leiningen (1)
- # off-topic (24)
- # onyx (2)
- # pathom (10)
- # re-frame (3)
- # reagent (3)
- # reitit (3)
- # shadow-cljs (48)
- # spacemacs (12)
- # tools-deps (98)
- # xtdb (7)
Hey @borkdude, we have released a new version of the Datalog parser: https://github.com/lambdaforge/datalog-parser/ for our next release of Datahike. It now supports more of Datomic's Datalog like pagination and limits. Feel free to bump the dependency in clj-kondo when you have the time.
Right now I added a pure Emacs based local auto-complete, works pretty well, especially since it handles unbalanced forms. But I'm trying to add java auto-complete, and if I wanted to auto-complete the methods, I'd need to know the type hint of the local ideally.
So I'm not sure I'd benefit from clj-kondo local analysis, but I guess I'm curious what it has, maybe there's some good stuff in there I could use 😄
clj-kondo currently only analyzes arities from standard Java classes and only when you're calling a static method.
$ clj-kondo --lint - <<< '(Thread/sleep 1 2 3)'
<stdin>:1:1: error: java.lang.Thread/sleep is called with 3 args but expects 1 or 2
linting took 12ms, errors: 1, warnings: 0
I'm actually using jar
and javap
for java, not clj-kondo as of now, thought clj-kondo had no java support whatsoever
it's limited. I analyzed these arities from javadoc sources, but I want to migrate it to some reflection based solution maybe one day. but in practice I don't see these java arity errors that often, so maybe it's not worth putting time in this
What I could use is if clj-kondo analysis could list the java imports in a given namespace, and it if could tell me the type hint of vars and local bindings
@didibus I think the imports are good to add, you already made an issue for it right? Type hints: it doesn't have that information
That way maybe I could take a stab at listing the methods for it. But I don't know, might not be worth the effort.
hmm, it might have that information because:
$ clj-kondo --lint - <<< '(defn foo [x] (let [^String y x] (inc y)))'
<stdin>:1:39: warning: Expected: number, received: string or nil.
but it doesn't remember the exact class, only if it matches one of the types that the "type system" can handle
And possibly the same for globals:
(defn get-bla ^Bla [a] ...)
And on the var-definition it would say: :type-hint "Bla"
something like that@borkdude We already test that in our repository. The only thing you need to do is bump the dependency. I can open a PR for that if you prefer that.
I just wondered if there is anything new that clj-kondo catches and if this should be mentioned in the release notes
clj-kondo doesn't macro expand? it reports a lot of error such as error: status-im.utils.email/send-email is called with 2 args but expects 3
where send-email
is a defined with a macro that creates a multi-arity fn taking 2 or 3 arguments
@yenda clj-kondo only expands a selected set of macros from clojure.core and some popular community libraries. See - https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#lint-a-custom-macro-like-a-built-in-macro - https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#exclude-unresolved-symbols-from-being-reported how to deal with this
switching from cljfmt to clj-kondo we get 600 warning 😄 from the doc it doesn't look like there is an equivalent of cljfmt fix in clj-kondo?
@yenda can you give more context?
user=> (fn [^number x])
Syntax error (IllegalArgumentException) compiling fn* at (REPL:1:1).
Unable to resolve classname: number
is this CLJS maybe?File: /home/yenda/status-react/src/status_im/ethereum/ens.cljs:108:27
--------------------------------------------------------------------------------
105 | ;; a length of 32 bytes
106 | ;; 1 byte is 2 chars here
107 | [next-field-length-hex raw-hash-rest] (split-at 64 raw-hash-rest)
108 | next-field-length (* (abi-spec/hex-to-number (string/join next-field-length-hex)) 2)
---------------------------------^----------------------------------------------
Error in phase :compilation
cljs.core/*, all arguments must be numbers, got [#{nil clj-nil} number] instead
{:warning :invalid-arithmetic, :line 108, :column 27, :msg "cljs.core/*, all arguments must be numbers, got [#{nil clj-nil} number] instead"}
ExceptionInfo: cljs.core/*, all arguments must be numbers, got [#{nil clj-nil} number] instead
in CLJS I don't get an error about this:
$ clj-kondo --lint - --lang cljs <<< '(fn [^number x] x)'
linting took 12ms, errors: 0, warnings: 0
I get it for this line:
next-field-length (* ^number (abi-spec/hex-to-number (string/join next-field-length-hex)) 2)
well clj-kondo should recognize that from the .cljs extension, so that's probably not it then
yeah I still get src/status_im/ethereum/ens.cljs:108:31: error: unresolved symbol number
yenda@desktop:~/status-react$ clj-kondo --lint - --lang cljs <<< '(fn [x] (* ^number x 1))'
<stdin>:1:13: error: unresolved symbol number
linting took 7ms, errors: 1, warnings: 0
it should probably be added here: https://github.com/borkdude/clj-kondo/blob/846bdb9a4f5f2b39bb6e96c6b3a7f3a4c9afcd0c/src/clj_kondo/impl/metadata.clj#L31