Fork me on GitHub

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 🙂


There is a style-guide rule to use underscores 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.


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).


^ @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.


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


@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?


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


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". ¯\_(ツ)_/¯


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

^ 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.


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


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


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...


@sogaiu did crossclj ever have information about local bindings?


@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


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


clj-kondo could emit it in the analysis info


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


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


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


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


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


it could potentially be improved


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


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


feel free to post an issue with this

👍 4

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

❤️ 12

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?


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


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


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


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


Is lang mandatory when using the cache?


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


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


yes, that's a good idea


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


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


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


I mean for this be the default.


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?


it's an option in the config yes


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


This is great, thanks!