Fork me on GitHub
#clj-kondo
<
2023-12-20
>
h0bbit16:12:05

Hi All, here is something small that is driving me crazy. I think I’m doing everything right with :lint-as , but clj-kondo is not linting the code for me. I’ll add details in the thread.

h0bbit16:12:55

This is what my logging namespace is:

(ns logger.interface
  (:require [io.pedestal.log :as log]
            [jsonista.core :as json]))

(defmacro trace [& keyvals]
  `(log/trace ::log/formatter json/write-value-as-string ~@keyvals))

(defmacro debug [& keyvals]
  `(log/debug ::log/formatter json/write-value-as-string ~@keyvals))

(defmacro info [& keyvals]
  `(log/info ::log/formatter json/write-value-as-string ~@keyvals))

(defmacro warn [& keyvals]
  `(log/warn ::log/formatter json/write-value-as-string ~@keyvals))

(defmacro error [& keyvals]
  `(log/error ::log/formatter json/write-value-as-string ~@keyvals))

h0bbit16:12:23

It’s a wrapper over io.pedestal.log to ensure that I can pass a ::formatter option. Now, when I use this code elsewhere, I want to ensure that I’m passing an even number of items to the call (so that & keyvals is correct). For this, I wrote the following in my config.edn file:

h0bbit16:12:54

{:lint-as {logger.interface/trace clojure.core/hash-map
           logger.interface/debug clojure.core/hash-map
           logger.interface/info  clojure.core/hash-map
           logger.interface/warn  clojure.core/hash-map
           logger.interface/error clojure.core/hash-map}}

h0bbit16:12:05

This does not work, the linter does not give me errors when the number of forms are not even. It gives me the right error if I replace the logging macro call with hash-map , so I know that clj-kondo itself is working.

h0bbit16:12:57

My questions: 1. What am I doing wrong, if it’s something obvious? 2. What are the steps to debug this? How do I see what clj-kondo is doing?

hiredman20:12:48

My guess would be hash-map is a function, and kondo has specific support for it, where lint-as works by replacing analysis of an unknown macro with a known macro, but not sure

h0bbit05:12:54

I removed the lint-as and instead wrote a hook that I could use in analyze-call. This took far more time than I wanted to spend on the task, but it’s working now the way I wanted it to. Here is the change I made: https://github.com/pedestal/pedestal/pull/781/commits/fdbd52229ce9907bf8048f99a5c2bdd8d09e06c3

Alexander Kouznetsov23:12:27

Looks like both .m2/repository/org/babashka/sci/0.8.41/sci-0.8.41.jar and .m2/repository/clj-kondo/clj-kondo/2023.12.15/clj-kondo-2023.12.15.jar contain clojure file named scratch.clj that probably shouldn’t be part of the jar file. (Our project flags this as a conflict on the classpath). Should I file an issue about this?