Fork me on GitHub
#clj-kondo
<
2024-03-25
>
3starblaze10:03:56

I recently had an idea. JS libraries usually come with Typescript type annotations. Is there a library for Clojurescript that takes those annotations and give it to clj-kondo so that static analysis can be done on all js libraries that have the annotations. Is there any existing solution for this? If not, how doable would that be? I assume it's just a great deal of reshaping TS annotation data into clj-kondo annotation data but maybe there's something in cljs side that could make this extra challenging?

👀 3
rayat19:03:59

great idea, I imagine there must have been attempts already. I know that clojure-lsp uses a library to power javascript-land intellisense, but I can’t remember the name, or if it’s still in use. I imagine your idea would best be implemented either in that library, or in clj-kondo land. I imagine the trickier part might not necessarily be in the ts type -> cljs side annotation part, but rather in the build or integration side of things. With that js intellisense library I mentioned, it can provide its data presumably because it has access to the installed js lib locally (unsure if that’s how it works, or it just hardcodes common APIs/libs or something). But with ts types? Do we auto install them from @types/* for the user if they’re not provided by the library? Do we require the user install the type defs themselves? I suppose in the type -> kondo conversion side, I’m unsure if clj-kondo can support the arbitrarily nested, structural types that ts does. Tho at least type checking the basics would be dope

3starblaze05:03:16

My idea is to translate TS typings into Malli defn schemas. We can turn those defn schemas into clj-kondo format. clj-kondo does as much as it supports and everything that it can't do can be handled with Malli instrumentation. How to handle type detection? We could let the user handle that and instead warn when typings cannot be found. Let's say that by default this checker always complains when no types can be found. The user could add configuration to override behavior (e.g. mark library's foo symbols to be unknown or even any or just ignore missing types entirely). It would be expected that the developer explicitly handles typeless libraries, so that they don't accidentally miss the lack of types.

3starblaze05:03:48

LSP integration is also a great idea. I would need to check out LSP and typescript's LSP to see how they deal with types.

rayat01:03:26

typescript actually doesn’t exactly use LSP -> the official TS IDE integrations - at least vsc and I believe vim - use tsserver which iirc is a superset of the official LSP server spec (despite all of these coming from the same company). That might not matter, I haven’t looked at its source in years, so you might still get a lot of insight out of it. I’m really hyped by this - please update us as/if you start working on this. I might free up in a few months to also help out 🤞:skin-tone-4:

3starblaze09:03:48

Glad to hear the enthusiasm. I am not sure how likely it would be for me to tackle this project. When I free up, I will focus on godot-clojure. I will have plenty of time after 2 months or so, maybe I could switch between this and godot-clojure.

Ngoc Khuat13:03:34

Anyone able to make kondo ignore a namespace?

(ns my-namespace
  {:clj-kondo/ignore true})

(unresolved-ns/fn 1)
doesn’t work for me

skynet13:03:14

I think it's

(ns #_:clj-kondo/ignore my-namespace
...

borkdude14:03:21

no, what @U023C0QKU4W wrote initially is the correct notation to ignore everything in the current namespace

👍 1
borkdude14:03:33

and it does work here locally. perhaps you are on an old version @U023C0QKU4W?

borkdude14:03:12

$ cat src/ignore.clj
(ns ignore
  {:clj-kondo/ignore true})
$ clj-kondo --lint src/ignore.clj
linting took 6ms, errors: 0, warnings: 0

Ngoc Khuat14:03:01

right I was on an old version, I did do brew upgrade clj-kondo before but apparently it doesn’t update kondo. updated works! Thanks!

👍 1