Fork me on GitHub
#clj-kondo
<
2023-09-22
>
ray08:09:15

A JS interop case that bit me yesterday was this line: (js/console "Something" js-obj-thing) and of course I meant js/console.log "Something" js-obj-thing but the output was to debug a third party library whose calling semantics were a bit obscured cos it's written in TS and I was getting all kinds of other errors that blinded me to that SNAFU ... totally floored when I realized that I had fixed the call to the library 30 mins ago but was still banging my head trying to understand this

TypeError: Function.prototype.apply was called on #<Object>, which is a object and not a function
    at bt (file:///home/ray/acme/repos/publish-rate-card/node_modules/nbb/lib/nbb_core.js:338:125)
    at file:///home/ray/acme/repos/publish-rate-card/node_modules/nbb/lib/nbb_core.js:597:410
    at R (file:///home/ray/acme/repos/publish-rate-card/node_modules/nbb/lib/nbb_core.js:309:469)
    at file:///home/ray/acme/repos/publish-rate-card/node_modules/nbb/lib/nbb_core.js:558:423
    at R (file:///home/ray/acme/repos/publish-rate-card/node_modules/nbb/lib/nbb_core.js:309:469)
    at file:///home/ray/acme/repos/publish-rate-card/node_modules/nbb/lib/nbb_core.js:559:305
    at R (file:///home/ray/acme/repos/publish-rate-card/node_modules/nbb/lib/nbb_core.js:309:469)
    at file:///home/ray/acme/repos/publish-rate-card/node_modules/nbb/lib/nbb_core.js:418:411
    at file:///home/ray/acme/repos/publish-rate-card/node_modules/nbb/lib/nbb_promesa.js:39:342
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

Jordan Yee18:09:34

This makes me wonder if it would be useful to support a simple regex rule type (if there isn't already such a thing). For a static case like this, you would define a rule something like:

{:regex {:match "js/console "
              :message "Did you mean `js/console.log`?"}}

ray19:09:00

Yes - would be 😎

ray08:09:34

Having a warning that it was not js/console.log or js/console.error would have been nice 🙂

ray09:09:57

oh, and the rule should be called consolation 😛 ... I'd be interested in making a PR if you want to give me a steer @borkdude

borkdude11:09:31

Hey Ray, thanks for the ideas, but not sure how generalizable this is. There might be objects on js that are legit, defined by libraries as globals. How would clj-kondo know what's valid?

ray12:09:58

Yeah, I’m not sure how to make it general but I still think that having some known good vs unknown states could be useful. Somebody might have console globally but if it is in the function slot, it should be callable ie not an object or an object property

ray12:09:22

I’m riffing here though… I’m sure you have a better grasp on what is feasible

martinklepsch16:09:03

Hello — I'm using lambdaisland/glogi and sometimes it happens that I do something like (log/info :test) but since glogi expects map-entries this should be at least (log/info :test nil) — I tried adding a :lint-as entry pointing to clojure.core/hash-map but so far it doesn't seem like that is being picked up. Am I missing anything here?

borkdude18:09:12

I’m at Strange loop but I’ll set a reminder for next week

❤️ 1
martinklepsch18:09:14

thank you! enjoy strange loop 🙂

borkdude13:09:34

I guess lint-as doesn't really treat type checking the same way, maybe for good reasons

martinklepsch17:09:58

ah but isn't this more of an arity-check in a way?

borkdude17:09:34

the hash-map function is varargs

borkdude17:09:51

but yes, in a way it is

borkdude17:09:44

but this is going via the type checking mechanism

borkdude17:09:09

it's expecting an even number of things which it is then going to type check

borkdude17:09:19

I don't think lint-as affects arity checking, it's mostly for getting rid of unknown macro syntax things

borkdude17:09:15

you could set this type for glogi/log manually:

'hash-map {:arities {:varargs {:args [{:op :rest :spec [:any :any]}]
                                  :ret :map}}}

borkdude17:09:36

{:linters {:type-mismatch {:namespaces {lint-as {dude {:arities {:varargs {:args [{:op :rest :spec [:any :any]}]
                                                                           :ret :map}}}}}}}

martinklepsch17:09:33

Thanks, that's doing what I was looking for 🙂