This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-08-06
Channels
- # aleph (1)
- # beginners (180)
- # calva (16)
- # cider (29)
- # clj-kondo (47)
- # cljsrn (5)
- # clojure (40)
- # clojure-dev (39)
- # clojure-europe (1)
- # clojure-italy (25)
- # clojure-nl (9)
- # clojure-russia (1)
- # clojure-spec (8)
- # clojure-uk (83)
- # clojurescript (54)
- # core-async (2)
- # datomic (20)
- # defnpodcast (7)
- # figwheel (6)
- # fulcro (6)
- # jobs (5)
- # joker (4)
- # kaocha (4)
- # luminus (4)
- # off-topic (8)
- # onyx (6)
- # pathom (14)
- # re-frame (28)
- # reagent (30)
- # remote-jobs (2)
- # shadow-cljs (88)
- # spacemacs (2)
- # specter (17)
- # sql (25)
- # tools-deps (78)
- # xtdb (1)
- # yada (2)
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: 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.
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.
@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.
^ 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.
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...
@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'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
eg. other read-time syntax errors like {a}
produce a lint error directly at the point without the rest of the file being affected
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
@borkdude chiming in here to say THANK YOU for clj-kondo
and flycheck-clj-condo
. Simple to install and use. Great stuff indeed. 🙂
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
@borkdude thanks, I was sure that I tried what you suggested earlier but it sure worked now.
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
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 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?