Fork me on GitHub
#clj-kondo
<
2022-01-26
>
borkdude10:01:23

Impressive work by @pfeodrippe Map keyword inference. Still reviewing PR.

šŸ‘ 6
clj-kondo 4
fadrian21:01:12

I have one macro defined and used many times in one file that is throwing large numbers of "Unresolved symbol" warnings from clj-kondo. According to the documentation, one can configure clj-kondo with namespace local config usingĀ `:clj-kondo/config`Ā metadata in the namespace form. Is there an example of how to do this anywhere on the web? I've searched and can't seem to figure out where/how to put this metadata so it would effect the throwing of these warnings.

fadrian21:01:12

Thank you.

borkdude21:01:44

Sure thing,. Let me know if you have any further questions. There's probably an even better solution for your macro, so if you give me some details, perhaps I can help you with that.

fadrian22:01:10

The macro gets passed a set of binding vars that get used in a let in the body of the macro. Each variable in the binding form generates one of the unresolved-symbol messages. In case it helps, here is the macro:

(defmacro expand [tag pnames err-check-fn err-check-msg fmt & fmt-args]
  `{~(keyword tag) {:exp-fn 
                    (fn [~'ss ~'rw]
                      (let [~pnames (:params ~'rw)]
                       (if (not (~err-check-fn ~'rw))
                         [(error (~err-check-msg ~'rw))]
                          ((partial pp/cl-format nil ~fmt) ~@fmt-args))))}})

borkdude22:01:42

do you mean ss and rw?

borkdude22:01:01

I think you could pretty much paste this macro in a file called .clj-kondo/macros.clj and then add this to your configuration in .clj-kondo/config.edn

{:hooks {:macroexpand {foo.bar/expand macros/expand}}}
You will have to fully qualify pp/cl-format to clojure.pprint/cl-format

fadrian22:01:48

No - it's complaining on the variables that get passed into pnames. Here's an example use of the macro:

(expand
             "Eligibility Gate"
             [coveragePeriod maxGaps maxGapDays type class]
             #(= 5 (count (:params %)))
             #(pp/cl-format nil "Wrong number of parameters in definition of ~a." (stringify (:name %)))
             "define ~a: ~a(~a, ~a, ~a, ~a, ~a)"
             (stringify (:name rw)) (stringify (:fn rw)) coveragePeriod maxGaps maxGapDays (unstring-null (s/lower-case type) "String") (unstring-null (s/lower-case class) "String"))
Its warning about the symbols coveragePeriod, maxGaps, maxGapDays, type, and class.

fadrian22:01:33

I'm also using deps.edn, if that makes any difference in the configuration.

borkdude22:01:48

ok, try the macro suggestion or else you can use the config for unresolved-symbol. the docs are here: https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md#unrecognized-macros

fadrian22:01:00

Thanks again.