This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-06-22
Channels
- # ai (1)
- # announcements (4)
- # babashka (23)
- # beginners (27)
- # biff (17)
- # calva (5)
- # clerk (6)
- # clj-commons (27)
- # clj-kondo (35)
- # clojars (12)
- # clojure (27)
- # clojure-denver (3)
- # clojure-europe (71)
- # clojure-norway (7)
- # clojure-spec (5)
- # clojure-uk (2)
- # clojurescript (45)
- # data-science (9)
- # datomic (4)
- # dev-tooling (2)
- # devcards (1)
- # hoplon (2)
- # hyperfiddle (36)
- # introduce-yourself (3)
- # malli (11)
- # missionary (2)
- # off-topic (63)
- # polylith (5)
- # rdf (2)
- # reagent (12)
- # schema (1)
- # shadow-cljs (11)
- # sql (6)
- # tools-deps (23)
- # xtdb (6)
Hello happy linters! I am adding hooks for some macros I wrote, and I am having issues adding a hook for this particular one: https://github.com/exoscale/ablauf/blob/master/src/ablauf/job/ast.clj#LL103C3-L111C46 I added the following hook:
(ns exoscale.ablauf-hooks)
(defn try-extract
[sym forms]
(if (and (list? (last forms)) (= sym (first (last forms))))
[(vec (drop-last forms)) (drop 1 (last forms))]
[forms]))
(defmacro try!! [& forms]
(let [[formsf finallyf] (try-extract 'finally!! forms)
[formsf rescuef] (try-extract 'rescue!! formsf)]
{:ast/type :ast/try
:ast/nodes [{:ast/type :ast/seq
:ast/nodes (vec formsf)}
{:ast/type :ast/seq
:ast/nodes (vec rescuef)}
{:ast/type :ast/seq
:ast/nodes (vec finallyf)}]}))
The issue I am reaching is that while both finally!!
and rescue!!
are understood as valid symbols in the context of the macro, any qualified symbol used loses its qualification, leading to unused namespace errors. For instance assume the following use of the macro:
(ns my-ns (:require [ablauf.job.ast :as ast] [my-action :as action]))
(ast/try!!
(ast/action!! ::action/something {:payload …})
(finally!! (ast/action!! ::action/cleanup {})))
The above would yield the following warning: warning: namespace my-action is required but never used
. Is there a way I am missing to ensure qualification is preserved for the keywords used?You could try to preserve the keywords and just emit it in another key of the expansion: :ast/_misc [keywords]
The issue I have is that I don't know ahead of time (in my example, I don't know ahead of time that ::action/something
will get called)
I'm not sure how to solve this right now, since you can't represent ::foo/bar
as a normal keyword and then turn it back into a ::foo/bar
node
but the alternative is to write an analyze-hook hook which gives you full control over these keywords as rewrite-clj nodes. it's a problem in general though so I'll have to think more about it
(still trying) In this particular case I only need the macro to walk the forms to find finally!!
and rescue!!
I could simply declare those as ok to be unknown and avoid the macro hook entirely
Another question, I am following this documentation https://github.com/clj-kondo/clj-kondo/blob/85c4b763e7a1c4563722f771243ae7e2359d17f4/doc/config.md#exporting-and-importing-configuration but I cannot get a dependent library to fetch my config, even if explicitly calling copy-configs. I checked that my JAR contains clj-kondo.exports/exoscale/ablauf/config.edn
Well, clojure-lsp dump
did the trick and fetched the configuration though, so it's all good
you should have gotten it with:
clj-kondo --copy-config --lint $(clojure -Spath) --dependencies
I think it was due to the fact that the dependencies are in aliases, anyway thanks, I now have fully working imports and configs, I'll make sure all my public libraries expose kondo hooks for the macros now 🙂
I have a small macro that I want to be linted as fn. When I put the macro definition in the ns it’s used from, my clj-kondo linter hints works, but when I move the macro to another namespace, it doesn’t seem to pick up on the linting info. Macro
(defmacro dfn
{:clj-kondo/config '{:lint-as {playground/dfn clojure.core/fn}}}
[argslist & body]
`(fn ~argslist
(println "-> " (mapv identity ~argslist))
(let [res# ~@body]
(println "<- " res# "\n")
res#)))
Ok, on it.
Need a few minutes
Well, I’ll be damned… When I put it in a small repo, it works as expected and a .clj-kondo/inline-configs is created… I must have something different configured in the larger context.
Thanks for making me create a smaller example
but when I move the macro to another namespace
it might be that the old inline config is still active or something, cleaning your cache and then re-linting might have helped
Looks like clj-kondo isn’t correctly checking for unused nested classes imports. It highlights the following import as unused even though it is used below and this evaluates without errors in repl:
(:import
(clojure.lang Compiler$CompilerException))
...
(is (thrown? Compiler$CompilerException (eval `(...))))
Nevermind, it just stopped doing so. Probably it was just a delay.