I'm encountering a bit of a problem with a hook that I'm trying to develop for a configuration library that we use. We have a macro that converts a property definition that looks something like this:
(cc/defprop-optint listen-port 0 references
"The port that apps listens to."
[props config-valid configs]
"apps.app.listen-port" 60000)
into the definition of a function that takes no arguments and returns the associated configuration setting from a set of properties. For my first attempt at the hook, I'm simply trying to translate this to something like (defn listen-port "The port that apps listens to." [] "apps.app.listen-port") so that the symbols defined by these macros won't be treated as undefined. I thought I could convert it to something more robust after I get it working. The hook itself looks like this:
(defn- rewrite
[node]
(let [[sym desc _bindings prop-name] (rest (:children node))]
(with-meta
(api/list-node
(list* (api/token-node 'defn)
sym
desc
(api/vector-node [])
(:lines prop-name)))
(meta node))))
(defn defprop [{:keys [node]}]
(println (str node))
(let [new-node (rewrite node)]
(println (str new-node))
{:node new-node}))
The problem that I'm running into is that this seems to work fine for the first property definition in the namespace where the configuration settings are defined, but it doesn't recognize subsequent property definitions. So in the example above, all references to listen-port are recognized, but references to any properties defined after it are treated as undefined variables.
If you'd like to see the actual hook definition, you can find it here: https://github.com/slr71/clojure-commons/tree/main/resources/clj-kondo.exports/org.cyverse/clojure-commons
I'm sure I'm missing something obvious here, but I'm not really sure what it is. Does anyone have any suggestions?perhaps a macroexpand hook could help here?
analyze-call should of course also work, when you do it properly
don't have to time to debug this now, but hopefully later today, if someone else hasn't
The :lines bit looks suspect, you should just pass the rewrite-clj node as is
@sarahr if you could make a github repo where I can run this hook by checking out the code, that would save me a lot of time. If you would do that, then I'll look into it and probably will find the issue soon
Will do. My day has been fairly busy so far, but I'll create a repo before I'm done for the day.
Cool, I’ll look at this first thing tomorrow then
Sounds good, thanks!
Ignore my previous replies. I hadn't really reproduced the problem when I thought I had.
I ran out of time today. Sorry about that; I had a ton of meetings, and it's taking me longer to create a minimal reproduction of the error than I expected.
I'll work on it later this week and let you know when it's ready.
Finding the time to work on this has been a bit more challenging than I would have expected. I think I'm going to have to table this for now and revisit it later. Sorry for the false alarm.