This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-12-21
Channels
- # adventofcode (8)
- # announcements (20)
- # babashka (43)
- # beginners (8)
- # biff (12)
- # calva (2)
- # cider (5)
- # clerk (6)
- # clj-commons (12)
- # clj-kondo (16)
- # clojure (20)
- # clojure-denver (1)
- # clojure-europe (14)
- # clojure-nl (1)
- # clojure-norway (105)
- # clojure-uk (2)
- # clojuredesign-podcast (5)
- # clojurescript (29)
- # datomic (2)
- # hyperfiddle (13)
- # jackdaw (1)
- # jobs (4)
- # jobs-discuss (4)
- # lsp (2)
- # malli (12)
- # pathom (2)
- # pedestal (1)
- # re-frame (22)
- # shadow-cljs (37)
- # squint (28)
- # xtdb (28)
- # yamlscript (4)
I’d like to propose this inline way of declaring hooks for macros:
(defmacro my-macro
{:clj-kondo/hook 'my-hook-namespace/my-hook-name}
[...]
...)
This way it is immediately visible how the macro is linted and moreover, cmd-click on the hook name (at least in calva) brings you immediately to the hook definition. Thoughts?We can detect whether it is analyze-call
or macroexpand
based on whether it is defined as a macro or as a function, but we could also add it to the inline tag to be explicit. :clj-kondo/macroexpand-hook 'my-hook-name
as one option.
I don't know if this helps since you need to define those hooks in external files anyway. I don't like to introduce any ambiguity between analyze-call or macroexpand, macros can be handled with analyze-call as well
What do you mean by external files? They’re in resources
which are also part of the source code.
the idea of inline configs originated from someone who didn't like to write external files like .clj-kondo/config.edn
but when you write hooks you need to add files in .clj-kondo/..../foo.clj_kondo
anyway
Is assert
expected to work in clj-kondo hooks? I have some and they crash with error: No matching ctor found for class java.lang.AssertionError
My code is (assert (vector? node))
in the analyze-call hook.
I like to use namespaced keywords for custom hook errors: :splint/mismatched-diagnosis, etc
We have roughly 15 custom linter keywords in my job’s codebase
> maybe it’s better to use api/reg-finding!
than assert though
is there a good way to obtain row
and col
when it is used in a macroexpand
hook?
I tried it outside of a syntax quote like this:
(defmacro my-hook [source & body]
(when-not (string? source) (api/reg-finding! (merge
(select-keys (meta source) [:row :col :end-row :end-col])
{:message "source must be string"
:type :type-mismatch
:level :error})
`(let [xyz# ~source] ~@body))
but the error I’m seeing has no line number my_file.clj::: error: source must be string
> is there a good way to obtain row
and col
when it is used in a macroexpand
hook?
the row/col metadata should be available as metadata, at least on objects that can carry metadata
you could pass the metadata of the &form
argument, which is the whole surrounding form
So there is no way to recover location of a number?