Fork me on GitHub
#clj-kondo
<
2021-07-29
>
nathanmarz01:07:13

trying to use :analyze-call hooks to implement some custom linting, but am unable to exclude callsites using the #_{:clj-kondo/ignore [:some-linter]} form

nathanmarz01:07:50

e.g. I'm trying to error on calls to satisfies? with this code:

(defn satisfies-hook
  [{:keys [node] :as input}]
  (let [m (meta node)]
    (api/reg-finding! {:message "use of satisfies? is not allowed!"
                       :type :rpl-satisfies?
                       :row (:row m)
                       :col (:col m)
                       })
    node))

nathanmarz01:07:18

but this code still causes linting to fail:

(defn platform-executable?
  [o]
  #_{:clj-kondo/ignore [:rpl-satisfies?]}
  (satisfies? PlatformExecutable o))

nathanmarz01:07:31

any suggestions on how to do this?

borkdude07:07:53

@nathanmarz You need to add :rpl-satisfies? into your linter config as well, {:linters {:rpl-satisfies? {:level :error}}}, have you done this?

borkdude07:07:33

you also need to include :end-row and :end-col, else the ignore annotation doesn't know what the span is where the ignore is valid

borkdude13:07:53

@nathanmarz let me know if that fixes it for you

borkdude13:07:24

you could perhaps just assoc onto the metadata and pass that to reg-finding!

borkdude14:07:48

oh, about the return value: you don't have to return anything, if you're not transforming. just return nil will do

nathanmarz14:07:33

@borkdude that fixed it

🎉 5
nathanmarz14:07:12

really cool tool, excited to make use of it

2
borkdude14:07:39

that's always nice to hear :)

nathanmarz14:07:15

are there any known issues with running kondo via lein?

nathanmarz14:07:31

running via CLI works great, but the lein runner is unreliable for me

nathanmarz14:07:44

it sometimes has errors like <path>:11:1: error: Attempting to call unbound fn: #'hooks.core/custom-hook

nathanmarz14:07:23

these are the commands I'm using:

nathanmarz14:07:32

lein with-profile kondo clj-kondo --lint 'distributed/src/clj:core/src/clj:distributed/test/clj:core/test/clj' --parallel --config-dir .clj-kondo-jenkins --fail-level error

clj-kondo --lint 'distributed/src/clj:core/src/clj:distributed/test/clj:core/test/clj' --parallel --config-dir .clj-kondo-jenkins --fail-level error

borkdude14:07:23

and what is in your lein profile?

nathanmarz14:07:47

profile is :kondo {:dependencies [[clj-kondo "2021.07.28"]]}

borkdude14:07:05

is the hooks.core code inside your .clj-kondo-jenkins folder in hook/core.clj ?

nathanmarz14:07:11

and alias "clj-kondo" ["run" "-m" "clj-kondo.main"]

nathanmarz14:07:15

the hook are in .clj-kondo-jenkins/hooks/core.clj

borkdude14:07:52

and you are sure there is a var there named custom-hook?

borkdude14:07:11

(should be, because with the native CLI it works)

nathanmarz14:07:19

also, the errors with lein are random

nathanmarz14:07:27

sometimes it has those errors, sometimes it doesn't

nathanmarz14:07:53

sometimes it says this: WARNING: error while trying to read hook for...

borkdude14:07:11

can you try without --parallel?

borkdude14:07:23

to investigate if this is some kind of concurrency bug

borkdude14:07:03

> WARNING: error while trying to read hook for... can you post the entire message?

nathanmarz14:07:43

it appears to be reliable without --parallel , no errors 6x in a row

nathanmarz14:07:12

already cleared the CLI, let me try to recreate that error

borkdude14:07:02

hmm, interesting.

borkdude14:07:24

yeah, I think I know what's going on, the require inside of the interpreter isn't thread safe :)

borkdude14:07:52

could you please post an issue about this?

borkdude14:07:07

preferably with a repro, but I think I can reproduce it myself

nathanmarz14:07:33

WARNING: error while trying to read hook for rpl.helpers/returning: Could not resolve symbol: hooks.core/returning-fn

borkdude14:07:48

satisfies? is a relatively common function, if you lint multiple dirs at the same time, the concurrent require might cause trouble somewhere

borkdude14:07:59

I should use a locking or so around the loading of the hook code

borkdude14:07:49

@nathanmarz you know what, let me push a quick fix and you can use that deployed artifact in your CI

borkdude14:07:54

just a minute

borkdude15:07:05

@nathanmarz try [clj-kondo "2021.07.29-20210729.150232-2"]

nathanmarz15:07:19

@borkdude lein with --parallel looks to be reliable now

borkdude15:07:42

I'll add some tests later

borkdude15:07:11

curious that this didn't manifest in the binary.

richiardiandrea15:07:33

Hi all, I have the following specter path

(def POST-ORDER-VALS
  (sp/recursive-path []
                     p
                     (sp/cond-path map?
                                   (sp/continue-then-stay [sp/MAP-VALS p])
                                   sequential?
                                   (sp/continue-then-stay [sp/ALL p])
                                   set?
                                   (sp/continue-then-stay [sp/ALL p])
                                   sp/STAY)))
And clj-kondo rightly says that p is an "unresolved symbol" p can change, it really depends on who implements the path...is there a way to tell :exclude to ignore recursive-path when linting? Here is what I have now in my config - but it does now work...
{:linters
 {:unresolved-symbol
  {:exclude [thrown-with-data? recursive-path]}}}

borkdude15:07:55

@richiardiandrea you can do {:exclude [(com.rpl.specter/recursive-path)]} to ignore unresolved symbols inside of a call to that function

richiardiandrea15:07:51

oh ok great, I actually tried (recursive-path) but I guess I needed the fully qualified symbol there - let me try

borkdude15:07:19

yes, fully qualified

❤️ 3
richiardiandrea15:07:49

works like a charm

borkdude15:07:19

and (com.rpl.specter/recursive-path [p]) to ignore only p

borkdude15:07:08

it's a co-incidence that @nathanmarz was just here and just after that someone asks a question about specter :)

borkdude15:07:35

perhaps specter can provide better support by providing some hooks or macroexpansions as part of the library (if that makes sense for the above case, not sure)

richiardiandrea15:07:42

yeah lol I have just seen it up there 😉

richiardiandrea15:07:56

Thanks both to you and Nathan for these great tools