Fork me on GitHub
#clj-kondo
<
2024-02-12
>
fmnoise13:02:05

I have a macro which wraps a multimethod and is used like this

(defsearch :customer
  [company id]
  (let [customer (->> company
                      :company/customers
                      (remove :entity/deleted)
                      (find-first (fn [{:company/keys [reference] :as company}]
                                    (= id (:company/id (or reference company))))))]
    (or customer (err/not-found (str "Customer #" id " doesn't exist")))))
previously it was configured to lint as defn but after last update it shows error how can I define linter rule for it?

borkdude13:02:08

please use a thread to discuss your question further

fmnoise13:02:57

I could probably rework macro to accept symbol

borkdude13:02:59

I think the easiest would be write a hook for this which transforms it to (defn customer [...])

borkdude13:02:02

at least, if your macro creates a var customer

fmnoise18:02:28

getting another error

error: Static fields should be referenced without parens unless they are intended as function calls
for
(def ^:private ^Locale locale
  (Locale/US))

Noah Bogart18:02:58

It should be referenced as (def locale Locale/US)

fmnoise18:02:35

an old code, curious why it was in parens

Noah Bogart18:02:17

yeah, this is part of the changes coming to Clojure in version 1.12. the alpha 6 announcement talks at length about it: https://clojure.org/news/2024/02/08/1-12-alpha6

Noah Bogart18:02:27

> Note: Static fields are values and should be referenced without parens unless they are intended as function calls, e.g (System/out) should be System/out. Future Clojure releases will treat the field’s value as something invokable and invoke it.

fmnoise18:02:08

hmm, interesting

Noah Bogart18:02:46

it was a bug/quirk of the compiler previously that allowed this to work, but it wasn't intentional and now they're changing it to have a specific meaning going forward

fmnoise18:02:09

that's good news then 😅

👍 1
seancorfield18:02:25

Note: (SomeClass/staticField) will still work in 1.12 but you shouldn't rely on it working in 1.13 or later. I'm just going through some code cleanup at work and we had several of these that clj-kondo has helpfully called out for us to fix!

clj-kondo 1