Fork me on GitHub
#clj-kondo
<
2020-04-24
>
whilo01:04:45

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.

borkdude07:04:37

@whilo A PR is welcome along with maybe a test which tests one of the new things?

borkdude07:04:29

@didibus It does that analysis, but it doesn't expose it.

didibus07:04:14

Ok I see. And, is it able to know the type hints of vars including locals?

didibus07:04:09

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.

didibus07:04:32

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 😄

borkdude07:04:08

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

didibus07:04:48

Oh, I didn't even know it did that. Cool!

didibus07:04:22

I'm actually using jar and javap for java, not clj-kondo as of now, thought clj-kondo had no java support whatsoever

borkdude07:04:22

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

didibus07:04:28

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

borkdude07:04:25

@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

didibus07:04:15

No I made one for refer, I'll make one for imports

borkdude07:04:26

or maybe I'm misunderstanding something about the type hints

didibus07:04:42

I'm thinking something like:

(let [^SomeClass a]
  (-> a (.method 1 2)))

didibus07:04:11

And clj-kondo can tell me the local a is of type-hint SomeClass

didibus07:04:01

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.

borkdude07:04:53

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.

borkdude07:04:21

but it doesn't remember the exact class, only if it matches one of the types that the "type system" can handle

borkdude07:04:29

but it could maybe be made so

didibus07:04:56

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

didibus07:04:36

In any case, wouldn't say its the highest on the list of priority

whilo08:04:59

@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.

borkdude08:04:28

sure, thanks!

borkdude08:04:57

I just wondered if there is anything new that clj-kondo catches and if this should be mentioned in the release notes

yenda09:04:52

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

yenda09:04:49

thank you!

yenda10:04:11

it looks like it doesn't like the ^number tag either unresolved symbol number

yenda10:04:34

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?

borkdude10:04:12

@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?

yenda10:04:26

witout it you get compilation errors

yenda10:04:27

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

borkdude10:04:49

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

borkdude10:04:15

@yenda Please make a small repro

yenda10:04:19

I get it for this line: next-field-length (* ^number (abi-spec/hex-to-number (string/join next-field-length-hex)) 2)

borkdude10:04:45

Can you make a repro, a small file that I can execute/lint locally?

yenda10:04:06

yes will try first this --lang cljs option

yenda10:04:08

maybe that's it

borkdude10:04:29

well clj-kondo should recognize that from the .cljs extension, so that's probably not it then

yenda10:04:04

yeah I still get src/status_im/ethereum/ens.cljs:108:31: error: unresolved symbol number

yenda10:04:05

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

yenda10:04:19

it doesn't like the inline tagging

borkdude10:04:40

issue + PR for this is welcome

borkdude10:04:25

For now you can use:

$ clj-kondo --lint - --config '{:linters {:unresolved-symbol {:exclude [number]}}}'  <<< '(fn [x] (* ^number x 1))'
linting took 10ms, errors: 0, warnings: 0

yenda10:04:39

yea that is what I did

yenda10:04:10

ok added an issue might give a shot to a pr later

yenda10:04:17

so there is no equivalent of cljfmt fix that automatically fixes the warnings right?