Fork me on GitHub
#clj-kondo
<
2020-01-10
>
borkdude09:01:06

who was asking me recently about orchestra/defn-spec? I forgot, but I now have a solution for it on master. possibly also for rum macros (cc @robert-stuttaford)

{:lint-as {foo/my-defn clj-kondo.lint-as/def-catch-call}}

borkdude09:01:28

Ah, it was probably@duck

ales.najmann13:01:36

no windows build this time?

borkdude13:01:48

Fixed. thanks

ales.najmann13:01:10

I'll do the bump later today in scoop

robert-stuttaford11:01:41

thanks @borkdude - the catch-all is definitely feeling better!

borkdude11:01:05

@robert-stuttaford Feel free to provide examples of code in the rum issue. That's what's still missing. Without any repros I can't do much

borkdude11:01:26

But if the catch-all is sufficient, that'll do for now

robert-stuttaford11:01:09

i'll write a short summary of the concern so it's there for future improvements

robert-stuttaford11:01:12

i did so, @borkdude https://github.com/borkdude/clj-kondo/issues/536#issuecomment-572997925 - super happy to update this comment if better information comes from elsewhere 🙂

robert-stuttaford11:01:12

i did so, @borkdude https://github.com/borkdude/clj-kondo/issues/536#issuecomment-572997925 - super happy to update this comment if better information comes from elsewhere 🙂

borkdude11:01:25

Responded in the issue.

lauri.lehmijoki12:01:49

Hello, I have the following function:

(defn wrap-internal-error [_handler]
  (fn [_req]
    (try+
     (_handler _req)
     (catch [:type :too-large-pdf] {:keys [request]}
     ...  
and running clj-kondo gives me the following error: my_file.clj:22:44: error: unresolved symbol request. The try+macro is from slingshot:0.12.2. Any suggestions on how to fix or work around the error?

borkdude12:01:46

@lauri.lehmijoki You can ignore unresolved-symbols using a configuration: https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#exclude-unresolved-symbols-from-being-reported so something like:

{:linters {:unresolved-symbol {:exclude [(foo/try+)]}}}

lauri.lehmijoki12:01:39

thank you so much!

lauri.lehmijoki13:01:02

I have the following expression:

(context "/api" []
                       :header-params [{authorization :- (describe s/Str (str "API key. For demo use: [TOKEN " @api-key "]")) nil}]
and running clj-kondo gives me the following error: my_file.clj:117:41: error: unresolved symbol authorization. The context macro is from https://github.com/metosin/compojure-api/blob/85738b802c7f150f4f550ffca91a4782c75f8091/src/compojure/api/core.clj#L58. Any suggestions on how to fix this one?

lauri.lehmijoki13:01:39

My .clj-kondo/config.ednis as follows:

{:linters {:unresolved-symbol {:exclude [(compojure.api.core/context)]}}
 :output {:progress true}}

borkdude13:01:27

This works for me:

(ns foo
  {:clj-kondo/config '{:linters {:unresolved-symbol {:exclude [(compojure.api.core/context)]}}}}
  (:require [compojure.api.core :refer [context]]))


(context "/api" []
         :header-params
         [{authorization :- (describe s/Str (str "API key. For demo use: [TOKEN " @api-key "]")) nil}])

borkdude13:01:12

I mean, no errors in that file

lauri.lehmijoki13:01:46

Thanks, I realised that my namespace actually required compojure.api.sweet/context instead of compojure.api.core/context. With config.edn being

{:linters {:unresolved-symbol {:exclude [(compojure.api.sweet/context)]}}
                           :output {:progress true}}
I see no clj-kondo errors. Thank you for clj-kondo and fast responses here on Slack!

filipematossilva13:01:30

@borkdude I'm starting to think that using https://github.com/borkdude/clj-kondo/pull/696 is better than having a npm package for shadow-cljs projects

borkdude13:01:33

if you want to invoke clj-kondo on the JVM, you can just use it as a dependency. if you want to run the binary, then a package manager like npm or scoop may be better

filipematossilva13:01:01

yeah in the shadow case there is a JVM available

filipematossilva13:01:31

tbh it wasn't clear (to me) at all how to do it with shadow in the same way it was possible to do it with tools.deps and lein

filipematossilva13:01:34

hence adding the pr

filipematossilva14:01:34

does the :exclude-files config entry support wildcards/globs/something to group things by, or does it need each individual file to be listed?

borkdude14:01:06

I had to look it up, but it seems each string in that entry is interpreted as a Java regex: https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#include-and-exclude-files-from-the-output

borkdude14:01:00

on which re-find is called

filipematossilva14:01:47

I've been trying to exclude a folder for the last 10 minutes and haven't had much success....

borkdude14:01:15

what's the folder name and what did you try?

filipematossilva14:01:34

I'm running shadow-cljs run clj-kondo.main --lint src/

filipematossilva14:01:58

I want to exclude everything in src/cljs/devcards/

borkdude14:01:23

you probably need to write: "src//cljs//devcards//"

filipematossilva14:01:23

what's the double slash?

borkdude14:01:51

Nope, this should just work:

user=> (re-find (re-pattern "/src/cljs/devcards") "/src/cljs/devcards/foo.cljs")
"/src/cljs/devcards"

borkdude14:01:15

so only: "/src/cljs/devcards"

borkdude14:01:38

but if the paths are reported relatively, you need to omit the starting slash maybe

filipematossilva14:01:06

I get reports like this

filipematossilva14:01:07

src\cljs\devcards\d_reactive.cljs:87:16: warning: unused binding *x
src\cljs\devcards\d_reactive.cljs:87:25: error: unresolved symbol conn
src\cljs\devcards\d_reactive.cljs:88:16: warning: unused binding *p
src\cljs\devcards\d_reactive.cljs:90:16: warning: unused binding *titles
src\cljs\devcards\d_reactive.cljs:109:27: error: unresolved symbol _
src\cljs\devcards\d_reactive.cljs:135:24: error: unresolved symbol dispatch
src\cljs\devcards\d_reactive.cljs:141:22: error: unresolved symbol ctx
src\cljs\devcards\keys.cljs:11:23: error: unresolved symbol x
src\cljs\devcards\keys.cljs:25:25: error: unresolved symbol app-state
src\cljs\devcards\keys.cljs:37:23: error: unresolved symbol ctx
src\cljs\devcards\keys.cljs:58:24: error: unresolved symbol id

filipematossilva14:01:29

maybe it's because I'm on windows

filipematossilva14:01:34

so the slash never works?

filipematossilva14:01:17

If I just use :output {:exclude-files ["d_reactive.cljs"]} I can do away with the first file

filipematossilva14:01:55

but so far I'm unable to exclude the folder...

borkdude14:01:46

user=> (re-find (re-pattern "src\\\\cljs\\\\devcards\\\\")  "src\\cljs\\devcards\\keys.cljs")
"src\\cljs\\devcards\\"

borkdude14:01:00

so the pattern is what goes into re-pattern

filipematossilva14:01:25

ok I can't do that then, because now the pattern might work locally but it will never work on CI or colleagues machines.... 😕

filipematossilva14:01:35

is there a way to exclude namespaces?

filipematossilva14:01:46

those wouldn't have path slash problems

borkdude14:01:44

no. I think in this case you just want to pass multiple paths:

--lint src\cljs\your-code src\cljs\your-other-code

borkdude14:01:08

the same paths that you have in your production build basically

filipematossilva14:01:19

ok I'll try that

nate_clojurians15:01:02

could you exclude both windows and *nix file separators in the pattern?

borkdude15:01:17

these are just patterns passed to re-pattern and then applied to the paths with re-find. so there's nothing OS or filesystem specific in there

nate_clojurians15:01:10

> ok I can't do that then, because now the pattern might work locally but it will never work on CI or colleagues machines.... 😕

nate_clojurians15:01:42

I assumed that was because it wouldn't match *nix file separators

nate_clojurians15:01:49

since he's on windows

nate_clojurians15:01:00

but since it's just a regex it could match both

borkdude15:01:36

you can just put more patterns in there to also support Windows

borkdude15:01:51

or indeed, use a more flexible regex

filipematossilva16:01:13

that can be done, but it's one of those "surprising in a bad way" things

filipematossilva16:01:38

the double escapes were very surprising

borkdude16:01:48

not if you know clojure

filipematossilva16:01:26

I don't think it's a matter of knowing the language, double escapes exist outside of clojure too

borkdude16:01:42

but I agree it is annoying. on the other hand, I don't know anyone who uses this feature

filipematossilva16:01:08

I wouldn't say it's a very important thing, no

filipematossilva16:01:59

it's just one of those "oh yeah I'm on windows so everything is harder" kind of thing

filipematossilva16:01:47

tbh most of the windows compat problems in the platforms I've come across are just path separator issues hahah

borkdude16:01:13

it took some effort to make the tests work on Windows, mostly due to that

filipematossilva16:01:21

on another project we tried to put a path abstraction on top of both unix and windows paths and then... we ended up with 3 types of paths to make work 😐

nate_clojurians18:01:31

{:exclude-paths [["src" "cljs" "devcards"]]}

nate_clojurians18:01:44

patches welcome, probably 😉

filipematossilva15:01:56

another question please

filipematossilva15:01:08

is there any good way of knowing the name of the rule that's failing?

filipematossilva15:01:17

I'm going through a codebase and need to add some exceptions

filipematossilva15:01:37

some are straightforward enough to guess like unresolved-symbol

borkdude15:01:38

you can figure it out using the EDN or JSON output

borkdude15:01:57

or look at clj-kondo/impl/config.clj

filipematossilva15:01:27

I was looking at that file but some stuff is hard to match

filipematossilva15:01:39

like use the idiom (seq x) rather than (not (empty? x))

filipematossilva15:01:39

I was looking for prefer use seq idiom

borkdude15:01:12

If you have any ideas about how to make this more accessible, e.g. by relating messages and their key in a table or something, PR welcome 🙂

filipematossilva15:01:48

I know tslint shows the rule name somewhere

borkdude15:01:09

maybe that could also be a configuration option... badum-tss

filipematossilva15:01:21

but with tslint the usual pattern is to add an exclude comment so it is slightly different

filipematossilva15:01:33

I don't know if clj-kondo allows exclude comments too

borkdude15:01:03

not at the moment. I'm holding back on that a bit, since I don't want to confront users with all kinds of tooling metadata

filipematossilva15:01:04

I'll open an issue for showing the rule name somewhere for this scenario

filipematossilva16:01:59

if I have a macro that I can't/know how to make work with :lint-as, is there a good way of just ignoring stuff using it?

filipematossilva16:01:28

e.g. clojure.core.match

filipematossilva16:01:52

I can destructure inside of it

filipematossilva16:01:53

(match [action]
                                            [{:test   t
                                              :action a}] (when (t evt)
                                                            (a evt))
                                            [action]      (do
                                                            (.preventDefault evt)
                                                            (action evt))))

filipematossilva16:01:07

but will get unresolved symbol t errors

borkdude16:01:41

1) There is an issue to add support for core.match. 2) You can ignore unresolved symbols inside a call, see config docs

aisamu17:01:20

(This might be unrelated to clj-kondo itself, but I couldn't find a #nix channel or something like that 🙂 - feel free to remove this!) Would it be feasible to make a clj-kondo's nix package that also works on Macs? I got the dreaded clj-kondo/default.nix:45 is not supported on ‘x86_64-darwin’ while trying to add it to a project. Some googling made me realise that my current nix-fu is not even close to sufficient to be able to diagnose/fix this 😬

aisamu17:01:22

(@ tagging you because I can see you got a PR accepted on that file!)

ericdallo17:01:23

I don't know for sure if this is the real problem, but its what looks like

jlle18:01:16

Hi, I made the first version of the nix package. The problem is that graalvm doesn't build currently on Darwin (for nixos). I think there is a PR to fix that, once graalvm works on Darwin you should be able to build clj-kondo on Darwin without any modifications

jlle18:01:20

Btw, for nix related questions, there is a relatively active community here: https://discourse.nixos.org/

borkdude17:01:58

@aisamu It would probably best to talk to the package maintainers

aisamu17:01:46

Yup, but I'm unsure where nix package maintainers hang out 🙈. I know that at least one of them is here, so I thought it'd be worth a shot. Sorry for the noise!

aisamu17:01:43

(and thanks a lot for clj-kondo, btw!)

borkdude17:01:07

@aisamu This issue was originally created for the nixOS package: https://github.com/borkdude/clj-kondo/issues/414 you can ping the author of that issue there as well

aisamu17:01:03

Ah, that's indeed helpful!

filipematossilva17:01:11

is it possible to exclude unresolved namespaces?

filipematossilva17:01:21

adding an exclude to the linter config doesn't seem to do it

filipematossilva17:01:13

but I'm not having luck adding the ns itself to the unresolved-symbol list

filipematossilva17:01:45

I can, however, add the macro that uses the unresolved-namespace to the unresolved-symbol exclude list though

borkdude18:01:11

which macro is that? can you give an example?

filipematossilva19:01:50

it's meant to take a namespace

borkdude19:01:50

yeah, clj-kondo assumes you forgot a require there, which is in most cases helpful, but maybe in a macro like this isn't. it looks at the exclusions in :unresolved-symbol though, as I suspected most macros that had this problem already needed such a rule there and it would be annoying to repeat rules for the same macro in two places

borkdude19:01:36

another option is to just turn off that linting rule, or maybe it works for namespace local config, but I haven't tested that