yesterday I noticed an issue with our tests where, we had something like
(deftest mytest
...
(fn [{:keys [v]}]
(is (= 1 1))))
which meant that the the assertion was never actually checked. It happened because previously there was a function that took another function just above and a refactoring messed it up.
I guess clj-kondo can't detect these sorts of mistakes right?There is a check like this but this specific case might not be covered yet. It’s called missing test assertion
Issue welcome
yeah I was wondering if it's technically possible at all
since it would have to know that the macro/function just above is not actually eventually executing that function passed in
I think a top level function should be reported as an unused value like in defn
I mean something like this should not be considered invalid for example, where with-infra can either be a function or a macro
(with-infra
(fn [k]
(is (= 1 ...))Sure but deftest is known to be not like that
yeah but we have this sort of code inside a deftest for example
I don't think you can tell from static analysis if a macro/function would call the function it takes as argument right?
Please give a complete example because I think we're misunderstanding. The example you gave:
(deftest mytest
...
(fn [{:keys [v]}]
(is (= 1 1))))
indicates that the fn is placed as a top level expression inside deftest but the explanations that follow make it seem that this is not the case. So a complete example would get rid of that ambiguityah yeah well it would not be under deftest directly
iI mean yeah if it is then yeah it's possible to detect
but I think it would not be in our code at least
yeah, in that case it's quite impossible
Is there a way to suppress the unused-binding linter specifically for the initial argument in a defrecord/extend-type/extend-protocol method arglist?
(defrecord Foo [bar]
Bazzable
(baz [this] bar)) ;; <- Warning: unused binding thisOne could go about naming them with a leading underscore _this /`_ but that doesn't seem very idiomatic.. after all it is being used implicitly by the field references bar` ~ (.-bar this)
perhaps we should make this an option , issue welcome
We use this in some code:
{:linters {:unused-binding {:exclude-patterns ["^this"]}}}
That's not specific for the first parameter of defrecord et. al, but it seems to work for us.
Ah yes, that’s a good solution as well