Fork me on GitHub
#clj-kondo
<
2020-10-01
>
dharrigan09:10:43

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

dharrigan09:10:49

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

dharrigan09:10:11

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]

dharrigan09:10:04

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)

dharrigan09:10:25

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

borkdude09:10:24

@dharrigan There is a recent issue for this.

borkdude09:10:43

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

borkdude09:10:06

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

dharrigan09:10:09

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

borkdude09:10:23

yeah well, PR welcome. :)

borkdude09:10:42

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

borkdude09:10:56

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

dharrigan09:10:28

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

borkdude09:10:29

Let me mark this for the next release

dharrigan09:10:42

but um, don't wait for me 🙂

borkdude09:10:06

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

Kevin19:10:51

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

; (template/fn args source)
; Example:
(def hello
  (template/fn [name] "Hello <%= name %>"))

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

borkdude19:10:31

probably clojure.core/fn

borkdude19:10:22

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

borkdude19:10:53

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

👍 3
Kevin19:10:34

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

borkdude20:10:18

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

👍 3
Kevin19:10:42

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

borkdude19:10:26

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

borkdude19:10:33

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

borkdude19:10:44

also these approaches tend to launch missiles