Fork me on GitHub
#clj-kondo
<
2022-03-18
>
ikitommi08:03:03

it seems that I would like to push the clj-kondo config.edn into git, but nothing else, could the config be in the top-level folder? currently doing this in .gitignore:

.clj-kondo/*
!.clj-kondo/config.edn

borkdude08:03:02

@ikitommi both lsp and clj-kondo have the convention that you can just put

.cache
in your .gitignore so it will work for both projects

ikitommi08:03:46

… but, under clj-kondo, there are the folders per package too? e.g. babashka, com.gfredericks, …

ikitommi08:03:23

…. or are these just ghosts from older versions of clj-kondo?

borkdude08:03:11

these are configurations imported automatically while scanning the classpath

borkdude08:03:41

you can disable this in .lsp/config.edn :copy-kondo-configs? true

borkdude08:03:53

you are probably seeing these configs because of babashka support in lsp

borkdude08:03:33

if you are using those configs, you can check them into source control, else you can ignore / delete them

ikitommi09:03:59

I think it’s good to have them, just not in the version control as they get created automatically and don’t need versioning.

ikitommi09:03:45

if the config.edn is the only relevant file, this should be ok:

.clj-kondo/*
!.clj-kondo/config.edn

ikitommi09:03:24

… but maybe if the configurations were imported under one folder, it would be easy to exclude, maybe even under .cache?

borkdude09:03:32

> I think it’s good to have them, just not in the version control as they get created automatically and don’t need versioning. This isn't true. They are only copied from the dependencies because lsp does this. If you want to have the same linting in CI, it's good to version those things into version control.

borkdude09:03:14

The recommended way is to include them into version control, so everyone who uses clj-kondo with this repo gets exactly the same linting, whether you use lsp or not

ikitommi15:03:41

good to know, thanks!

lassemaatta09:03:26

is it normal for clj-kondo to warn about the new clojure.core/parse-? functions even when using org.clojure/clojure 1.10.3?

lassemaatta09:03:31

[lassemaatta@archlinux] 10:58 $ echo '(def parse-long 1)' | clj-kondo --lang clj --lint -
<stdin>:1:1: warning: parse-long already refers to #'clojure.core/parse-long
linting took 7ms, errors: 0, warnings: 1

lassemaatta09:03:52

clj-kondo v2022.03.09

lassemaatta09:03:37

I'm creating the local cache with the typical --dependencies --parallel --copy-configs

lassemaatta09:03:10

the clojure.core.transit.json within the cache does not (obviously) mention the new parse- functions

borkdude09:03:18

if you lint dependencies using clj-kondo --lint $(clojure -Spath) this should reset to the clojure version you are using locally

borkdude09:03:46

you can add :refer-clojure :exclude [parse-long] in your namespace to prevent the warning, makes it future-proof anyway

lassemaatta09:03:15

hmm.. if I do something like clj-kondo --lint $(clojure -Spath) --lint some-path-in-project I still get warnings about parse-long, parse-double. Even if I clear the cache. Of course, it's a good idea to deal with those functions, as you said, but I'm curious why do we get these warnings.

lassemaatta09:03:56

and to be clear, clojure -Spath returns src:/home/lassemaatta/.m2/repository/org/clojure/clojure/1.10.3/clojure-.10.3.jar:/home/lassemaatta/.m2/repository/org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-.2.56.jar:/home/lassemaatta/.m2/repository/org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar

borkdude09:03:27

do you have a .clj-kondo directory? this is a requirement for the cache to be saved

borkdude09:03:36

can you try:

mkdir -p .clj-kondo
clj-kondo --lint $(clojure -Spath) --dependencies

borkdude09:03:40

exactly that

borkdude09:03:49

and still the warning about parse-long?

borkdude09:03:18

on the command line?

borkdude09:03:29

repro welcome

lassemaatta09:03:59

and as I mentioned previously, I looked into the cache and at the clojure.core.transit.json file and found no references to the parse- -functions within

borkdude09:03:18

ok, so the transit file is updated to the newest

borkdude09:03:24

to your own version of clojure

lassemaatta09:03:32

no problem, I'll see if I can build a repro 🙂

lassemaatta09:03:47

oh and thanks for you help debugging this, much appreciated 👍

👍 1
borkdude12:03:28

Ah I see yeah. This is probably a won't fix as there is a list of clojure vars built-in independent of version and it's already bumped to 1.11. Just future-proof your repo using :exclude

borkdude12:03:33

Thanks for repro-ing.

robert-stuttaford11:03:22

got a bit of a headscratcher, where although i am specifying an exclude for unused-namespace, it's not being applied. pictured: the file that's being linted, and the output from kondo, with just that linter's config displayed. you can clearly see the namespace, the file path, the error, and the exclude pattern. both the dep and the cli are on 2022.03.09. what should i do next to diagnose?

robert-stuttaford11:03:18

i've already read all the relevant kondo source and i don't have a hypo for why this may be; it all looks correct!

borkdude11:03:56

Possibly you have :skip-comments true?

robert-stuttaford11:03:30

i definitely have!

borkdude11:03:52

That acts as if the comment doesn't exist. There is now something far better:

{:config-in-comment {...}}

borkdude11:03:02

Just use that instead and disable any linters you don't want to activate in comments

borkdude11:03:21

:redefined-var is already deactivated automatically

robert-stuttaford11:03:21

{:config-in-comment {:linters {:unresolved-namespace {:level :off}}}}

robert-stuttaford11:03:31

yes this is so much better!

borkdude11:03:33

for example yes

robert-stuttaford11:03:40

hm. with that in, i'm still getting the warnings. surely the presence of a comment form is irrelevant here? i wish to control the linting of the top-level ns form

borkdude11:03:18

oh right sorry :)

borkdude11:03:38

what's your config?

robert-stuttaford11:03:11

{:linters {:unused-namespace {:exclude ["^dev.*$"]}}
 :skip-comments true}

robert-stuttaford11:03:21

other than this, we have a bunch of lint-as and a bunch of hooks

borkdude11:03:38

well, clojure.data.csv doesn't match this regex?

robert-stuttaford11:03:18

so the exclude is about the requires themselves, not the ns in which the unused require is?

robert-stuttaford11:03:33

hi i'm robert and i am a professional haha

borkdude11:03:52

hehe, no problem

robert-stuttaford11:03:14

ok so there's no way to do what i thought it did, right

robert-stuttaford11:03:30

i'd basically have to add a rule to each ns in dev/* separately

borkdude11:03:20

aha so in dev* you want to disable a linter, I see

robert-stuttaford11:03:43

cos its full of scripts we use via remote repl, with all the meat in comment forms

robert-stuttaford11:03:01

so we specifically don't care about unused requires in just this source folder

borkdude11:03:17

if you move those requires to comment forms then it would be possible...

borkdude11:03:24

it would not be very hard to support this though

borkdude11:03:50

(comment
  (require '[clojure.data.csv])
)
is the current workaround

robert-stuttaford11:03:40

ok, thanks man, i appreciate your time on this, very helpful

borkdude11:03:31

issue is welcome.

robert-stuttaford11:03:18

i'll add one for the idea of being able to prevent a rule running within (rather than about) a pattern of namespaces

robert-stuttaford11:03:46

it's really just the generalisation of :namespaces here

borkdude11:03:41

yeah, thanks. clj-kondo already generalized :config-in-comment as :config-in-call {clojure.core/comment ...}

borkdude11:03:52

but we need :config-in-namespace too

borkdude11:03:33

Note that for CI purposes you could lint your sources in multiple steps with different configs

robert-stuttaford11:03:00

yeah. what we're trying to do right now is get one config in use in hooks and in CI, and with zero known issues. then we'll try to work to keep issues to zero. so, it's important that our editors, our pre-commits, and our CI all agree on what an error / warning is

robert-stuttaford11:03:29

the other thing is we want our entire classpath to remain compilable so that e.g. lsp or clj-refactor doesn't break when using find-usages or similar

robert-stuttaford11:03:22

thanks @U04V15CAJ! have a great weekend man!

🙏 1
robert-stuttaford11:03:51

once the issue above is resolved, our 161kloc Clojure codebase will be at zero warnings, zero errors 😄

🎉 4
apt21:03:23

Hi folks. Consider the function below:

(defn path
  [url]
  (keyword (re-find (re-matcher #"(?<=\{\{services\.).*?(?=\}\})" url))))
example of usage:
(re-find (re-matcher #"(?<=\{\{services\.).*?(?=\}\})" "{{services.blueprint}}/api/v2/services"))
;; blueprint
Because of keyword, I’m getting this error:
clj-kondo: Expected: symbol or string or keyword, received: seq.
Is this expected?

borkdude21:03:35

That seems like a bug. I will create an issue. Workaround:

(defn path
  [url]
  (keyword #_:clj-kondo/ignore (re-find (re-matcher #"(?<=\{\{services\.).*?(?=\}\})" url))))

borkdude21:03:12

I guess clj-kondo assumed the return value would be something like:

user=> (re-find (re-matcher #"foo" "foo"))
"foo"
user=> (re-find (re-matcher #"(foo)" "foo"))
["foo" "foo"]

apt21:03:55

Thanks! Yeap, makes sense.

Drew Verlee21:03:11

Is there clj-kondo linter config/code that can help mark places where form 2 components aren't properly passing there arguments on. eg

(defn outer 
  [a b c]            ;; <--- parameters
  ;;  ....
  (fn [a b c]        ;; <--- forgetting to repeat them, is a rookie mistake
    [:div
      (str a b c)]))

borkdude21:03:40

This is a reagent component right?

borkdude21:03:09

If reagent had some marker functions then we would be able to write a hook for it

borkdude21:03:24

but right now you cannot see statically that a function is a reagent component

Drew Verlee21:03:52

yea. thats what i was worried about. errr.

borkdude21:03:12

if you write a custom macro that just passes the body to defn, e.g.

(defmacro component [& body]
  `(defn ~@body))
Then you could write a hook for that.
(component [x y]
  (fn [x y] ...))

borkdude21:03:45

But I guess reagent also has with-let for this right?