Fork me on GitHub
#clj-kondo
<
2024-03-06
>
martinklepsch08:03:53

Weird linting request — could I lint keywords that start with :on to not contain dashes?

borkdude08:03:22

Not currently - you could however use the analysis output and scan for it manually using a script

martinklepsch08:03:40

Hm yeah, but then I wouldn't get warnings in my editor which is kind of the motivation. No problem though, just thought I'd ask 🙂 thanks for the quick response!

martinklepsch10:03:28

I guess one thing that might be possible is a function linter that checks literal keywords in a map that's passed to it?

pavlosmelissinos13:03:08

We started getting OOM errors on CircleCI with the latest version of clj-kondo. Anyone else facing the same problem? 2024.02.12 works fine. Context in thread

1
pavlosmelissinos13:03:58

command:

clojure -M:clj-kondo --lint "$(clojure -Spath)" --dependencies --parallel
clojure -M:clj-kondo --fail-level error --lint src --lint test --lint plugins
where clj-kondo is this alias:
{:replace-deps {clj-kondo/clj-kondo {:mvn/version "RELEASE"}}
                         :main-opts ["-m" "clj-kondo.main" ]}
stacktrace:
Exception in thread "pool-1-thread-3" java.lang.OutOfMemoryError: Java heap space
        at clojure.lang.ArraySeq.next(ArraySeq.java:78)
        at clojure.lang.RT.next(RT.java:713)
        at clojure.core$next__5451.invokeStatic(core.clj:64)
        at clojure.core$second__5457.invokeStatic(core.clj:98)
        at clojure.core$assoc__5481.invokeStatic(core.clj:197)
        at clojure.core$assoc__5481.doInvoke(core.clj:192)
        at clojure.lang.RestFn.invoke(RestFn.java:731)
        at clj_kondo.impl.types$add_arg_type_from_call.invokeStatic(types.clj:390)
        at clj_kondo.impl.types$add_arg_type_from_call.invoke(types.clj:387)
        at clj_kondo.impl.analyzer$analyze_expression_STAR__STAR_.invokeStatic(analyzer.clj:2977)
        at clj_kondo.impl.analyzer$analyze_expression_STAR__STAR_.invoke(analyzer.clj:2799)
        at clj_kondo.impl.analyzer$analyze_children$fn__14975.invoke(analyzer.clj:77)
        at clojure.core$map_indexed$fn__8634$fn__8635.invoke(core.clj:7366)
        at clojure.lang.ArrayChunk.reduce(ArrayChunk.java:58)
        at clojure.core.protocols$fn__8244.invokeStatic(protocols.clj:136)
        at clojure.core.protocols$fn__8244.invoke(protocols.clj:124)
        at clojure.core.protocols$fn__8204$G__8199__8213.invoke(protocols.clj:19)
        at clojure.core.protocols$seq_reduce.invokeStatic(protocols.clj:31)
        at clojure.core.protocols$fn__8236.invokeStatic(protocols.clj:75)
        at clojure.core.protocols$fn__8236.invoke(protocols.clj:75)
        at clojure.core.protocols$fn__8178$G__8173__8191.invoke(protocols.clj:13)
        at clojure.core$transduce.invokeStatic(core.clj:6947)
        at clojure.core$into.invokeStatic(core.clj:6962)
        at clojure.core$into.invoke(core.clj:6950)
        at clj_kondo.impl.analyzer$analyze_children.invokeStatic(analyzer.clj:75)
        at clj_kondo.impl.analyzer$analyze_children.invoke(analyzer.clj:50)
        at clj_kondo.impl.analyzer$analyze_children.invokeStatic(analyzer.clj:52)
        at clj_kondo.impl.analyzer$analyze_children.invoke(analyzer.clj:50)
        at clj_kondo.impl.analyzer$analyze_fn_body.invokeStatic(analyzer.clj:511)
        at clj_kondo.impl.analyzer$analyze_fn_body.invoke(analyzer.clj:459)
        at clj_kondo.impl.analyzer$analyze_defn$fn__15161.invoke(analyzer.clj:652)
        at clojure.core$map$fn__5935.invoke(core.clj:2772)

borkdude13:03:26

do you have a repro that I can run locally?

pavlosmelissinos13:03:37

Sorry, I can't reproduce it locally 😞

borkdude13:03:56

It could be a bug in the new release, but without a repro it's hard to confirm that... Perhaps you can lower the memory with

-Xmx2048m
or so and play with it and see where the previous version still works and the new one doesn't

pavlosmelissinos16:03:09

Nope, still can't reproduce... In fact the new version seems to behave better on my machine at 512MB. I don't think there's anything you can do with this information... We've bypassed the issue by pinning clj-kondo to the previous version (`2024-02-12`), so it's not a big deal (for now). I've marked this as resolved. Thanks for your help 🙂

borkdude16:03:55

so you'll stay on 2024-02-12 forever now? ;)

😄 1
borkdude10:03:31

@UEQPKG7HQ I think I may have found where the issue could be coming from. Are you using clj-kondo on the JVM in CI? If so, could you please test with commit:

c1780ac6308edebbefa9745d0887442c9964b99a
vs commit:
ace53daa65afe251354c331c74c334df6beb877a

borkdude11:03:53

you can also try the binaries for those commits, I can link you to those binaries

pavlosmelissinos11:03:37

so you'll stay on 2024-02-12 forever now?Why not? It's good enough 😄 > could you please test with commit Just did; c1780a works, ace53d doesn't! (on CI, still can't reproduce locally)

borkdude11:03:12

yeah I suspected so. I will try to make a fix and then you can try the new commit

❤️ 1
borkdude11:03:29

Alright, try commit 99650c58bb8df990d6c28d8b554d84df6608ad4c

🏃 1
pavlosmelissinos11:03:48

It works, thanks a lot! 🙂

grav21:03:50

Curious, what was the issue?

borkdude21:03:53

Too many large hash-maps in memory

👍 1
jpmonettas13:03:03

hi everybody! What is the simplest way of making clj-kondo not complain about :

(def possibly-a-number nil)

(defn some-check []
   (and possibly-a-number (< possibly-a-number 42)))
on the and line it says Expected a number, received: nil . This should be fine because possibly-a-number is being changed with alter-var-root to a number

borkdude13:03:12

Maybe just change nil to a number?

jpmonettas13:03:54

but I need the nil, which means that option hasn't been set

borkdude13:03:05

alternatively you can prefix the offending form with #_:clj-kondo/ignore

👍 1
jpmonettas13:03:59

but in this case I guess I can assign a default number which means no number

jpmonettas13:03:27

thanks!

👍 1
Ed15:03:34

If it's a thing that you're updating, why not use a promise?

(def possibly-a-number (promise))

(defn some-check []
  (and (realized? possibly-a-number) (< @possibly-a-number 42)))

(defn initialise []
  (deliver possibly-a-number 12)
  nil)

(comment

  (some-check) ;; => false

  (initialise) ;; => nil

  (some-check) ;; => true

  )

Ed15:03:50

or an atom?

jpmonettas15:03:49

just semantics. That was a contrived example, not my exact code. It is a thing that will be nil for most users but you can put a number there once if you need a different behavior. A promise conveys that something will be delivered there eventually, and an atom that is a value that is supposed to change so you need to constantly deref. Since you are constantly derefing the var, a simple var is enough for this, doesn't need a reference inside a reference.

Noah Bogart15:03:56

to solve this generally, clj-kondo would have to become a fully-fledged type inference engine lol