Fork me on GitHub
#clj-kondo
<
2023-04-20
>
genmeblog19:04:02

Is the :exclude-patterns planned in :unused-private-var linter?

borkdude19:04:20

Do you have that many private vars that you need to suppress a whole lot of them? :)

borkdude19:04:09

Tell me more, I want to see them :)

borkdude19:04:43

but seriously, I think that would be fine

borkdude19:04:51

issue / PR welcome

genmeblog19:04:31

haha, it's not easy to convince you 🙂

genmeblog19:04:00

I use some general patterns for private functions to later generate public functions

borkdude19:04:11

The way I usually solve this is move those to an foo.internal namespace and make them public

genmeblog19:04:38

hmmm... it's possible in this case.

genmeblog19:04:22

actually I can make them public

genmeblog19:04:11

anyway, I think that every linter which can have :exclude could have :exclude-patterns as well, what do you think?

genmeblog19:04:33

it will enable a lot of possiblities and simplification in some cases

borkdude20:04:37

yes, I'm not opposed to it

genmeblog20:04:27

I'll leave the issue then

borkdude20:04:25

@U1EP3BZ3Q Note that you can also disable the unused-private-var linter in one specific namespace only

genmeblog20:04:01

Yes, I know it. I usually prefer to narrow exclusion as much as possible. I solved this particular case by making these functions public.

genmeblog20:04:25

Another question today, amap warns about unused binding ret or any used symbol (there was an issue about throwing the error which was fixed). Is it ok and should I change it to _ret for example?

borkdude20:04:02

Do you have an example?

genmeblog20:04:39

(def an-array (int-array 25000 (int 0)))

(time (amap ^ints an-array 
            idx 
            ret 
            (+ (int 1) 
               (aget ^ints an-array idx))))

genmeblog20:04:09

clj-kondo v2023.04.14

borkdude20:04:30

yes, underscore seems fine there if ret is not used?

borkdude20:04:42

or am I missing something?

genmeblog20:04:32

ret is internal name used by amap which is a macro. It expands as:

(let*
  [a__6552__auto__
   an-array
   l__6553__auto__
   (alength a__6552__auto__)
   ret
   (aclone a__6552__auto__)]
  (loop*
    [idx 0]
    (if (< idx l__6553__auto__)
      (do
        (aset ret idx (+ (int 1) (aget an-array idx)))
        (recur (unchecked-inc idx)))
      ret)))

genmeblog20:04:11

In 99% you do not use this name.

borkdude20:04:20

why does amap make you choose a name for this?

genmeblog20:04:26

It doesn't. But this is stated in documentation >

Maps an expression across an array a, using an index named idx, and
> return value named ret, initialized to a clone of a, then setting 
> each element of ret to the evaluation of expr, returning the new 
> array ret.

genmeblog20:04:42

So probably everyone just leave it as ret

borkdude20:04:59

you can also name it _

borkdude20:04:31

I'm fine with suppressing that lint warning

borkdude20:04:06

it raises the question: is there ever a situation when someone does want to have a warning about that being unused? seems unlikely right

genmeblog20:04:22

Seem unlikely I think. It's kind of pattern introduced by authors and documented as "use ret"

genmeblog20:04:37

areduce is another case

borkdude20:04:59

sure issue welcome, although myself I've always just underscored the binding

genmeblog20:04:32

Without knowing the internals, most people - probably - will use ret because it's stated in the doc and clojuredocs examples. I agree that maybe there is someone who will complain about switching off this warning, who knows... Anyway, leaving the issue.

👍 2
genmeblog20:04:53

areduce is the wrong example, so it applies only for amap

genmeblog20:04:45

ret in areduce is and should be used by user (it's the accumulator)

borkdude21:04:47

it feels a bit arbitrary to make an exception just for amap - I think most clj-kondo users will know that when you're not referring to ret, they can underscore it

genmeblog21:04:29

Yes, it's arbitrary. I agree with that. Well. I've never hit the case when ret was referred. But it should be named.

genmeblog21:04:44

I'm starting to have doubts 🙂