Fork me on GitHub
#clj-kondo
<
2019-08-06
>
viesti04:08:16

hum, was just mocking a function with with-redefs to return a canned response and wondered how to make the squiggly line under unused argument go away and happened to put a underscore in front and it did the trick, like:

(with-redefs [clojure.core/identity (fn [_argument] 42)])
Felt like a useful thing, maybe this is a pattern even that didn't know 🙂

pithyless06:08:25

There is a style-guide rule to use underscores for unused bindings: https://guide.clojure.style/#underscore-for-unused-bindings There is also an extension of that rule, such that you can use an underscore followed by a name to give a binding a name, but to specify it will not be used (so, for documentation purposes only). IIRC, both clj-kondo and joker implement this extension.

pithyless06:08:19

It seems intuitive to me, but honestly I just now realize this is a convention I was already familiar with from the ML-based languages (Haskell, OCaml).

pithyless07:08:42

^ @borkdude WDYT of linting the opposite? Reporting that an "underscored" binding was used. This to me sounds similar to using def inside a defn => something you may want to do during development, but not something you want to commit.

pithyless07:08:45

❯ echo '(defn foo [_x] _x)' | clj-kondo --lint -

borkdude07:08:12

@pithyless I've thought about that, but it I'm not 100% sure if that's a good idea. in some cases it might be desirable to call your binding _foo_ while also be able to use it without a warning?

borkdude07:08:21

_ is a way to disable the linter. I think the mode "you're on your own now" makes sense

pithyless07:08:35

Fair enough; for me the _ is a useful pattern to document unused arity arguments or side-effecting let bindings, but I have not personally thought of it as "you're on your own". ¯\_(ツ)_/¯

borkdude07:08:38

In practice, when using variables with an underscore when it's not a binding will probably make you change it anyway, in my experience.

☝️ 4
pithyless07:08:52

^ I agree with this sentiment, which was actually my reason for raising the idea. If you think of a linter as an automated PR check to make sure that reviewer time is not spent on pointing out things that could have been automated, then I would argue that any code that is referencing _foo should get a warning. This could be a either because something was missed during the commit phase or someone is simply unaware of the convention that will trip up other readers.

pithyless07:08:08

But I'm not prepared to die on the hill for this; we can just as easily drop it ;]

pithyless07:08:48

I wonder how prevalant it is to use _foo_ or _foo intentionally in real codebases... :thinking_face:

sogaiu07:08:50

there isn't a crossclj replacement to make queries of this sort, right? perhaps it will be something the cljdocs folks will take on eventually...

borkdude07:08:24

@sogaiu did crossclj ever have information about local bindings?

borkdude07:08:22

@pithyless it's an interesting idea, I'm just not sure if it will lead to unwanted warnings. it could be an optional linter that's not on by default

sogaiu07:08:32

i do not know if crossclj had info on local bindings.

borkdude07:08:42

clj-kondo could emit it in the analysis info

borkdude07:08:02

that will lead to loads of data, but it could be optionally on

yuhan08:08:11

I've noticed that flycheck-clj-kondo chokes up on certain syntax errors like a single colon : or a incomplete namespaced symbol foo/, and just outputs a single error on the first line of the file with a message referencing the actual error location

yuhan08:08:34

Is this a bug with the linter output format or some sort of reader limitation?

yuhan08:08:11

eg. other read-time syntax errors like {a} produce a lint error directly at the point without the rest of the file being affected

borkdude08:08:17

I think it's a reader limitation, since tools.reader chokes on it

borkdude08:08:43

it could potentially be improved

yuhan08:08:36

hmm yeah, it's friendlier if the line/col info from the reader-error could be propagated to the linter output

yuhan08:08:33

I assume Flycheck would then pick it up and display the squiggly line at the correct place

borkdude09:08:59

feel free to post an issue with this

👍 4
manuel12:08:25

@borkdude chiming in here to say THANK YOU for clj-kondo and flycheck-clj-condo. Simple to install and use. Great stuff indeed. 🙂

❤️ 12
mynomoto20:08:58

On the latest release clj-kondo is not using the created cache. I have a file with warnings when I run clj-kondo --lint "$(clj -A:dev -Spath)" --cache but not when I run clj-kondo --lang clj --cache the-file-with-warnings Am I doing something wrong?

borkdude21:08:06

the (optional) argument to --cache is a directory. you should pass the file to lint to --lint

borkdude21:08:39

so: clj-kondo --lang clj --cache --lint the-file

borkdude21:08:55

thank you for your issue on schema defmethod, I'll take a look later this week

mynomoto21:08:07

@borkdude thanks, I was sure that I tried what you suggested earlier but it sure worked now.

mynomoto21:08:30

Is lang mandatory when using the cache?

borkdude21:08:39

lang is derived from the file extension. the cmd line option is only used when you lint from stdin because then this information isn't there

mynomoto21:08:31

Ok, good to know, thanks. I need to do a pr on Ale for it to use the cache on vim.

borkdude21:08:51

yes, that's a good idea

borkdude21:08:06

maybe I can change the default for the cache option, because there's also an issue at @marc-omorain’s clojure-lint for this, which isn't fixed yet

borkdude21:08:22

so: always use the cache if you can find a .clj-kondo directory... not sure if that's a good idea

mynomoto21:08:16

I was thinking about it and what worries me is stale caches.

mynomoto21:08:27

I mean for this be the default.

mynomoto21:08:11

I think you posted a command to do the whole cache but output only project files. Was that a grep on the results or it is a clj-kondo option? Or I'm just imagining things?

borkdude21:08:51

it's an option in the config yes

borkdude21:08:52

maybe these editor plugins should allow you to pass in extra arguments yourself

mynomoto22:08:45

This is great, thanks!