Fork me on GitHub
#clj-kondo
<
2022-01-12
>
borkdude12:01:21

The latest clojure-extras plugin for IntelliJ which integrates clj-kondo, has a lot better performance! https://plugins.jetbrains.com/plugin/18108-clojure-extras/ Thank you @brcosta!

❤️ 6
borkdude12:01:57

@brcosta Perhaps you can also rename the github repo to clojure-extras and also link to the marketplace from there.

yes 1
borkdude12:01:03

I think the locations of the yellow stuff can be fixed by the plugin, perhaps. I did a similar thing in clj-kondo.lsp for Calva. https://github.com/clj-kondo/clj-kondo.lsp/blob/53b59828bfc6a6dab8c67ca4e1442093fec4b5c8/server/src/clj_kondo/lsp_server/impl/server.clj#L76-L88

brcosta12:01:59

I’ll try this approach later today 🙂

NoahTheDuke15:01:43

in the library semantic-csv, there are a bunch of casting functions (`->int` converts a value to an int if possible), which are defined using an in-house function called clone-var. The block of code that defines them is wrapped in a reader conditional and I’m not sure exactly how to make these functions lint as functions: https://github.com/metasoarous/semantic-csv/blob/10f436bacf2ca9ed2f22ffbbecea6467ba20c2e4/src/semantic_csv/core.cljc#L321-L335

NoahTheDuke15:01:22

any ideas how to make clj-kondo recognize or at least stop marking them as “unresolved var”?

borkdude16:01:06

@nbtheduke :lint-as {foo.bar.impl/clone-var clojure.core/declare}

borkdude16:01:40

ehm no, sorry

borkdude16:01:35

you can add this namespace to {:linters {:unresolved-var {:exclude [semantic-csv.core]}}} or make a proper macro for it in .clj-kondo

borkdude16:01:18

The macro would look something like:

(defmacro clone-var [sym] (def ~(symbol (name sym)) ~sym)))

borkdude16:01:13

and then add to :macroexpand {foo.bar.impl/clone-var my_hooks/clone-var}

borkdude16:01:23

and the code would then live in .clj-kondo/my_hooks.clj or so

NoahTheDuke16:01:56

cool, i’ll give that a whirl! thank you for the help

Alex Miller (Clojure team)16:01:54

I have the same problem as https://github.com/clj-kondo/clj-kondo/issues/272, which is closed. any advice? Repro:

git clone 
cd tools.deps.alpha
clj -M:lint

src/main/clojure/clojure/tools/deps/alpha/specs.clj:122:9: error: Unresolved symbol: clojure.tools.deps.alpha/resolve-deps
src/main/clojure/clojure/tools/deps/alpha/specs.clj:126:9: error: Unresolved symbol: clojure.tools.deps.alpha/make-classpath-map
src/main/clojure/clojure/tools/deps/alpha/specs.clj:130:9: error: Unresolved symbol: clojure.tools.deps.alpha/make-classpath

borkdude16:01:40

Let me take a look locally. Is this on tda master?

borkdude16:01:24

The error goes away when I add [clojure.tools.deps.alpha] to the namespace form. I think clj-kondo expects the fdef name to be related to one of your loaded namespaces.

borkdude16:01:32

(ns clojure.tools.deps.alpha.specs
  (:require [clojure.spec.alpha :as s]
            [clojure.tools.deps.alpha]))

Alex Miller (Clojure team)16:01:43

but that's not necessary

Alex Miller (Clojure team)16:01:57

it's just a symbol going in the registry

borkdude16:01:18

hm yeah, it can be any fully qualified symbol. I'll fix that then

borkdude16:01:15

This is the config which makes those things go away for now:

{:skip-args [clojure.core/comment]
 :linters
 {:unused-binding {:level :off}
  :unresolved-symbol [(clojure.spec.alpha/fdef)]}}

borkdude16:01:23

you can also apply this config locally in the namespace

borkdude16:01:51

or before the form even:

#_:clj-kondo/ignore 

borkdude16:01:35

:skip-args [clojure.core/comment] can be written as :skip-comments true as well

borkdude16:01:56

you can also apply a separate config for comment forms:

:config-in-comment {...}

Alex Miller (Clojure team)16:01:47

when I added that :unresolved-symbol line above, I suddenly got 100s of warnings/errors

Alex Miller (Clojure team)16:01:23

seemed weird that was a vector and not a key in a map?

borkdude16:01:22

Ah sorry, my bad.

{:skip-comments true
 :linters
 {:unused-binding {:level :off}
  :unresolved-symbol {:exclude [(clojure.spec.alpha/fdef)]}}}

borkdude16:01:33

I still have to write a linter for clj-kondo's own config file :)

borkdude16:01:38

the (..) means, within a call to. without the parens it means: ignore this symbol itself globally. I kind of regret this but I stole this 2.5 years ago based on what joker was doing at the time. sorry about that ;)

borkdude16:01:19

you can also say: :exclude [(foo.bar/baz [x y z])] which ignores only the symbols x y z within calls to foo.bar/baz

borkdude16:01:51

which some macros which introduce arbitrary symbols can use

borkdude16:01:35

I checked the implementation of the fdef analysis and it was explicitly written as: if the namespace is unresolved, then the symbol is reported as unresolved. Since you can easily make typos and most people will load the namespace when they write specs.

borkdude16:01:53

but I guess this should be an opt-in warning and not an error

Alex Miller (Clojure team)16:01:59

I tried that config and it didn't suppress the errors

borkdude16:01:19

which config did you try?

Alex Miller (Clojure team)16:01:31

your last code block above

borkdude16:01:45

this one?

{:skip-comments true
 :linters
 {:unused-binding {:level :off}
  :unresolved-symbol {:exclude [(clojure.spec.alpha/fdef)]}}}

borkdude16:01:12

it does work over here. are you sure you have that exact config with :exclude ?

borkdude16:01:22

I forgot to add that before

Alex Miller (Clojure team)16:01:13

% cat .clj-kondo/config.edn
{:skip-comments true
 :linters
 {:unused-binding {:level :off}
  :unresolved-symbol {:exclude [(clojure.spec.alpha/fdef)]}}}
% clj -M:lint
src/main/clojure/clojure/tools/deps/alpha/specs.clj:122:9: error: Unresolved symbol: clojure.tools.deps.alpha/resolve-deps
src/main/clojure/clojure/tools/deps/alpha/specs.clj:126:9: error: Unresolved symbol: clojure.tools.deps.alpha/make-classpath-map
src/main/clojure/clojure/tools/deps/alpha/specs.clj:130:9: error: Unresolved symbol: clojure.tools.deps.alpha/make-classpath
linting took 1088ms, errors: 3, warnings: 0

borkdude16:01:51

ah my bad again, I get the same. argh, yeah, it uses a "custom" way to handle that so configuring won't work.

borkdude16:01:54

#_:clj-kondo/ignore ;; see kondo issue #1532
(s/fdef clojure.tools.deps.alpha/resolve-deps
  :args (s/cat :deps ::deps-map :options ::resolve-args)
  :ret ::lib-map)

borkdude16:01:12

that will do it, or load the ns, until I fix the issue which I'm on right now.

borkdude18:01:37

1532 is fixed on master

Alex Miller (Clojure team)16:01:31

I tried adding a suppression in the config per that issue, but it did not suppress

ingesol18:01:02

Seeing some strange behaviour using Cursive + clojure extras + clj-kondo. A number of vars are reported as unresolved, while they are clearly not. Only inside cursive, not in clj-kondo CLI

borkdude18:01:28

@brcosta Are you sending the :filename ... so clj-kondo can see that this is .cljs code?

borkdude18:01:56

That is likely the issue

ingesol18:01:03

that would make sense, I think I also saw this on some reagent vars

ingesol18:01:11

reagent is cljs source, IIRC

borkdude19:01:29

could you make an issue at https://github.com/brcosta/clj-stuff-plugin so we don't forget?

👍 1