This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2024-03-10
Channels
- # aleph (1)
- # beginners (4)
- # biff (7)
- # calva (7)
- # cider (8)
- # clara (17)
- # clerk (19)
- # clj-kondo (30)
- # clojure (12)
- # clojure-austin (1)
- # clojure-europe (12)
- # clojure-losangeles (1)
- # clojure-norway (21)
- # clojurescript (2)
- # datalevin (1)
- # datomic (24)
- # duct (3)
- # fulcro (8)
- # hyperfiddle (8)
- # lambdaisland (4)
- # membrane (6)
- # missionary (7)
- # off-topic (55)
- # overtone (2)
- # reagent (4)
- # reitit (4)
- # releases (6)
- # shadow-cljs (80)
Can I put custom configuration for my library in src/clj-kondo.exports
? E.g. src/clj-kondo.exports/no.cjohansen/portfolio/config.edn
I attempted a Portfolio defscene
config based on what @U0ETXRFEW did for dumdom: https://github.com/cjohansen/portfolio/commit/6a9ad65db6614880721c988e19d07c8b039a2526 I have not had success yet. For instance, this:
(defscene heading [data]
(pr-str (:text data)))
Parses to this:
{:node
{:tag :list,
:format-string "(%s)",
:wrap-length 2,
:seq-fn #function[clj-kondo.impl.rewrite-clj.node.seq/list-node/fn--11837],
:children
({:value defn, :string-value "defn", :clj-kondo.impl/generated true}
{:value heading, :string-value "heading"}
{:lines ["no docs"], :clj-kondo.impl/generated true}
{:tag :vector,
:format-string "[%s]",
:wrap-length 2,
:seq-fn #function[clojure.core/vec],
:children ({:value data, :string-value "data"})}
{:tag :map,
:format-string "{%s}",
:wrap-length 2,
:seq-fn #function[clj-kondo.impl.rewrite-clj.node.seq/map-node/fn--11843],
:children [],
:clj-kondo.impl/generated true}
{:tag :list,
:format-string "(%s)",
:wrap-length 2,
:seq-fn #function[clj-kondo.impl.rewrite-clj.node.seq/list-node/fn--11837],
:children
({:value pr-str, :string-value "pr-str"}
{:tag :list,
:format-string "(%s)",
:wrap-length 2,
:seq-fn
#function[clj-kondo.impl.rewrite-clj.node.seq/list-node/fn--11837],
:children
({:k :text, :namespaced? nil} {:value data, :string-value "data"})})}),
:clj-kondo.impl/generated true}}
But this:
(:findings
(with-in-str
(str
'(require '[portfolio.dumdom :refer [defscene]])
'(defscene heading [data]
(pr-str (:text data))))
(clj-kondo.core/run! {:lint ["-"]})))
Produces this error:
[{:end-row 1,
:type :unresolved-symbol,
:level :error,
:filename "<stdin>",
:col 65,
:end-col 72,
:langs (),
:message "Unresolved symbol: heading",
:row 1}
{:end-row 1,
:type :unresolved-symbol,
:level :error,
:filename "<stdin>",
:col 74,
:end-col 78,
:langs (),
:message "Unresolved symbol: data",
:row 1}]
The second one is expected, the first is not. I may be holding any number of elements wrong here. How can I make sure that clj-kondo.core/run!
even uses my code? Is this done via the config.edn file? I don’t understand whether this is a configuration problem or a coding problem.@U9MKYDN4Q add this to your .clj-kondo/config.edn
:
:config-paths ["../src/clj-kondo.exports/no.cjohansen"]
That seems to have achieved something, because now my code has been copied into .clj-kondo
. But I’m still getting “unresolved symbol heading”, which should be treated as a defn
:thinking_face:
Sure, thanks! It’s on main here: https://github.com/cjohansen/portfolio
https://github.com/cjohansen/portfolio/tree/main/src/clj-kondo.exports/no.cjohansen/portfolio
I tested it by starting a clojure REPL, and evaluating the comment block expressions here: https://github.com/cjohansen/portfolio/blob/main/src/clj-kondo.exports/no.cjohansen/portfolio/portfolio/defscene.clj
@U9MKYDN4Q can you formulate your latest problem in terms of invoking clj-kondo
from the command line in your main branch?
e.g. when I invoke:
$ clj-kondo --lint src
I see many lint warnings, but which ones are unexpected?@U04V15CAJ sure! clj-kondo --lint sample
produces lots of errors. Most of these, including the first one is unexpected:
sample/src/portfolio/components/box.cljs:5:11: error: Unresolved symbol: shadowed-box
I expected the code in src/clj-kondo.exports/no.cjohansen/portfolio/portfolio/defscene.clj
to translate this macro to something akin to a defn
, so shadowed-box
should have been understood as a deffed var.Did you have a chance to look at this @U04V15CAJ?
The first issue: Change the config in the exported config to:
{:linters {:portfolio/component-options {:level :warning}}
:hooks {:analyze-call {portfolio.dumdom/defscene portfolio.defscene/defscene}}}
There was a type there: portfolio.defcomponent/defscene
or soNext, in the root config, .clj-kondo/config.edn
:
{:config-paths ["../src/clj-kondo.exports/no.cjohansen/portfolio"]}
Then in inside of the hook code:
(ns portfolio.defscene
(:require #_[clj-kondo.core :as clj-kondo]
[clj-kondo.hooks-api :as api]))
#_(defn- get-findings [code]
(:findings
(with-in-str
(str
'(require '[portfolio.dumdom :refer [defscene]])
code)
(clj-kondo.core/run! {:lint ["-"]}))))
The namespace clj-kondo.core
isn't available in hook code. The hook code runs inside of an interpreter which only has a limited number of stuff available which is documented in doc/hooks.mdAfter fixing those, I get:
$ clj-kondo --lint sample/src/portfolio/components/box.cljs
linting took 46ms, errors: 0, warnings: 0