Fork me on GitHub
#clj-kondo
<
2024-03-10
>
cjohansen16:03:00

Can I put custom configuration for my library in src/clj-kondo.exports ? E.g. src/clj-kondo.exports/no.cjohansen/portfolio/config.edn

cjohansen16:03:17

“Yes”, it seems. It worked after a REPL restart.

cjohansen16:03:59

Or maybe not :thinking_face:

cjohansen16:03:39

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.

borkdude17:03:39

@U9MKYDN4Q add this to your .clj-kondo/config.edn:

:config-paths ["../src/clj-kondo.exports/no.cjohansen"]

cjohansen18:03:57

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:

borkdude18:03:51

can you make a repository which I can clone? then I'll have a look tomorrow

cjohansen18:03:17

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

borkdude10:03:55

@U9MKYDN4Q can you formulate your latest problem in terms of invoking clj-kondo from the command line in your main branch?

borkdude10:03:18

e.g. when I invoke:

$ clj-kondo --lint src
I see many lint warnings, but which ones are unexpected?

cjohansen12:03:37

@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.

cjohansen08:03:22

Did you have a chance to look at this @U04V15CAJ?

borkdude08:03:42

hopefully today, I'm dealing with a cold...

cjohansen08:03:13

No worries! I know you have a lot 😊

borkdude08:03:25

It's on my todo list :)

cjohansen08:03:42

Then I will stop pestering you 😅

borkdude11:03:11

Alright, I found the issues

borkdude11:03:49

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 so

borkdude11:03:09

Next, in the root config, .clj-kondo/config.edn:

{:config-paths ["../src/clj-kondo.exports/no.cjohansen/portfolio"]}

borkdude11:03:17

This will make your own project use its exported configuration

borkdude11:03:17

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.md

borkdude11:03:44

After fixing those, I get:

$ clj-kondo --lint sample/src/portfolio/components/box.cljs
linting took 46ms, errors: 0, warnings: 0

cjohansen11:03:24

Ah, wonderful 🙏

cjohansen11:03:01

Thanks a lot! Pretty embarrassing it was a typo 🙈 good to know about the hook API 👍

borkdude11:03:35

Thanks for your patience :)

cjohansen11:03:26

Portfolio will shortly ship good clj-kondo config then, that's very cool 😄

🙏 2
cjohansen11:03:55

Awesome, it now works both on the command line and from my REPL 👌

🎉 1