Fork me on GitHub
#clj-kondo
<
2020-04-10
>
borkdude09:04:49

Aaah, light weight type checking.

💯 16
Adrian Smith13:04:17

I'm looking to build something that enforces specs on data|functions via lsp, do you know if there's a good library in Clojure for LSP? I can see clojure-lsp is using org.eclipse.lsp4j under the hood I can't work out what kondo-clj is using

borkdude13:04:16

@sfyire that code is here. it's based on how clojure-lsp is using the lsp4j library: https://github.com/borkdude/clj-kondo.lsp/tree/master/server

borkdude16:04:55

Does this make sense? Automatically shutting off the unresolved symbol linter in macros? I'm playing with the idea, but it has pros and cons maybe.

seancorfield16:04:51

It's a bit of a sledgehammer... I don't think I'd want it to be the default?

seancorfield17:04:39

@borkdude This is puzzling -- I have the following import:

(:import (org.apache.oltu.jose.jws
            JWS$Builder
            signature.impl.SymmetricKeyImpl
            signature.impl.SignatureMethodsHMAC256Impl)))
and these two functions:
(defn signer [] (SignatureMethodsHMAC256Impl.))

(defn symkey [k] (SymmetricKeyImpl. k))
but clj-kondo flags the signature.impl imports as being unused.

seancorfield17:04:13

If I change the import to this, it no longer flags them:

(:import (org.apache.oltu.jose.jws JWS$Builder)
           (org.apache.oltu.jose.jws.signature.impl
            SymmetricKeyImpl
            SignatureMethodsHMAC256Impl)))

borkdude17:04:56

Feel free to post an issue about this.

seancorfield18:04:59

Nah, I'm going to bow to clj-kondo's limitation here because nested imports are less readable (and it's already discouraged for requires).

borkdude17:04:38

clj-kondo apparently doesn't understand that nested import syntax (unlike nested namespace requires, which are discouraged in some style guides). I think I encountered this in tools.reader once and @bronsa's reaction was this: https://github.com/clojure/tools.reader/commit/97d5dac9f5e7c04d8fe6c4a52cd77d6ced560d76

seancorfield18:04:55

Yup, that's basically what I did to that code that was reporting the problem 🙂 It's probably clearer than what I had before anyway.

borkdude17:04:22

I guess clj-kondo could add support for it, but I haven't seen it a lot myself out there

borkdude17:04:47

Re: the macro sledgehammer idea: https://clojurians.slack.com/archives/CHY97NXE2/p1586536435275900 I tried implementing a linter which reports when you use a macro as a value. like (filter when [1 2 3]), but it resulted in quite a lot of false positives since you can pass any symbol to macros without it being resolved as vars.

borkdude17:04:24

So I thought it would be useful to capture at least what all used macros in a code base are named so it can be used to suppress certain things

borkdude17:04:46

But maybe just a configuration to suppress these, like any other linter, will work, without automatically suppressing anything (which would be optional anyway)

borkdude17:04:50

If you're curious what it found and wrote to the cache while linting several libraries: