taoensso / encore

Core utils library for Clojure/Script
https://www.taoensso.com/encore
Eclipse Public License 1.0
272 stars 53 forks source link

Add clj-kondo hook for `defonce` #77

Closed marksto closed 3 months ago

marksto commented 3 months ago

Hi Peter!

Adding yet another hook for clj-kondo here.

Before

Having, for instance:

(encore/defonce v-thread-executor
  "..."
  {:private true
   :tag     'java.util.concurrent.ExecutorService}
  (knit/executor :virtual {:thread-factory v-thread-factory}))

produces the following clj-kondo --lint result:

error: Unresolved symbol: v-thread-executor

Which is not cool, right?

After

A new hook translates the defonce example above into:

(clojure.core/defonce v-thread-executor (knit/executor :virtual {:thread-factory v-thread-factory}))

with all the metadata

{:private true, :tag (quote java.util.concurrent.ExecutorService), :doc "..."}

being appropriately set to the v-thread-executor token node.

This eliminates the aforementioned error.

Cheers, Mark

ptaoussanis commented 3 months ago

@marksto Thank you Mark! Merged manually, will be included in the next Encore release 👍