This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-09-11
Channels
- # announcements (3)
- # babashka (6)
- # babashka-sci-dev (37)
- # beginners (39)
- # calva (1)
- # clj-kondo (55)
- # clj-on-windows (1)
- # cljdoc (1)
- # clojure (30)
- # clojure-dev (3)
- # clojure-europe (8)
- # clojure-losangeles (1)
- # clojure-morsels (1)
- # clojurescript (26)
- # conjure (8)
- # graalvm (5)
- # helix (6)
- # hyperfiddle (12)
- # meander (6)
- # minecraft (1)
- # pathom (17)
- # polylith (1)
- # releases (2)
- # shadow-cljs (2)
- # sql (1)
- # squint (4)
Since I'm new to clj-kondo, I'm wondering if someone has advice for configuring around a construct...
I'm calling a macro inside conditional compilation, where the macro generates a record definition that satisfies a protocol. clj-kondo is seeing one of the function definitions in this as a call to the function, and reports an error. The error in this case is that the function expects 3 args but that it's being called with 2 (what it's seeing at the arg vector and a let
block that forms the body of the function).
Any suggestions on how I might inform the linter that this is not a problem, please?
The code in question is at: https://github.com/quoll/asami/blob/a469640790e272ecad6d47bb00a687a3b0291722/src/asami/cache.cljc#L120
Here's what you can do with macros: https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md#unrecognized-macros
I know I'm being a bit needy here, but... Any idea why this causes a problem? https://github.com/quoll/asami/blob/a469640790e272ecad6d47bb00a687a3b0291722/src/asami/durable/flat_file.clj#L118
It's a call of (recur 1)
which is asking to restart a function that's defined in a letfn
and takes a single argument.
But it says:
src/asami/durable/flat_file.clj:118:25: error: recur argument count mismatch (expected 0, got 1)
src/asami/durable/flat_file.clj:135:33: error: recur argument count mismatch (expected 0, got 1)
> I know I'm being a bit needy here Not at all, please do ask all the questions you want
I'm trying to repro that...
$ clj-kondo --lint - <<< '(letfn [(foo [x] (recur 1))])'
<stdin>:1:10: warning: unused binding foo
<stdin>:1:15: warning: unused binding x
linting took 15ms, errors: 0, warnings: 2
:thinking_face:I see that there was an https://github.com/clj-kondo/clj-kondo/issues/131 that was also a problem with arities in letfn, and it referred to something happening in #129
$ clj-kondo --lint - <<< '(defrecord Foo [] clojure.lang.ILookup (valAt [_ _] (letfn [(foo [x] (recur 1 2))])))'
<stdin>:1:62: warning: unused binding foo
<stdin>:1:67: warning: unused binding x
<stdin>:1:70: error: recur argument count mismatch (expected 0, got 2)
so what's happening here: clj-kondo compensates for the recur in valAt
and subtracts the "this" argument but it forgets to turn that off for the letfn function
or you could just use let
+ fn
? :) I usually don't use letfn
at all unless I need mutually recursive functions which I never do
Posted the issue here: https://github.com/clj-kondo/clj-kondo/issues/1806 - I'll fix it before the next release (usually within a month)
While that's reasonable, this code has been around a while, and there's nothing actually wrong with letfn
, so I'll leave it for now
any suggestions on how to create a minimum reproduction that leads to error: Unresolved symbol: format
?
This is an awkward one. The following fails, claiming that fn is called with 1 arg but expects 2
:
https://github.com/quoll/asami/blob/a469640790e272ecad6d47bb00a687a3b0291722/src/asami/query.cljc#L350
The map is creating a transducer that gets applied to a pair of seqs, so I can see how this might confuse the linter
But I can't reproduce it on a smaller scale. For instance, this passes:
(sequence (comp (map (fn [a b] [a b])) cat) [1 2 3] [4 5 6])
So too does code that doesn't work:
(sequence (comp (map (fn [a b c] [a b c])) cat) [1 2 3] [4 5 6])
When I pass that to the linter, it works fine:
$ echo '(sequence (comp (map (fn [a b c] [a b c])) cat) [1 2 3] [4 5 6])' | clj-kondo --lint -
linting took 10ms, errors: 0, warnings: 0
That's despite the code actually failing:
user=> (sequence (comp (map (fn [a b c] [a b c])) cat) [1 2 3] [4 5 6])
Execution error (ArityException) at user/eval1 (REPL:1).
Wrong number of args (2) passed to: user/eval1/fn--137
I need one of these stickers... http://etsy.com/listing/1181583724/idk-what-im-doing-as-a-service-glossy
Speaking of letfn
, it seems that the clj-kondo really doesn't like the plumatic schema version of letfn
@U051N6TTC clj-kondo has built-in support for some schema things, but I don't think letfn has ever come up.
About the invalid arity bug, it seems like clj-kondo is indeed confused about transducer vs. seq. This yields a similar but valid warning:
(comp (map (fn [results _]
(map identity results))
[])
cat)
I narrowed the example down to this in your ns:
(defn disjunction
"Implements an OR operation by repeating a join across each arm of the operation,
and concatenating the results"
[graph
part
[_ & patterns]] ;; Discard the first element, since it is just the OR operator
(sequence
(comp (map (fn [_results _cols]))
cat)
[]
[]))
but when I move this example to a standalone file, the error disappears