Fork me on GitHub
#clj-kondo
<
2019-10-27
>
p-himik11:10:52

How do you think - is it reasonable to check that any particular namespace has consistent aliases throughout the project? E.g. one file uses (:require [a.b.c :as c]), another one uses [a.b.c :as x], the third one uses something else.

borkdude11:10:40

@p-himik @dominicm is using the analysis export for this I think

borkdude11:10:46

maybe he could give you his script

dominicm11:10:55

I didn't write it, but the data is there now. I got a bit hung up trying to figure out a happy integration story.

dominicm11:10:46

I've had discussions internally, and some people are really into "context" of reusing namespace aliases. I don't think this can be in kondo because there's no consensus.

borkdude11:10:02

It can be there as an "optional" linter that's turned off by default, just like the "missing docstring" one

borkdude11:10:53

but it can already be done as a separate script on top of the analysis export, so it doesn't have very high priority

borkdude11:10:07

unless people start bugging me about it more

dominicm11:10:06

I agree :).

p-himik11:10:34

Got it. Thanks for the discussion!

mynomoto20:10:19

Is there some way to whitelist :refer :all for some namespaces?

mynomoto20:10:49

Ok, thanks. I'm using a strange library that sort of encourages/needs :refer :all and I don't want to turn it off wholesale. But I'm starting to think that turning it of is the best option atm.

p-himik20:10:29

Is it specter by any chance?

borkdude20:10:43

I'd be curious why/when it would be encouraged. it doesn't work at all in CLJS for example

mynomoto20:10:16

@p-himik No, specter encourages but doesn't require that so I use it with a alias usually.

p-himik20:10:28

Yep, that's why after starting using clj-kondo, I had no remorse replacing :use with :require :as. 🙂

p-himik20:10:48

Huh. Why would something need :refer :all?

mynomoto20:10:24

@U04V15CAJ it's http://github.com/viasat/salt and it works this way because it will be transpiled to tla+ and it wants to keep the semantic close to that language.

borkdude20:10:36

you can explicitly refer the vars you need with :refer [foo bar]

mynomoto20:10:37

My attempts of transpilation failed after I changed the require.

borkdude20:10:28

maybe you should raise an issue with that repo to support aliases?

mynomoto20:10:45

That would be too different from the way tla+ works I suppose. Being near the output is an objective.

mynomoto20:10:31

But you are right, I can refer specific symbols and it worked. I think I tried to use alias before and that doesn't work.

dave16:10:19

in general, i avoid using :refer :all, but i do prefer it in rare cases where a library provides a DSL

dave16:10:47

when libraries like salt and alda-clj give you a DSL, using :refer :all lets you pretend that all the public vars in a namespace are sort of a part of the clojure language. like you're not writing clojure anymore, you're writing clojure + alda-clj, or whatever

dave16:10:25

it's totally not a good coding practice, in general

dave16:10:44

but i think there are rare use cases

borkdude16:10:25

thanks @U0AHJUHJN, so maybe for these rare cases a rule in clj-kondo would be good then

borkdude16:10:02

unless the linter already complains about a lot of other stuff as well, that it doesn't know about

dave16:10:07

i think it would be useful to have the ability to whitelist namespaces to make them OK to :refer :all

borkdude16:10:48

@U0AHJUHJN what about :refer [x y z]?

dave16:10:51

oh, is the issue with :refer in general?

dave16:10:17

i'd have to think about that one a bit

dave16:10:46

i don't think :refer [about twenty-five different vars] would help in cases like alda-clj

dave16:10:53

there's a whole standard library of sorts

dave16:10:29

when i use alda-clj, i'm putting myself in a mindset where i have a whole language available to me, and it's cumbersome to either have to namespace all the vars, or worry about which ones i've explicitly referred in

dave16:10:40

so :refer :all makes a lot of sense to me in that context

dave16:10:47

i think another example is clojure.test

borkdude16:10:56

right, and that's probably also the only namespace that you're going to use?

dave16:10:01

although i typically do explicit refers there, like :refer [deftest testing is are]

borkdude16:10:13

yes, typically that's true for me as well

borkdude16:10:46

if you can provide me with some typical alda-clj code, I'd be happy to take a look in an issue for it

borkdude16:10:56

right, makes sense!

borkdude16:10:01

I'll make an issue for this

dave16:10:32

awesome, thanks a lot!

borkdude16:10:09

^ @U05094X3J

borkdude16:10:27

note: the unresolved symbols for the referred-all namespace go away once clj-kondo has linted the lib namespace and there is a .clj-kondo directory in the project

dave16:10:01

proposal looks great - well captured!

borkdude16:10:04

@U0AHJUHJN if you feel like it, you're welcome to make PR. if you don't feel like it, that's ok too 🙂

mynomoto03:10:20

That proposal looks great.

mynomoto20:10:13

Do regex work to configure unresolved-symbols?

mynomoto20:10:13

Do regex work to configure unresolved-symbols?

borkdude20:10:16

I don't think that works (I had to look it up myself).

mynomoto20:10:09

Yeah, I saw that. I was just wondering if it could be undocumented 😉 Do you think that would be a useful addition?

borkdude20:10:34

I haven't had this need myself, could you give an example where it makes sense?

mynomoto03:10:43

Well, the same library http://github.com/viasat/salt has a thing where when you create a variable x it creates another x' that is the next step for x. I want to whitelist #".*'$" in this case.

mynomoto03:10:18

But I'm almost giving up linting this project. It's not really clojure.

borkdude08:10:41

If it's just to support this library I would say it's not a strong enough case yet. But you can blacklist certain files in your project so linting is turned off there

borkdude08:10:45

(check the config docs)

mynomoto14:10:44

Ok, thanks!