Fork me on GitHub
#clj-kondo
<
2021-02-09
>
Adam Helins19:02:46

I have a special macro which is essentially about executing given forms as Clojure code no matter the target platform. (In CLJS, they are evaled during the compilation stage) Is there a way to write a hook for that very special use case? Forcing linting as Clojure? The problem is that in a CLJC file, Clj-kondo will complain if those forms refer to something that is Clojure specific (eg. a call to alter-var-root) because as such, it doesn't know that they will never execute as CLJS.

borkdude11:02:06

@UCFG3SDFV Is it an option to put this code in a :clj reader conditional?

borkdude11:02:22

If not, please make a small repro which clarifies the problem

Adam Helins12:02:40

I tried to make my case here but feel free to close it if you find it to be too narrow of a use case: https://github.com/clj-kondo/clj-kondo/issues/1165 Thanks!

borkdude12:02:51

Why don't you suppress unresolved symbol linting for this macro?

borkdude12:02:38

{:linters
  {:unresolved-symbol
    {:exclude [(your-ns/eval-as-clojure)]}}}

borkdude12:02:18

I have another feature in the works to only lint .cljc as one language, e.g. only consider the :clj branches and unbranched code as only clj and ignore the rest.

borkdude12:02:25

Would that also fit your use case?

borkdude12:02:30

This would disable cljs linting for .cljc

Adam Helins13:02:54

The thing is, forms passed to such a macro are Clojure forms which should be linted as usual. In that example, Clj-kondo will end up complaining about format because it thinks it is going to be called from CLJS as well. It is essentially about forcing to lint as Clojure in a context where a reader conditional cannot be used. Unfortunately, forcing linting to Clojure in a whole CLJC file would be a heavy price to pay since you would become blind regarding the CLJS side.

borkdude13:02:11

so the macro is always executed by clojure on the JVM side right? so expanding the macro into #?(:clj the-forms) in a hook would be the correct interpretation?

borkdude13:02:40

this is currently not possible I think but could be an appropriate solution

Adam Helins13:02:11

I guess you didn't have many people requesting that. Outside of tooling, I admit I am not sure how useful that would be in "day to day" code

borkdude13:02:50

yes, but adding the possibility of creating reader conditionals to hook code might be generally useful

👍 3
borkdude13:02:58

although still a bit niche maybe

Adam Helins13:02:31

Unfortunately I can't help you much since I am not very aware of the inner workings. I've started writing hooks and taking a deeper look only recently

borkdude13:02:06

I'll leave the issue open and will think about it for a while

metal 3