Fork me on GitHub
#clj-kondo
<
2021-11-24
>
Noah Bogart14:11:03

does clj-kondo respect type hints for non-primitives when linting function calls?

Noah Bogart14:11:24

(defn ^DBObject find-one
  "Returns a single DBObject from this collection matching the query."
  ([^DB db ^String coll ^Map ref]
     (.findOne (.getCollection db (name coll))
               (to-db-object ref))))
coll here is type hinted as a String which doesn’t change anything about how the function actually works (due to the name call), but if I write (mg/find-one db :example {}), I get an error about find-one requiring a string

borkdude14:11:41

if you hint it as a string, clj-kondo will think you will have to pass a string or nil there.

Noah Bogart14:11:59

any way I can disable this?

borkdude14:11:31

why would you add a type hint that doesn't do anything?

Noah Bogart14:11:43

i didn’t write the library, so I don’t know lol

borkdude14:11:34

you're trying to solve lint warnings in libraries?

borkdude14:11:57

oh I get it, you're calling the function and then get the lint warning

borkdude14:11:00

you can override this with {:linters`{:type-mismatch {:namespaces {library {function {:arities {3 {:args [:any :any :any]}}}}}}}}`

👍 1
Noah Bogart14:11:07

cool, thank you.

hugod15:11:26

In a hook, what’s the best way of adding clj-kondo suppression of certain lints (on the re-written code)? The re-written code defines some things that may not be used.

borkdude15:11:55

emit code that uses the things

borkdude15:11:04

just a vector with the things for example

hugod15:11:25

of course, that works - thanks

chrisn15:11:44

For clj-kondo integration with emacs, there are three possibilities - flycheck-clj-kondo, anakondo, and flymake-kondor. IS there are clear recommendation from the community as to which one is preferred?

Derek15:11:20

If you already use flycheck, flycheck-clj-kondo

borkdude16:11:04

@chris441 I'm using and maintaining flycheck-clj-kondo myself. But I'm also using clojure-lsp. If I wasn't maintaining clj-kondo myself, I might not be using flycheck-clj-kondo since clojure-lsp already packages clj-kondo.

borkdude16:11:32

But as I'm always on the latest master, I'm using flycheck-clj-kondo separately from clojure-lsp.

Derek16:11:58

flymake is built in to emacs, so some people prefer that. especially if they’re using eglot

ericdallo16:11:05

@chris441 check https://clojure-lsp.io/features/, clojure-lsp uses kondo under the hood

chrisn17:11:24

Right, so reading into those answers a bit perhaps using lsp-mode for emacs is also a recommended pathway. Especially since the point of this work is to enable a smoothr \flo

chrisn17:11:32

sorry, baby typing

chrisn17:11:47

flow for calva users and tmd.

chrisn17:11:19

Then, is there a different setup you use if you are going to be configuring kondo hooks and such? Like I guess just running kondo from the command line?

borkdude17:11:44

@chris441 with clojure-lsp there is no need to run clj-kondo from the command line

chrisn17:11:06

Including when debugging config macro definitions?

borkdude17:11:24

for debugging, I would use the command line and println

borkdude17:11:47

but for seeing feedback in the editor from your hooks using clojure-lsp should be enough

chrisn17:11:36

@dpassen1 - I currently intermittently use flycheck-joker. But I want to integrate correct clj-kondo hooks into our stack which is kind of extensive so switching that portion of my system is the just not a big deal work-wise as compared to the actual work of going through each library and updating it so the various macros used to define the interfaces are correctly represented in clj-kondo.

chrisn17:11:02

What is the relationship between emacs lsp-mode and clojure-lsp?

chrisn17:11:21

Well, and clj-kondo.lsp?

borkdude17:11:31

lsp-mode is the emacs lsp client

borkdude17:11:39

clojure-lsp is the clojure lsp server

borkdude17:11:54

and clj-kondo.lsp is an lsp server which only provides clj-kondo and nothing else

borkdude17:11:11

if you use clojure-lsp, you don't need to install clj-kondo or use clj-kondo.lsp

chrisn17:11:35

Perfect, this all makes sense. Thanks everyone (bork, eric, derek) for the help.

👍 1
ericdallo22:11:32

Is it possible to return a valid :keywords analysis for this code 🧵 ?

ericdallo22:11:52

(ns test-ns
  (:require
   [xtdb.api :as xt]))

::xt/

ericdallo22:11:41

kondo return the analysis for all other things like namespaces and requires, but I'd like a keyword analysis element for ::xt/ , even if is not correct, I'd like to know easily the namespace from that alias

ericdallo22:11:11

this is already possible for ::xt/anything , but not when the code is invalid

ericdallo22:11:54

this is useful to show to users completion items when they just ask for ::xt/ , to show all available :reg keywords on that namespace. Related issue: https://github.com/clojure-lsp/clojure-lsp/issues/649

borkdude22:11:31

Feel free to post an issue

👍 1