clj-kondo

https://github.com/clj-kondo/clj-kondo
dharrigan 2020-10-01T09:27:43.063900Z

One of the things I'm playing around with is using this style of destructuring:

dharrigan 2020-10-01T09:27:49.064100Z

(defn foo
  [{:keys [bar baz] :as config}]
  ...
  ...do something with bar
  ...do something with baz
  ...)

dharrigan 2020-10-01T09:29:11.065200Z

As you notice, config is not being used, however, it is useful for documenting, as pointed out elsewhere ...two fns that look superficially similar can be immediately distinguished [by looking at the :as]

dharrigan 2020-10-01T09:30:04.066300Z

Current clj-kondo flags config as not being used. I know I could put an unused var escape before the form or globally, but that's overkill (globally) or noise (individually for each form)

dharrigan 2020-10-01T09:30:25.066700Z

Could clj-kondo have a configuration to ignore unused binding for :as?

borkdude 2020-10-01T09:31:24.067300Z

@dharrigan There is a recent issue for this.

dharrigan 2020-10-01T09:31:27.067500Z

oooh

dharrigan 2020-10-01T09:32:02.067700Z

<https://github.com/borkdude/clj-kondo/issues/1016>

borkdude 2020-10-01T09:32:12.067900Z

https://github.com/borkdude/clj-kondo/issues/1016

borkdude 2020-10-01T09:32:14.068200Z

right

borkdude 2020-10-01T09:32:43.068700Z

for now the way to do this is to use :as _the-name

borkdude 2020-10-01T09:33:06.069500Z

or :as #_:clj-kondo/ignore the-name but this needs fixing

dharrigan 2020-10-01T09:33:09.069700Z

I'm sorta in agreement with the OP, using _ is a bit aesthetically out of place

borkdude 2020-10-01T09:33:23.070100Z

yeah well, PR welcome. :)

dharrigan 2020-10-01T09:33:26.070300Z

🙂

borkdude 2020-10-01T09:33:42.070700Z

if nobody will do a PR, I'll probably fix it relatively soon

borkdude 2020-10-01T09:33:56.070900Z

since I'm getting paid for it by CT ;)

dharrigan 2020-10-01T09:34:12.071200Z

w00t! 🙂

dharrigan 2020-10-01T09:34:28.071700Z

I'll try to look (understand) the code base myself today to see if I can contribute

borkdude 2020-10-01T09:34:29.071900Z

Let me mark this for the next release

borkdude 2020-10-01T09:34:34.072100Z

OK

dharrigan 2020-10-01T09:34:42.072400Z

but um, don't wait for me 🙂

borkdude 2020-10-01T09:35:06.072700Z

A hint: look in analyzer.clj in extract-bindings

dharrigan 2020-10-01T09:35:34.073200Z

👌

Kevin 2020-10-01T19:14:51.075100Z

What would the lint-as equivalent be for this macro template/fn ?

; (template/fn args source)
; Example:
(def hello
  (template/fn [name] "Hello &lt;%= name %&gt;"))

(hello "Alice")
https://github.com/weavejester/comb I tried defn but defn has a function name before the args

borkdude 2020-10-01T19:15:31.075700Z

probably clojure.core/fn

borkdude 2020-10-01T19:16:22.076100Z

but you will get unused bindings with that, since kondo doesn't know about this macro

borkdude 2020-10-01T19:16:53.076700Z

you can suppress those with #_:clj-kondo/ignore[:unused-binding] before the (template/fn ...) call

👍 1
Kevin 2020-10-01T19:18:42.077300Z

I'm still new to clojure, but is it not possible to lint macros automatically without supporting them on a case by case basis

borkdude 2020-10-01T19:19:26.078Z

clj-kondo doesn't execute your code, so it can't know what your macro does, which is the fundamental problem

borkdude 2020-10-01T19:20:33.078500Z

there are approaches that execute your code, but they aren't generally suited for editor integration because they are too slow

borkdude 2020-10-01T19:20:44.078800Z

also these approaches tend to launch missiles

Kevin 2020-10-01T19:46:34.080500Z

Is it possible to do something like this:

{:linters {:unused-binding {:exclude [comb.template/fn]}}}
I tried this in my config.edn but it doesn't seem to be working

borkdude 2020-10-01T20:03:18.080700Z

Alas, that's not yet supported. Feel free to make an issue

👍 1