Is keys destructuring for documentation reasons good style? The reason I'm asking is that clj-kondo, a linter for Clojure, reports unused bindings. E.g.:
(let [x 1, y 2] y)
results in a warning about x
being unused.
Sometimes people do this:
(defn public-foo [{:keys [foo bar] :as x}]
(private-baz x))
only to get a better docstring (or generated documentation) for public-foo
. But they will get a warning about foo
and bar
being unused. An example from the wild: link.
Destructuring is not free in terms of performance, so using spec or :arglists
may be a better alternative to get these documentation benefits. E.g.:
user=>
(defn public-foo
{:arglists '([{:keys [foo bar] :as x}])}
[x]
;; (private-baz x)
)
#'user/public-foo
user=> (doc public-foo)
-------------------------
user/public-foo
([{:keys [foo bar], :as x}])
nil
I'd like some consensus on this before I make any configuration support in clj-kondo to suppress warnings for unused bindings introduced by keys destructuring in function arguments.