Fork me on GitHub
#clj-kondo
<
2022-02-24
>
Drew Verlee02:02:51

would there be a way to use clj-kondo to read clojure and sort of expand regular clojure the same way you do macro expand? Like (defn foo [x] x) (defn bar [x] (foo x)) -> expand "(foo x)" -> (defn bar [x] x)

delaguardo11:02:47

cool, idea. something like "term rewrite" but in clojure such analyser have to take in account that foo is not static value, it is a reference that can be redefined in runtime

Stefan15:02:26

Hi all! I just had a situation that caught me off guard. I had a test that should fail, but didn’t when running the tests from the command line (poly test in my case). The reason turned out to be that the namespace name of the test file did not match the file name. I was surprised that clj-kondo didn’t catch this. Do you think this would be a good linter to add to clj-kondo? I.e.: check whether the namespace name matches the filename + path of the file?

borkdude15:02:03

@stefan.van.den.oord Absolutely and there is already an issue for it. It might be a relatively easy one if you want to hack on it. https://github.com/clj-kondo/clj-kondo/issues/1240

Stefan15:02:14

Cool, I will definitely keep that in mind. I think I might pick that up quite soon.

Stefan16:02:16

@U04V15CAJ Could you jump-start me by telling roughly where I should add my code?

borkdude16:02:24

Somewhere here: https://github.com/clj-kondo/clj-kondo/blob/4495e9387733e891ee735d745fd0bcf92185d59c/src/clj_kondo/impl/analyzer/namespace.clj#L358 In the ctx is a key called :file that you can use to compare to the name of the namespace

Stefan16:02:38

For the unit test I think it would be easiest to create a couple of test resource files that I then read in in the unit test, is that ok with you? (Just checking because this way of testing by reading actual files doesn’t seem to be used yet.)

borkdude16:02:11

yes, there is a directory called "corpus" for this

Stefan16:02:43

A right I just found that, sorry for asking too quickly.

borkdude21:02:32

@stefan.van.den.oord you can disable the linter for all of the other tests in test_utils

Stefan21:02:03

Yeah thanks, that’s indeed the strategy that I’m working on 🙂 I didn’t know about the base config there, that’s going to make it a lot easier, thanks! 🙂

Stefan21:02:27

How should it behave (in real-life) when there are multiple ns-forms in a file?

Stefan21:02:23

Currently it will report the ones that don’t match the file name. I think that’s desired behaviour, do you agree @U04V15CAJ?

borkdude21:02:03

Perhaps just take the first one?

Stefan21:02:48

That does make the linter more complex of course. I’m not sure what the use case would be for this. You can always silence the warnings with comments in the file…

Stefan21:02:29

I’m calling it the day. 🛏️ There’s a few failing tests remaining that I have to look into, I will followup soon.

Stefan21:02:34

Re multiple ns forms: the question is I think: in cases where this occurs in real life, is it by accident or on purpose most of the time? I have never felt the need to have multiple ns forms in one file.

borkdude21:02:55

Ok, then why the question? Did this come up in the tests?

Stefan21:02:58

I saw it in corpus/use.clj.

Stefan21:02:21

Not after disabling my linter in base test setup of course, but that’s why it made me think.

borkdude21:02:54

yeah, ok. I think it's ok to just keep it simple and lint it always

borkdude21:02:59

we can change it when we need to.

👍 1
Stefan22:02:07

Now locally all tests are passing, but not in CI. Not sure what’s going on. But that will have to wait till tomorrow. Good night!

borkdude22:02:54

Good night!

borkdude20:02:14

@grzegorz.rynkowski

(->> '("Mike" "Tom" "Jerry")
     (map (fn [x] (count x)))
     (cond->> true (map str)))
gives the same warning to me, so your lint-as seems to be working :)

greg20:02:50

Oh, right, cond->> might not be a good linter for ?>>. Nope, I did not 😬

borkdude20:02:06

The example doesn't run, but throws an exception

greg20:02:17

sorry @U04V15CAJ, I was too eager and added a unnecessary lint-as statements for ?>>. There is no issue. Sorry.

borkdude20:02:35

Have you tried executing that example?

danielcompton20:02:31

For exported config (in our case marick/midge/config.edn) is it expected that we would add this to source control or gitignore it and let each user's computer generate it for them?

borkdude20:02:32

@danielcompton I prefer to check it into source control so everyone has the same consistent linting results

👍 2
borkdude20:02:52

also when you don't scan your classpath in a clean checkout