clj-kondo

https://github.com/clj-kondo/clj-kondo
Niklas 2021-02-19T14:17:22.216400Z

does the :refer linter suppport :exclude? I'm running both clj-kondo and joker, and it seems clj-kondo wants me to :refer :all for clojure.test whereas joker wants me to :refer [deftest]...? I would like to not allow :refer in any other cases.

borkdude 2021-02-19T14:18:38.217400Z

@nicke.claesson Can you lint on the command line with clj-kondo only? This way you will exclude any other linting output from this issue, which is often a confusing factor. And then please ask the question again.

borkdude 2021-02-19T14:19:37.218Z

Clj-kondo does not want you to do :refer :all by default (it discourages this for its own analysis good)

Niklas 2021-02-19T14:20:24.218500Z

for code like this [clojure.test :refer [deftest is testing use-fixtures]] I get test/integration/reconciliation_writer_test.clj:6:27: error: require with :refer

Niklas 2021-02-19T14:20:53.219Z

which is fair, becuase I want to disallow usage of :refer because then you don't see that functions are external

Niklas 2021-02-19T14:21:31.220100Z

however for macros in clojure.test it makes sense to refer them, I think (t/deftest) is unneccessary

borkdude 2021-02-19T14:21:58.220600Z

OK, I see. The config for this linter is here: https://github.com/clj-kondo/clj-kondo/blob/master/doc/linters.md#refer and as of now it doesn't support exclusions. But you can ignore the warning locally using #_:clj-kondo/ignore before the form

borkdude 2021-02-19T14:22:29.221300Z

Feel free to post an issue

Niklas 2021-02-19T14:23:32.222400Z

I'm more interested in a solution without hacks, so basically you are open to adding the :exclude arg to the :refer linter?

borkdude 2021-02-19T14:23:41.222600Z

yeah

Niklas 2021-02-19T14:23:51.222800Z

thanks

borkdude 2021-02-19T14:24:52.223500Z

@nicke.claesson One thought: since you will probably also add the same namespace to the exclude for the refer-all, maybe we can make it so that the refer linter also uses that config

borkdude 2021-02-19T14:25:21.223800Z

oh wait, you were not going to do :refer :all, then never mind

Niklas 2021-02-19T14:29:14.224400Z

exactly, I won't need :refer :all πŸ™‚

practicalli-john 2021-02-19T14:54:13.225Z

Is there an annotation I can add to my rich comment blocks that tells clj-kondo to completely ignore the contents for any checks (I am looking at the docs, but trying to fix a broken build)

borkdude 2021-02-19T14:55:14.225400Z

yes, #_:clj-kondo/ignore

borkdude 2021-02-19T14:55:39.225600Z

just place it before the comment form

practicalli-john 2021-02-19T14:58:09.225900Z

Awesome, you have unbroken the build πŸ™‚

dharrigan 2021-02-19T14:59:20.226600Z

how about this too? {:skip-comments true} in the config.edn?

practicalli-john 2021-02-19T15:00:06.227200Z

That is a good idea, once we update the project to deps.edn πŸ™‚

dharrigan 2021-02-19T15:01:11.227400Z

it's not in deps.edn

dharrigan 2021-02-19T15:01:18.227700Z

it's the configuration for clj-kondo

dharrigan 2021-02-19T15:01:25.228Z

.clj-kondo/config.edn

practicalli-john 2021-02-19T15:04:35.228500Z

Ah, yes, sorry doing many things all at once and all of them are broken 😞

practicalli-john 2021-02-19T15:19:47.230700Z

Thinking about this, we only want to skip comments on the build which is done via GitHub actions, so I assume instead of this line in the .yml file

run: lein with-profile test clj-kondo --lint .
we can add the config like this to the .yml file
run: lein with-profile test clj-kondo --lint --config '{:skip-comments true}' .
I guess if I run it I will find out πŸ™‚

borkdude 2021-02-19T15:23:00.230900Z

yes, you can do that

borkdude 2021-02-19T15:23:11.231100Z

no

borkdude 2021-02-19T15:23:16.231300Z

--lint . --config ...

practicalli-john 2021-02-19T15:23:59.231400Z

ah, thanks. I'll fix before I push πŸ™‚

ikitommi 2021-02-19T15:48:23.234100Z

is there a way to describe HOFs with clj-kondo? e.g. β€œfunction takes a function of :int -> :int”. there is :fn and :ifn, but they don’t have type info or arities, I guess.

borkdude 2021-02-19T15:51:20.234700Z

no higher kinded types or even generics in the clj-kondo type system currently :)

πŸ‘Œ 1
2021-02-19T17:16:51.241200Z

Hi, first off - thank you for creating clj-kondo :thanks3:. It's amazing project. Quick question on the https://github.com/clj-kondo/config. It looks like the recommended way to lint slingshot is https://github.com/clj-kondo/config/blob/master/slingshot/.clj-kondo/config.edn (or at least that's the only way i got it to work). Does anyone have an example of pulling slingshot as a library instead of the manual copy config ? maybe there is something different about slingshot that prevents us from pulling it as a library ?

{:lint-as { slingshot.slingshot ...} }

borkdude 2021-02-19T17:18:45.242600Z

@dviramontes if you put the clj-kondo configs library on your classpath and then lint your classpath using:

clj-kondo --lint $(clojure -Spath) --no-warnings
while you also have a .clj-kondo directory, then clj-kondo will copy the config and it will also propose how you can activate it.

borkdude 2021-02-19T17:19:52.242800Z

$ clj-kondo --no-warnings --lint "$(clojure -Spath -Sdeps '{:deps {clj-kondo/config {:git/url "<https://github.com/clj-kondo/config>" :sha "e2e156c53c6c228fee7242629b41013f3e55051d"}}}')"

borkdude 2021-02-19T17:20:02.243100Z

(you might need to update the SHA)

2021-02-19T17:24:27.243900Z

Gotcha, thank you so much @borkdude!

practicalli-john 2021-02-19T17:34:09.246600Z

For a CI environment, if I only want to get error level and skip warnings, would I use the --no-warnings flag as a command line argument? I only want the build to fail on error level linting, skipping warnings that are less important. Or would it be more appropriate to specify a particular config file and somehow suppress clj-kondo warnings in that ci-config.edn file? I guess I could create a ci-config.edn with ignores for the rules we didnt want to stop the build for.

borkdude 2021-02-19T18:13:21.247400Z

@jr0cket The, no --no-warnings argument is only used for populating the cache, so you lint, but you will ignore the warnings

borkdude 2021-02-19T18:13:46.247800Z

Creating a ci-config.edn is indeed the one you need

πŸ‘ 1
ikitommi 2021-02-19T19:17:48.248400Z

given that a library (here: malli) can emit clj-kondo :type-mismatch configs from a namespace x. is there a convention / place where to write the info so it's picked up automatically?

borkdude 2021-02-19T19:18:36.248900Z

@ikitommi Not really, you can write to any dir inside .clj-kondo and then users can opt in to that config using :config-paths

borkdude 2021-02-19T19:19:04.249300Z

This is opt-in for safety, since I don't want users to automatically opt-in to hook code, etc

πŸ‘Œ 1
ikitommi 2021-02-19T19:19:12.249400Z

and same question but for the library's own function definitions.

borkdude 2021-02-19T20:24:13.250700Z

@l0st3d Not really, since I don't think you will catch many errors using static analysis.

borkdude 2021-02-19T20:24:32.251Z

Unless you go fully statically typed

borkdude 2021-02-19T20:28:47.252900Z

same answer applies, I think?

Ed 2021-02-19T20:29:04.253500Z

yeah ... you're probably right πŸ˜‰ ... just wondered how far you could go with that sort of analysis ... like maybe as far as the structural typing type thing, so something like

(-&gt;&gt; (range 10)
       (map #(array-map :test %))
       (map #(update % :test str))
       (map #(update % :test inc)))
would give an error ... but you're probably right, it's probably way more effort than it's worth πŸ˜‰

Ed 2021-02-19T20:30:49.253900Z

that's probably a research project ...

borkdude 2021-02-19T20:31:20.254400Z

there's already such a research project and someone who has a PhD on it: @ambrosebs in #core-typed

Ed 2021-02-19T20:32:00.254700Z

yeah ... that's what I meant πŸ˜‰

borkdude 2021-02-19T20:33:12.255500Z

If Clojure becomes popular enough, maybe M$FT will make a TypeScript for CLJ? ;)

Ed 2021-02-19T20:33:18.255800Z

ha

Ed 2021-02-19T20:36:02.259Z

it's just I feel like having the type system outside of the compiler (like a linter) is just better design ... you don't need to police it, just inform people of possible problems ... and given that freedom, I wondered if it would be easier to get some quick wins in that direction ...

Ed 2021-02-19T20:36:22.259700Z

just an idle thought πŸ˜‰

Helins 2021-02-19T20:36:49.260200Z

Kondo complains that do is redundant, is it?!

#?(:clj  (Long/reverseBytes b64)
     :cljs (do
             (.setBigUint64 -data-view
                            0
                            b64
                            false)
             (.getBitUint64 -data-view
                            0
                            true)))

borkdude 2021-02-19T20:37:09.260700Z

Well, clj-kondo already has a type system, albeit a simple one which catches many things I found annoying myself.

$ clj-kondo --lint - &lt;&lt;&lt; '(take 10 (map inc))'
&lt;stdin&gt;:1:10: error: Expected: seqable collection, received: transducer.

borkdude 2021-02-19T20:37:30.261100Z

@adam678 This depends on the context

borkdude 2021-02-19T20:38:21.261900Z

If there is already an (implicit do) around this, then it could be redundant and you can avoid this using #?@

Ed 2021-02-19T20:38:28.262Z

yup ... and I think it's great ... I find it very ... it catches a lot of the stupid mistakes I make every day ... Thank-you so much for releasing it to the world

Helins 2021-02-19T20:40:12.263400Z

Right, those forms are the body of a function so I should #?@ indeed to be technically correct. Took me a bit off guard.

Ed 2021-02-19T20:45:17.263500Z

could you treat map/`filter` /etc as -&gt;? so that if you can tell what type the elements of the list are, you could turn (map inc (map str (range 10))) into (-&gt; 10 str inc), which could return a warning? ...

borkdude 2021-02-19T20:58:32.263700Z

Maybe, but probably not low hanging fruit

2021-02-19T21:12:11.264300Z

Does CLJ-Kondo have a way to exclude a namespace from linting ?

borkdude 2021-02-19T21:14:39.264800Z

@dviramontes Kind of, you can exclude files from the lint output. See https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md#include-and-exclude-files-from-the-output

1
1
2021-02-19T21:15:20.265400Z

right on! thank you

borkdude 2021-02-19T21:18:11.265600Z

@ikitommi I am considering a dir structure reflecting the namespaces of the vars being typed if the type output gets too large to read on every clj-kondo startup

borkdude 2021-02-19T21:18:37.265800Z

But this would only become relevant if people are type annotating lots and lots of functions, which is currently not the case