This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-09-22
Channels
- # announcements (11)
- # architecture (7)
- # babashka (26)
- # beginners (314)
- # calva (20)
- # chlorine-clover (1)
- # cider (5)
- # circleci (27)
- # clara (6)
- # clj-kondo (41)
- # cljsrn (6)
- # clojure (120)
- # clojure-berlin (2)
- # clojure-czech (2)
- # clojure-dev (4)
- # clojure-europe (45)
- # clojure-france (4)
- # clojure-germany (1)
- # clojure-nl (5)
- # clojure-uk (20)
- # clojuredesign-podcast (8)
- # clojurescript (6)
- # conjure (42)
- # datascript (5)
- # datomic (21)
- # deps-new (28)
- # duct (1)
- # fulcro (36)
- # graalvm (10)
- # graphql (24)
- # jackdaw (19)
- # jobs (2)
- # jobs-discuss (46)
- # kaocha (6)
- # malli (26)
- # off-topic (21)
- # parinfer (5)
- # re-frame (10)
- # sci (19)
- # shadow-cljs (95)
- # tools-deps (24)
- # vim (3)
Is it possible to disable the arity-check for keywords? We have an embedded language that uses keywords in function position, with an arbitrary number of arguments.
No urgency. Thanks for the config pointers. I see how to disable the check for a specific function/macro, but not for keywords in general. The set of keywords we use like this is open, although there is a limited set that probably covers most usage. Maybe that is good enough.
Um, looks like it is not possible to define a hook on an unqualified symbol pulled in via a :refer :all
This is the code:
(ns hooks.kw-macro
(:require [clj-kondo.hooks-api :as api]))
(defn rewrite [node]
(let [sexpr (api/sexpr node)]
(if (and (seq? sexpr)
(keyword? (first sexpr)))
(let [children (rest (:children node))
children (mapv rewrite children)]
(with-meta (api/vector-node children)
(meta node)))
(with-meta
(update node :children #(mapv rewrite %))
(meta node)))))
(defn kw-macro [{:keys [:node]}]
(let [new-node (api/vector-node (mapv rewrite (rest (:children node))))]
;; for debugging:
;;(prn :new-node new-node)
{:node new-node}))
I basically rewrite (my/kw-macro (:foo 1 2 3) (:bar 1 2 3))
to [[:foo 1 2 3] [:bar 1 2 3]]
the macro is required with a :refer :all
and is actually defined in a different namespace via an import-vars
like mechanism.
it does have support for import-vars (the widely used one). so if you use the same syntax as that one and use lint-as AND lint all of your namespaces, it might work
Is there any existing macro to inspect how clj-kondo is currently parsing an expression? eg, something I can insert around a form that prints the rewrite map
How do you develop hooks? clj-kondo seems to just silently ignore the hook if it fails to load.
e.g. with this config:
{:hooks {:analyze-call {my/kw-macro hooks.kw-macro/kw-macro2}}}
borkdude@MBP2019 /tmp/proj $ clj-kondo --lint example.clj
WARNING: error while trying to read hook for my/kw-macro: Could not resolve symbol: hooks.kw-macro/kw-macro2 [at line 2, column 1]
example.clj:4:14: error: keyword :foo is called with 3 args but expects 1 or 2
example.clj:5:14: error: clojure.core/inc is called with 3 args but expects 1
example.clj:6:15: error: keyword :foo is called with 3 args but expects 1 or 2
example.clj:6:28: error: clojure.core/inc is called with 3 args but expects 1
linting took 59ms, errors: 4, warnings: 0
^ @hugodand correcting it:
$ clj-kondo --lint example.clj
example.clj:5:14: error: clojure.core/inc is called with 3 args but expects 1
example.clj:6:28: error: clojure.core/inc is called with 3 args but expects 1
linting took 33ms, errors: 2, warnings: 0
I'm putting a random x in my hook code:
$ clj-kondo --lint example.clj
WARNING: error while trying to read hook for my/kw-macro: Could not resolve symbol: x [at /private/tmp/proj/.clj-kondo/hooks/kw_macro.clj, line 5, column 3]
yeah, you might have hit a different case. repro welcome, maybe something could be improved
meanwhile you might want to look at https://github.com/borkdude/clj-kondo/blob/master/doc/config.md
I think this is what you're after: https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#exclude-arity-linting-inside-a-specific-macro-call