Fork me on GitHub
#clj-kondo
<
2021-09-06
>
Pratik05:09:05

Hi, I was using some of the macros of failjure library - https://github.com/adambard/failjure There are ~13 macros, so what would be the best way to get rid of unresolved-symbol linting warnings? I have tried something like this

{:linters
  {:unresolved-symbol
    {:exclude [(failjure.core)]}}}
but it’s not working(it’s taking clojure-lsp initialization to load forever)

borkdude07:09:56

This config isn't valid, don't wrap this in parens as the symbol isn't fully qualified

Pratik07:09:53

ah, okay, then do I need to mention all the 13 macros here?

borkdude07:09:02

There may be a better solution. Can you give me an example of such a macro?

Pratik07:09:52

(defmacro ok->
  "Like some->, but with ok? instead of some?
   (i.e., short-circuits when it encounters a failure)"
  ([start & forms]
   `(if-let-failed? [v# ~start]
      v#
      (attempt-> v# [email protected]))))
this is one of them

borkdude07:09:56

You can use {:lint-as {foo.bar/ok-> clojure.core/->}} here

👍 2
borkdude07:09:07

which gives you better linting than suppressing errors

borkdude07:09:36

and if you have it all working, you can donate the config to the library itself or to clj-kondo/config so others don't have to re-invent the wheel

Pratik07:09:17

sure, I will try to add it for all the macros

Pratik07:09:21

failjure.core/ok->             clojure.core/->
failjure.core/ok->>            clojure.core/->>
failjure.core/try-all          clojure.core/let
failjure.core/try*             clojure.core/fn
failjure.core/when-failed      clojure.core/fn
failjure.core/if-failed        clojure.core/fn
failjure.core/attempt-all      clojure.core/let
failjure.core/if-let-ok?       clojure.core/let
failjure.core/if-let-failed?   clojure.core/let
failjure.core/when-let-failed? clojure.core/let
failjure.core/when-let-ok?     clojure.core/let
these mostly are the configs, I’ll take a look on the docs you shared later today, to add it in the configs or the library itself

borkdude08:09:03

isn't it better to lint if-let* as clojure.core/if-let?

Pratik08:09:43

yes, I will do that(even for when-let*s) also this try* macro was giving error Function arguments should be wrapped in vector.

(defmacro try* [& body]
  `(try-fn (fn [] [email protected])))
what could be the possible linting option for that?

borkdude08:09:26

clojure.core/try?

👍 2
borkdude08:09:59

I would lint *-when-let as clojure.core/when-let, not if-let

ericdallo16:09:17

@pratikgandhi1997 in your PR, this way will only work for the failjure repo, not for libs using it

borkdude16:09:00

But this is a good start, thanks @pratikgandhi1997

☝️ 2
Pratik16:09:16

oh, I thought we need to do that only if we are using hooks to do some special thing, let me take a look

borkdude16:09:49

clj-kondo doesn't import config from the libraries own .clj-kondo directory since that's not on the classpath typically

borkdude16:09:00

and also not because it can contain config for libraries other than its own sources

ericdallo16:09:02

yeah, your case you don't need any clojure code as you only need the lint-as, but even so you need to add it to the resources

borkdude16:09:38

but you can refer to the exported config from the .clj-kondo dir so you can use it while developing the lib

Pratik16:09:40

okay, I am a little unsure about what to add in the place of com.fulcrologic/fulcro Should it be adambard/failjure in this case? How do we derive it?

ericdallo16:09:19

yes, group-id/artifact-id, just something to not conflict with other configs in classpath from other libs

2
Pratik16:09:48

Updated the PR with that

borkdude16:09:46

You need to remove the intermediate clj-kondo in the directory structure

borkdude16:09:58

since fulcro has a different project layout

ericdallo16:09:05

That should work, just not sure if adding to src is a good idea, maybe adding to the resources folder?

borkdude16:09:14

it has src/java, src/clj, src/clj-kondo

borkdude16:09:23

but failjure just has src

borkdude16:09:36

yeah. I think resources is better

👍 2
ericdallo16:09:06

it would be /resources/clj-kondo.exports/...

ericdallo16:09:29

since resources folder is alredy in classpath as lein adds that folder by default

👍 2
Pratik16:09:27

Updated the PR, please recheck, I have assumed that we don’t need to give a relative path in the .clj-kondo/config.edn as it’s already on classpath

ericdallo16:09:24

Exactly, looks good to me :)

👍 2
pez07:09:31

Why do I get Found an opening ( with no matching ) here?

(foo^ :bar)
(It’s not something I need to do, just some test data I have, and I got curious about the problem report.)

pez07:09:46

Clojure is complaining in similar ways. Though it is giving me some more context by first warning: Metadata must be Symbol,Keyword,String or Map.

borkdude08:09:27

This is coming from tools reader, I think.

$ plk
ClojureScript 1.10.597
cljs.user=> (foo^ :bar)
Syntax error reading source at (<cljs repl>:1).
Unmatched delimiter ).

borkdude08:09:50

it's because the metadata character expected another token after :bar

pez08:09:33

Thanks. I should probably fix this in Calva’s tokenizer, but as long as clj-kondo protects the user it is maybe not worth it.

Benjamin13:09:39

I realized my defroutes warning came from clj-joker 😅 is there any reason to use both?

borkdude13:09:03

I'll let others speak to that

mynomoto14:09:04

I stopped using other linters long ago, clj-kondo is really a joy to use and both the most complete out of the box and most used by the community.

dharrigan14:09:22

I too only use clj-kondo thesedays.

6
dharrigan14:09:39

Of course, this channel is heavily biased 😉

Pratik17:09:32

I am using https://github.com/seancorfield/honeysql library in my project and when I use it with clj-kondo I am getting few unresolved-var errors, looks like some of those functions use defalias, what would be the best way to suppress/fix them?

seancorfield17:09:13

@pratikgandhi1997 Sounds like you're using HoneySQL 1.0? I'd strongly recommend using 2.0 for any new code.

Pratik17:09:28

looks like we are using even older "0.9.1" 😐

Pratik17:09:35

Is there any doc that explains the compatibility issues between these versions?

borkdude17:09:55

anyway, defalias linting can be accomplished like this:

{:lint-as {honeysql.util/defalias clojure.core/def}}
if you're not ready to upgrade

👍 2
borkdude17:09:21

same for honeysql.helpers/defhelper clojure.core/def

borkdude17:09:31

which we have in our app at work as well still

borkdude17:09:42

I still have to upgrade the old code. they work side by side