clj-kondo

https://github.com/clj-kondo/clj-kondo
neotyk 2021-02-10T11:31:35.115100Z

@borkdude https://github.com/clj-kondo/clj-kondo/issues/1164 is this something that would be useful?

borkdude 2021-02-10T11:34:06.115300Z

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

borkdude 2021-02-10T11:35:22.115500Z

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

borkdude 2021-02-10T11:44:28.117600Z

Replied in the issue

neotyk 2021-02-10T11:56:09.117800Z

me also 🙂

borkdude 2021-02-10T11:58:25.118Z

I'll let the issue be open to gather feedback from the community first.

borkdude 2021-02-10T12:15:24.118200Z

If this doesn't end up in clj-kondo eventually you can write a custom hook to handle cond and condp yourself

neotyk 2021-02-10T12:22:14.118400Z

how would I go about writing custom hook, we’ve being bitten in our rear end few times over last days because of condp lacking default case

borkdude 2021-02-10T12:24:49.118600Z

I will write a small one

neotyk 2021-02-10T12:44:34.119400Z

thank you Michiel

borkdude 2021-02-10T12:46:02.119600Z

np. you might have to do some more work to take into account :>>, e.g. filter it out, but if you're not using that this should already be sufficient

Helins 2021-02-10T12:53:40.120100Z

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!

borkdude 2021-02-10T12:56:51.120400Z

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

borkdude 2021-02-10T12:57:38.120600Z

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

borkdude 2021-02-10T12:58:18.120800Z

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.

borkdude 2021-02-10T12:58:25.121Z

Would that also fit your use case?

borkdude 2021-02-10T12:58:30.121200Z

This would disable cljs linting for .cljc

Helins 2021-02-10T13:10:54.121400Z

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.

borkdude 2021-02-10T13:16:11.121600Z

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?

borkdude 2021-02-10T13:16:40.121800Z

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

Helins 2021-02-10T13:20:56.122Z

Exactly so

Helins 2021-02-10T13:24:11.122200Z

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

borkdude 2021-02-10T13:26:50.122400Z

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

1👍
borkdude 2021-02-10T13:26:58.122600Z

although still a bit niche maybe

Helins 2021-02-10T13:30:31.122900Z

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

borkdude 2021-02-10T13:32:06.123100Z

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

1🤘
serioga 2021-02-10T15:02:14.125300Z

Idea for linting: warn about useless -> in the code like (-> 'x). Sometimes during refactoring I remove all forms in threading macro and miss remaining macro itself.

2021-02-10T15:11:36.125400Z

Maybe also (-> x y)

borkdude 2021-02-10T15:12:44.125600Z

feel free to post an issue

serioga 2021-02-10T15:26:12.125800Z

“Maybe also (-> x y)” NO!

2021-02-10T15:30:30.126Z

Why? That is like (y x) with extra chars.

2021-02-10T15:31:52.126200Z

I'm not talking about when y is a form, that should be fine, but for a symbol or keyword.

serioga 2021-02-10T15:40:09.126800Z

Sometime I would like to emphasize that x is more important in the context than y. Like (f a (-> b xform)). This allows me to place accents. https://clojurians.slack.com/archives/CHY97NXE2/p1612971030126000?thread_ts=1612969334.125300&cid=CHY97NXE2

2021-02-10T15:59:52.127100Z

Interesting, never thought about using it that way. Thanks.