Fork me on GitHub
#clj-kondo
<
2021-08-31
>
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

borkdude17:08:37

There is an open issue about this: https://github.com/clj-kondo/clj-kondo/issues/996 Feel free to provide feedback or upvote it using a thumbs up

👍 1
borkdude17:08:01

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

borkdude19:08:01

@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

noah@Noahs-MBP ~/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

noah@Noahs-MBP ~/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"]}
noah@Noahs-MBP ~/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+}}}
noah@Noahs-MBP ~/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]
  (reduce
    (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)

borkdude20:08:46

it's similar to the layout in a mvn dir

borkdude20:08:09

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

borkdude21:08:06

I might have overlooked that as wel

borkdude21:08:27

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

Noah Bogart21:08:19

yep! doing that makes it work

borkdude21:08:28

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

👍 1
borkdude19:08:25

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

👍 1
borkdude19:08:49

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

borkdude19:08:57

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

borkdude20:08:29

I would recommend changing it for the next release

👍 1
borkdude20:08:55

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

borkdude20:08:03

perhaps a link to the lib?

borkdude20:08:18

ok yeah that makes sense, thanks

borkdude20:08:08

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

borkdude20:08:25

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

borkdude20:08:42

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

borkdude20:08:47

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
borkdude20:08:11

basically the same as with clojure code and classpaths