Fork me on GitHub
Noah Bogart17:08:03

is it possible to exclude a given symbol’s use?

Noah Bogart17:08:31

something like {:disallowed [clojure.core/cond]}

Noah Bogart17:08:49

and then if that symbol is used, a warning/error is thrown


There is an open issue about this: Feel free to provide feedback or upvote it using a thumbs up

👍 1

You can also leverage the analysis output to look for used vars and do your own thing with it, currently

Joshua Suskalo17:08:24

Interesting concept, but I gotta ask, of all the vars you could disallow, cond?

Noah Bogart17:08:22

well, 1) it’s just an example, but 2) i adapted Racket’s cond and want to use it in my library and want to enforce using it instead of the built-in cuz i am the literal devil

😈 1
Noah Bogart17:08:44

very cool, thank you. i’ve subscribed to that issue, don’t have much to add yet tho

Noah Bogart18:08:24

just wrote my first hook! Very nifty and easy to use.

Noah Bogart19:08:13

To double check, if I want to export a library’s config and hooks, this should be the folder structure? (output from git status)

new file:   .clj-kondo/config.edn
	new file:   .clj-kondo/hooks/cond_plus.clj
	new file:   resources/clj-kondo.exports/cond-plus/cond-plus/config.edn
	new file:   resources/clj-kondo.exports/cond-plus/cond-plus/hooks/cond_plus.clj


@nbtheduke Yes. You can even add resources/clj-kondo.exports/cond-plus/cond-plus to :config-paths into your .clj-kondo/config.edn so you don't have to duplicate your config

🎉 1
Noah Bogart20:08:36

I’m struggling to get this to work

Noah Bogart20:08:19

[email protected] ~/Personal/cond-plus [master ≡ +3 ~2 -0 | +0 ~1 -0]
$ git status
On branch master
Your branch is up to date with 'origin/master'.

Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
	new file:   .clj-kondo/config.edn
	modified:   .gitignore
	new file:   resources/clj-kondo.exports/cond_plus/cond_plus/cond_plus/cond_plus.clj
	new file:   resources/clj-kondo.exports/cond_plus/cond_plus/config.edn
	modified:   test/cond_plus/core_test.clj

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	modified:   test/cond_plus/core_test.clj

[email protected] ~/Personal/cond-plus [master ≡ +3 ~2 -0 | +0 ~1 -0]
$ cat .clj-kondo/config.edn
{:config-paths ["resources/clj-kondo.exports/cond_plus/cond_plus"]}
[email protected] ~/Personal/cond-plus [master ≡ +3 ~2 -0 | +0 ~1 -0]
$ cat resources/clj-kondo.exports/cond_plus/cond_plus/config.edn
{:linters {:cond-plus/empty-else {:level :error}
           :cond-plus/missing-fn {:level :error}
           :cond-plus/non-final-else {:level :error}
           :cond-plus/sequence {:level :error}
           :unresolved-symbol {:exclude [(cond-plus.core/cond+ [=> else])]}}
 :hooks {:analyze-call {cond-plus.core/cond+ cond-plus.cond-plus/cond+}}}
[email protected] ~/Personal/cond-plus [master ≡ +3 ~2 -0 | +0 ~1 -0]
$ clj-kondo --lint .
./test/cond_plus/core_test.clj:126:30: error: Unresolved symbol: =>
./test/cond_plus/core_test.clj:168:27: error: Unresolved symbol: else
linting took 67ms, errors: 2, warnings: 0

Noah Bogart20:08:41

i’ve modified the test file to produce an error, which should be caught by kondo, and instead it’s telling me about something that should be ignored

Noah Bogart20:08:42

$ head resources/clj-kondo.exports/cond_plus/cond_plus/cond_plus/cond_plus.clj
(ns cond-plus.cond-plus
  (:require [clj-kondo.hooks-api :as api]))

(defn analyze-clauses [clauses]
    (fn [found-else? clause]
      ;; non-sequence clause
      (if (not (or (api/list-node? clause)
                   (api/vector-node? clause)))
        (let [{:keys [row col]} (meta clause)]

Noah Bogart20:08:14

(lol at cond_plus/cond_plus/cond_plus/cond_plus.clj)


it's similar to the layout in a mvn dir


I'll take a look in a bit

Noah Bogart21:08:16

did some digging and it seems that the :config-paths is relative from the config.edn file, not from the project root/where clj-kondo is called?

Noah Bogart21:08:56

okay, seems i misunderstood that


I might have overlooked that as wel


so then it would be config-paths ["../resources/etc"]

Noah Bogart21:08:19

yep! doing that makes it work


great! @U0522TWDA this is what I tried to explain yesterday with the fulcro lib

👍 1

@nbtheduke Also note that you have to lowercase your directory names: cond_plus/cond_plus

👍 1

and I would advise to use an org name like noah_the_duke/cond_plus instead


to not conflict with other configs for the same macro

Noah Bogart20:08:34

i suspect this is outside the scope of this channel, but i’ve already published the library with that org, so i’m not sure how I would go about changing it

Noah Bogart20:08:42

i’ll keep that in mind in the future


I would recommend changing it for the next release

👍 1

or is the library's name cond-plus? then it may not be that bad


perhaps a link to the lib?


ok yeah that makes sense, thanks


I didn't mean changing the org for your lib but for the clj-kondo exports


but now I see that's actually what the lib is published like, so all good


as long as conflicts are avoided then it's ok basically


so instead of hooks/cond_plus.clj it would be actually better to choose cond_plus/cond_plus.clj as well, since there may be someone else who has a hooks/cond_plus.clj file in their config and then they will conflict

👍 1

basically the same as with clojure code and classpaths