Fork me on GitHub
#clj-kondo
<
2021-07-30
>
Jim Newton08:07:05

Hi @borkdude, big bravo for your recent work.

đź‘Ť 2
Jim Newton08:07:22

seems to work well.

Jim Newton09:07:19

one thing that I noticed which works well, but I was expecting to fail is that (do x) warns that the do is redundant. However if a macro expands to something containing a singleton do this warning is thankfully suppressed. Is that an accident or by design?

Jim Newton09:07:29

how does it know?

borkdude09:07:55

the generated nodes are marked as "generated" and the redundant do linter doesn't warn if the node was generated

2
Jim Newton09:07:15

so if the macro does something like

`(foo (do 41) ~@user-code)
and user-code contains a (do 42) does it know to flag (do 42) but not (do 41) ?

borkdude09:07:15

with :macroexpand it doesn't but with :analyze-call it does, because you can re-use the incoming node

borkdude09:07:36

:analyze-call is more powerful, :macroexpand is just for "ease"

Jim Newton09:07:48

I haven't read the HOW-TO yet.

Jim Newton09:07:08

this sort of limitation could be worth noting

borkdude09:07:40

Yes, I think we have to emphasize that :macroexpand comes with these trade-offs.

borkdude09:07:03

but it may be good for people like yourself who are not yet familiar with :analyze-hook and want to get started more quickly

borkdude09:07:43

note that :macroexpand will still provide linter warnings for the majority of linters

borkdude09:07:51

just not for some of these "redundant" ones

Jim Newton09:07:25

yes it seems like a powerful feature, and easy to use.

Jim Newton09:07:03

can you give me the link to the HOWTO again please?

Jim Newton09:07:52

I'd like to add some things to this doc. What should I do?

borkdude09:07:09

(pull request)

borkdude09:07:51

if you're not familiar with this, there are some docs on the internet explaining how this works. e.g.: https://opensource.com/article/19/7/create-pull-request-github

Jim Newton09:07:58

I have a patch for backtick/template which makes it compatible with clj-kondo Is that something we should include in the clj-kondo repo, or should I try to convince the backtick folks to take it?

borkdude09:07:08

I think it depends. What is the patch and which problem does it solve?

Jim Newton09:07:22

it provides a macro expansion for cli-kondo to use. you can't simply copy the default backtick.clj file into the .clj-kondo directory because the interpreter can't underhand direct references to java class names, and a few more issues. I replace (instance? x Boolean) with (boolean? x) and several similar things. These changes theoretically could but sent upstream to the backtick maintainers. However, I had to change one of the throw exception calls in a way which would probably break the code, but doesn't break it as far as clj-kondo is concerned.

Jim Newton10:07:15

seems backtick was last touched 6 years ago.

borkdude10:07:35

the boolean? predicate was introduced in clojure 1.9

borkdude10:07:07

modifying that library in that way would make it incompatible with clojure 1.8 for example, but that's a trade-off for the lib maintainer to make

borkdude12:07:09

@jimka.issy But you could try to provide a "config" with a macro that that library will export

borkdude12:07:52

And then users of that library will receive the config automatically, e.g. if they use clojure-lsp

Jim Newton12:07:00

could that be made invisible to the users of backtick? I.e. somewhere in the backtick download would be a .clj-kondo configuration which the system would implicitly know about? Or would each user need to modify his .clj-kondo directory to include copies of the files, or entries in the deps.edn file?

borkdude12:07:53

@jimka.issy if the library includes the config in its resources under clj-kondo.exports then it works automatically when you lint the classpath

Jim Newton12:07:54

or would it be something that I (Jim) would provide independent and in parallel to backtick?

borkdude12:07:11

you could also do the latter

borkdude12:07:37

in the latter case, you could also contribute it to https://github.com/clj-kondo/config

borkdude12:07:56

and if users then include that library on their classpath, or install the config for backtick manually it will also work

Jim Newton12:07:56

ah, so if the maintainers of that library are amenable, I could submit a PR to backtick including this configuration?

borkdude12:07:13

you could also make your own clj-kondo config project and include that on your own classpath

borkdude12:07:18

if you want to keep it completely private

borkdude12:07:52

but it's better if people improved one single config over time, probably in the repo of the original library

Jim Newton12:07:10

again, would I hard code a particular sha1 into the deps.edn file of that library? wouldn't that conflict with the sha found elsewhere?

borkdude12:07:02

what do you mean by that library in this context?

Jim Newton12:07:21

according to https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md#exporting-and-importing-configuration I need to create a deps.edn file at the top level directory of the backtick library with the following content:

{:deps {clj-kondo/config {:git/url ""
                          :sha "e2e156c53c6c228fee7242629b41013f3e55051d"}}}
right?

Jim Newton12:07:45

ahhhh. good thing I asked.

borkdude12:07:59

this is when you would include the clj-kondo/config library which would then contain the config for the backtick library

borkdude12:07:27

but if you would contribute the config to the backtick library itself, you wouldn't need the clj-kondo/config library

borkdude12:07:03

the config is extracted from whatever dependency provides it

borkdude12:07:09

it could be your own custom dependency

borkdude12:07:14

it doesn't matter

borkdude12:07:31

as long as the path starts with clj-kondo.exports inside your dependency

borkdude12:07:55

(a better path would maybe have been META-INF/clj-kondo.exports but oh well)

borkdude12:07:02

during the linting of dependencies, clj-kondo checks for this and then copies these files into your local config dir

borkdude12:07:27

(if you call clj-kondo with --copy-configs, which clojure-lsp does automatically)

borkdude12:07:52

so clj-kondo --copy-configs --lint $(clojure -Spath) should copy configs from all dependencies that provide them

Jim Newton12:07:48

ahhh. and I need config.edn inside clj-kondo.exports which contains

{:hooks {
         ;; {:macroexpand {app.bar/baz hook.bar/baz}}}
         :macroexpand {backtick/template     backtick/template}}}

Jim Newton12:07:14

along with the backtick.clj file which contains the (defmacro ...)

borkdude12:07:39

inside clj-kondo.exports you will need to create a uniquely named dir as well

Jim Newton12:07:45

simple, but I'm not sure how I can test it before submitting the PR

borkdude12:07:54

clj-kondo.exports/backtick/backtick/config.edn

borkdude12:07:46

(the first backtick is an org name, the second the lib name)

borkdude12:07:00

@jimka.issy You can test this by making a local project using :local/root

borkdude12:07:10

and then doing what you described in that directory

borkdude12:07:47

deps.edn:

{:deps {backtick/backtick {:local/root "/Users/jim/dev/backtick"}}}

borkdude12:07:11

(EDITED the above example)

borkdude12:07:13

and then calling clj-kondo --copy-configs --lint $(clojure -Spath) should dump the config from /Users/jim/dev/backtick/resources/clj-kondo.exports/backtick/backtick into your local .clj-kondo dir

borkdude12:07:52

Note that the backtick library should add a resources directory to accomodate this config

borkdude12:07:11

also you will need to add a deps.edn with :paths ["src" "resources"] in backtick or produce a pom.xml from the lein project with lein pom to make :local/root understand it

borkdude13:07:45

(it's quite the ceremony)

🤪 2
Jim Newton13:07:08

bash-3.2$ clojure -Spath Error building classpath. Manifest type not detected when finding deps for backtick/backtick in coordinate #:local{:root "/Users/jnewton/Repos/backtick"} bash-3.2$

Jim Newton13:07:41

after added deps.edn to backtick, I have the following:

bash-3.2$ clojure -Spath
src:/Users/jnewton/Repos/backtick/src:/Users/jnewton/Repos/backtick/resources:/Users/jnewton/.m2/repository/org/clojure/clojure/1.10.3/clojure-1.10.3.jar:/Users/jnewton/.m2/repository/org/clojure/core.specs.alpha/0.2.56/core.specs.alpha-0.2.56.jar:/Users/jnewton/.m2/repository/org/clojure/spec.alpha/0.2.194/spec.alpha-0.2.194.jar

Jim Newton13:07:13

what do you mean by: Note that the backtick library should add a `resources` directory to accomodate this config

Jim Newton13:07:25

do I need to create a resources directory in backtick ?

borkdude13:07:37

you should put the config inside the resources dir yes

borkdude13:07:48

/Users/jim/dev/backtick/resources/clj-kondo.exports/backtick/backtick/config.edn

borkdude13:07:04

Make it look like that

✔️ 2
Jim Newton13:07:27

I see the following unexpected but understandable message: Imported config to .clj-kondo/backtick/backtick. To activate, add "backtick/backtick" to :config-paths in .clj-kondo/config.edn.

borkdude13:07:33

yes, that is expected. In your local config.edn you should then have :config-dirs ["backtick/backtick"]

borkdude13:07:35

to activate it

Jim Newton13:07:38

Here is my current config.edn

{:hooks {
         ;; {:macroexpand {app.bar/baz hook.bar/baz}}}
         :macroexpand {clojure-rte.util/print-vals     clojure-rte.util/print-vals,
                       clojure-rte.util/defn-memoized  clojure-rte.util/defn-memoized,
                       clojure-rte.util/defmethod-memoized  clojure-rte.util/defmethod-memoized,
                       clojure-rte.util/exists  clojure-rte.util/exists,
                       clojure-rte.util/setof  clojure-rte.util/setof,
                       clojure-rte.util/forall  clojure-rte.util/forall,
                       clojure-rte.util/forall-pairs  clojure-rte.util/forall-pairs,
                       clojure-rte.util/exists-pair  clojure-rte.util/exists-pair,
                       clojure-rte.util/casep clojure-rte.util/casep,
                       clojure-rte.cl-compat/cl-cond clojure-rte.cl-compat/cl-cond,
                       clojure-rte.cl-compat/with-escape clojure-rte.cl-compat/with-escape
                       clojure-rte.rte-case/rte-case clojure-rte.rte-case/rte-case
                       clojure-rte.rte-case/destructuring-case clojure-rte.rte-case/destructuring-case
                       clojure-rte.rte-case/destructuring-fn clojure-rte.rte-case/destructuring-fn
                       clojure-rte.rte-case/-destructuring-fn-many clojure-rte.rte-case/-destructuring-fn-many
                       clojure-rte.rte-case/dsfn clojure-rte.rte-case/dsfn
                       clojure-rte.rte-case/dscase clojure-rte.rte-case/dscase
                       clojure-rte.typecase/typecase clojure-rte.typecase/typecase
                       ;; backtick/template backtick/template
                       }}}
what do I need to add where?

Jim Newton13:07:16

added :config-dirs parallel with :hooks ?

borkdude13:07:21

yes, top-level

Jim Newton13:07:34

hmmm here is my config.edn now

{:config-dirs ["backtick/backtick"]
 :hooks {
         ;; {:macroexpand {app.bar/baz hook.bar/baz}}}
         :macroexpand {clojure-rte.util/print-vals     clojure-rte.util/print-vals,
                       clojure-rte.util/defn-memoized  clojure-rte.util/defn-memoized,
                       clojure-rte.util/defmethod-memoized  clojure-rte.util/defmethod-memoized,
                       clojure-rte.util/exists  clojure-rte.util/exists,
                       clojure-rte.util/setof  clojure-rte.util/setof,
                       clojure-rte.util/forall  clojure-rte.util/forall,
                       clojure-rte.util/forall-pairs  clojure-rte.util/forall-pairs,
                       clojure-rte.util/exists-pair  clojure-rte.util/exists-pair,
                       clojure-rte.util/casep clojure-rte.util/casep,
                       clojure-rte.cl-compat/cl-cond clojure-rte.cl-compat/cl-cond,
                       clojure-rte.cl-compat/with-escape clojure-rte.cl-compat/with-escape
                       clojure-rte.rte-case/rte-case clojure-rte.rte-case/rte-case
                       clojure-rte.rte-case/destructuring-case clojure-rte.rte-case/destructuring-case
                       clojure-rte.rte-case/destructuring-fn clojure-rte.rte-case/destructuring-fn
                       clojure-rte.rte-case/-destructuring-fn-many clojure-rte.rte-case/-destructuring-fn-many
                       clojure-rte.rte-case/dsfn clojure-rte.rte-case/dsfn
                       clojure-rte.rte-case/dscase clojure-rte.rte-case/dscase
                       clojure-rte.typecase/typecase clojure-rte.typecase/typecase
                       ;; backtick/template backtick/template
                       }}}
However, when I run
clojure -M:clj-kondo --copy-configs --lint $(clojure -Spath)
I still see the first line of output
Imported config to .clj-kondo/backtick/backtick. To activate, add "backtick/backtick" to :config-paths in .clj-kondo/config.edn.

Jim Newton13:07:59

ahhhhh config-paths, not config-dirs ..... hold on

Jim Newton13:07:33

bash-3.2$ clojure -M:clj-kondo --copy-configs --lint $(clojure -Spath)
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:30:1: warning: redefined var #'backtick/*resolve*
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:32:1: warning: redefined var #'backtick/*gensyms*
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:37:1: warning: redefined var #'backtick/resolve
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:48:1: warning: redefined var #'backtick/unquote?
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:53:1: warning: redefined var #'backtick/unquote-splicing?
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:102:1: warning: redefined var #'backtick/quote-fn
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:107:1: warning: redefined var #'backtick/defquote
/U

Jim Newton13:07:41

maybe I need to remove some caches somewhere?

borkdude13:07:42

hmm, I think clj-kondo should actually not lint your hook code

borkdude13:07:05

I kind of expected this error

Jim Newton13:07:10

removing .cache and .cpcache seems to have no effect.

borkdude13:07:41

it should consider namespaces from hook code and application code differently

borkdude13:07:52

now it thinks they are the same ;)

Jim Newton13:07:04

bash-3.2$ clojure -M:clj-kondo --copy-configs --lint src
src/clojure_rte/genus.clj:35:31: warning: Unresolved var: template
src/clojure_rte/genus_spec.clj:27:31: warning: Unresolved var: template
src/clojure_rte/rte_case.clj:29:31: warning: Unresolved var: template
src/clojure_rte/rte_construct.clj:37:31: warning: Unresolved var: template
src/clojure_rte/rte_construct.clj:2113:34: warning: unused binding sink-state-id
src/clojure_rte/rte_extract.clj:32:9: warning: unused binding canonicalize-pattern
src/clojure_rte/typecase.clj:25:31: warning: Unresolved var: template
src/clojure_rte/xymbolyco.clj:34:31: warning: Unresolved var: template
linting took 1742ms, errors: 0, warnings: 8

borkdude13:07:52

yes, this is the same problem basically. the hook namespace replaces the real namespace. instead, we should just never save the results from linted hook code to the cache

Jim Newton13:07:56

I wonder if clojure if finding the correct template library now?

borkdude13:07:37

this warrants another issue on github

borkdude13:07:56

so far this wasn't a problem since the hook namespaces were always called differently than application code

Jim Newton13:07:57

sorry, me no understand.

borkdude13:07:49

ok, what happens is that clj-kondo lints the backtick library. but while linting it, it also lints the hook namespace code and mistakes it for the original namespace since it has the same name

borkdude13:07:06

and then when you use this library from your code, you will see some vars are "unresolved" because they are not in the hook code

borkdude13:07:46

instead, clj-kondo should never "replace" the results of linted hook code in the cache

Jim Newton13:07:03

so what triggered clj-kondo to lint the backtick library?

borkdude13:07:13

clj-kondo lints your config code as well, that's the problem

Jim Newton13:07:23

ahhh was that the --lint $(clojure -Spath) ?

borkdude13:07:50

yes, that code is on the classpath. which was the point, because else it wouldn't have been copied

borkdude13:07:09

but clj-kondo just skip linting it

borkdude13:07:18

lemme push a quick fix for this

borkdude13:07:30

@jimka.issy Can you test commit 07fd7d0ca055e09072d9ea9779e9e5c73e0c0026 of clj-kondo?

Jim Newton13:07:04

oops was away from desk.

Jim Newton13:07:26

bash-3.2$ clojure -M:clj-kondo --copy-configs --lint src
Checking out:  at 07fd7d0ca055e09072d9ea9779e9e5c73e0c0026
src/clojure_rte/genus.clj:35:31: warning: Unresolved var: template
src/clojure_rte/genus_spec.clj:27:31: warning: Unresolved var: template
src/clojure_rte/rte_case.clj:29:31: warning: Unresolved var: template
src/clojure_rte/rte_construct.clj:37:31: warning: Unresolved var: template
src/clojure_rte/rte_construct.clj:2113:34: warning: unused binding sink-state-id
src/clojure_rte/rte_extract.clj:32:9: warning: unused binding canonicalize-pattern
src/clojure_rte/typecase.clj:25:31: warning: Unresolved var: template
src/clojure_rte/xymbolyco.clj:34:31: warning: Unresolved var: template
linting took 1758ms, errors: 0, warnings: 8
Do I need something else other than just changing the sha code?

borkdude13:07:54

yes, re-lint the classpath

Jim Newton13:07:00

bash-3.2$ clojure -M:clj-kondo --copy-configs --lint $(clojure -Spath)
/Users/jnewton/Repos/backtick/src/backtick.clj:58:11: error: Unresolved symbol: template
/Users/jnewton/Repos/backtick/src/backtick.clj:101:11: error: Unresolved symbol: syntax-quote
clojure/core.clj:35:17: warning: unused binding &form
clojure/core.clj:35:23: warning: unused binding &env
clojure/core.clj:40:18: warning: unused binding &form
clojure/core.clj:40:24: warning: unused binding &env
clojure/core.clj:45:20: warning: unused binding &env
clojure/core.clj:210:9: warning: Missing else branch.
clojure/core.clj:223:27: warning: unused binding fdecl
clojure/core.clj:294:17: warning: unused binding &form
clojure/core.clj:294:23: warning: unused binding &env
clojure/core.clj:325:23: warning: Missing else branch.

borkdude13:07:26

and now re-lint your src

borkdude13:07:39

(you don't need config-configs for that anymore)

Jim Newton13:07:30

bash-3.2$ clojure -M:clj-kondo  --lint src
src/clojure_rte/genus.clj:35:31: warning: Unresolved var: template
src/clojure_rte/genus_spec.clj:27:31: warning: Unresolved var: template
src/clojure_rte/rte_case.clj:29:31: warning: Unresolved var: template
src/clojure_rte/rte_construct.clj:37:31: warning: Unresolved var: template
src/clojure_rte/rte_construct.clj:2113:34: warning: unused binding sink-state-id
src/clojure_rte/rte_extract.clj:32:9: warning: unused binding canonicalize-pattern
src/clojure_rte/typecase.clj:25:31: warning: Unresolved var: template
src/clojure_rte/xymbolyco.clj:34:31: warning: Unresolved var: template
linting took 1690ms, errors: 0, warnings: 8

borkdude13:07:56

What is inside your :clj-kondo alias?

Jim Newton13:07:40

{:aliases
 {:clj-kondo
  {:replace-deps
   {clj-kondo/clj-kondo
    {:git/url ""
     
     :sha "07fd7d0ca055e09072d9ea9779e9e5c73e0c0026" ;; "30c878d719c7630ee5f5e51876ba780c5667b23f"
     }}
   :main-opts ["-m" "clj-kondo.main"]}}
 :deps {backtick/backtick {:local/root "/Users/jnewton/Repos/backtick"}}
}

Jim Newton13:07:55

did you make a copy of my repo?

I have pushed everything if you'd like to take a look

borkdude13:07:31

Oh I see what the problem is.

Jim Newton13:07:40

oops but you don't have my local backtick directory. details 🤪

borkdude13:07:13

You can solve that one using :lint-as {backtick/defquote clojure.core/declare} config

borkdude13:07:42

I will revert my previous commit to get this sorted out better and not to confuse things

Jim Newton13:07:10

but wait. why is that file being linted anyway?

borkdude13:07:35

so clj-kondo knows about the arities, types, etc from that library

borkdude13:07:52

so when you call that library, clj-kondo can provide you with better linting

borkdude13:07:22

Reverted the commit in 5fd42138312f7a41126c48edb32c79f42b036cbf

Jim Newton13:07:28

so I need to add :lint-as {backtick/defquote clojure.core/declare} in the file backtick/resources/clj-kondo.exports/backtick/backtick/config.edn ?

Jim Newton13:07:03

and :lint-as is parallel with :macroexpand, or rather parallel with :hooks ?

Jim Newton13:07:47

hmmmm. now

clojure -M:clj-kondo --copy-configs --lint $(clojure -Spath)
gives the following output

Jim Newton13:07:46

bash-3.2$ clojure -M:clj-kondo --copy-configs --lint $(clojure -Spath)
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:30:1: warning: redefined var #'backtick/*resolve*
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:32:1: warning: redefined var #'backtick/*gensyms*
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:37:1: warning: redefined var #'backtick/resolve
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:48:1: warning: redefined var #'backtick/unquote?
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:53:1: warning: redefined var #'backtick/unquote-splicing?
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:102:1: warning: redefined var #'backtick/quote-fn
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:107:1: warning: redefined var #'backtick/defquote
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:116:1: warning: redefined var #'backtick/class-symbol
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:119:1: warning: redefined var #'backtick/namespace-name
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:122:1: warning: redefined var #'backtick/var-namespace
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:125:1: warning: redefined var #'backtick/var-name
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:128:1: warning: redefined var #'backtick/var-symbol
/Users/jnewton/Repos/backtick/resources/clj-kondo.exports/backtick/backtick/backtick.clj:131:1: warning: redefined var #'backtick/ns-resolve-sym
clojure/core.clj:35:17: warning: unused binding &form
clojure/core.clj:35:23: warning: unused binding &env
clojure/core.clj:40:18: warning: unused binding &form
clojure/core.clj:40:24: warning: unused binding &env
clojure/core.clj:45:20: warning: unused binding &env
clojure/core.clj:210:9: warning: Missing else branch.

Jim Newton13:07:51

is that what you expect?

borkdude13:07:33

ok, let me re-apply my commit from just before ;)

borkdude14:07:17

try d5e0ec443fecbc01f8fc5aae4de69cce2e1e72be

Jim Newton14:07:22

got distracted with work.

Jim Newton14:07:56

OK, here is the output

bash-3.2$ clojure -M:clj-kondo --copy-configs --lint $(clojure -Spath)
Checking out:  at d5e0ec443fecbc01f8fc5aae4de69cce2e1e72be
clojure/core.clj:35:17: warning: unused binding &form
clojure/core.clj:35:23: warning: unused binding &env
clojure/core.clj:40:18: warning: unused binding &form
clojure/core.clj:40:24: warning: unused binding &env
clojure/core.clj:45:20: warning: unused binding &env
clojure/core.clj:210:9: warning: Missing else branch.
clojure/core.clj:223:27: warning: unused binding fdecl
clojure/core.clj:294:17: warning: unused binding &form
clojure/core.clj:294:23: warning: unused binding &env
clojure/core.clj:325:23: warning: Missing else branch.
clojure/core.clj:454:16: warning: unused binding &form
clojure/core.clj:454:22: warning: unused binding &env
clojure/core.clj:544:4: warning: unused binding x
clojure/core.clj:794:5: warning: unused binding x
clojure/core.clj:826:5: warning: unused binding x
clojure/core.clj:908:5: warning: unused binding x
clojure/core.clj:1063:5: warning: unused binding x
clojure/core.clj:1078:5: warning: unused binding x
clojure/core.clj:1093:5: warning: unused binding x
clojure/core.clj:1108:5: warning: unused binding x
clojure/core.clj:1451:14: warning: unused binding args
clojure/core.clj:2307:56: warning: unused binding e
clojure/core.clj:2511:4: warning: unused binding flags-ignored-for-now
clojure/core.clj:2731:1: warning: redefined var #'clojure.core/map
clojure/core.clj:3301:1: warning: redefined var #'clojure.core/dotimes
clojure/core.clj:3651:31: warning: unused binding writer
clojure/core.clj:3654:28: warning: unused binding writer
clojure/core.clj:3937:12: error: Unresolved symbol: setInt

Jim Newton14:07:12

perhaps those are real errors from that library?

Jim Newton14:07:21

bash-3.2$ clojure -M:clj-kondo  --lint src
src/clojure_rte/rte_construct.clj:2113:34: warning: unused binding sink-state-id
src/clojure_rte/rte_extract.clj:32:9: warning: unused binding canonicalize-pattern
linting took 1641ms, errors: 0, warnings: 2

Jim Newton14:07:22

indeed, those are two error/issues in my code. I don't yet know how to solve them. I think they indicate something is wrong more than just lint.

Jim Newton15:07:15

do you think there are other widely used macros which clj-kondo users might be exploiting, or is template the only one. My gut feel is there are several widely used macros. if clj-kondo knew how to support them it might be easier the convincing maintainers of xyzzy-library to adopt support for clj-kondo which they no nothing about ????

Jim Newton15:07:42

I'm happy to submit my template support for clj-kondo. Not sure what I need to change.

borkdude15:07:22

clj-kondo has built-in support for some macros but we can't possible support all of the macros from the ecosystem. for that the library has to be widely used. I don't think backtick is that widely used

borkdude15:07:35

so for now the config can live in clj-kondo/config

Jim Newton15:07:34

I don't see such a directory. how do the contents of clj-kondo/config relate the the contents of backtick/resources/clj-kondo.exports ?

Jim Newton14:07:59

@borkdude maybe you'd like to join this discussion, in case I've given some false information. https://github.com/brandonbloom/backtick/issues/8

FiVo16:07:54

What is the standard way of developing a hook. I added clj-kondo to my deps. I am getting Could not locate clj_kondo/hooks_api.... when evaluating

(ns hooks.macros
  (:require [clj-kondo.hooks-api :as api]))

borkdude16:07:07

@finn.volkel The hook code runs in an interpreter during linting. You don't actually call it as a library from clojure. You call the API from within the lint config code.

borkdude16:07:43

To develop you just call the linter

borkdude16:07:53

with some examples

FiVo16:07:03

I see thanks

FiVo17:07:36

so I added the following line to my config :hooks {:analyze-call {ramper.util.macros/cond-let hooks.macros/cond-let}} , wrote the hook code and tried with

cat src/clj/ramper/util/macros.clj | clj-kondo --lint -
I am still getting errors. How I do figure out where stuff goes awry? Is my hook code bad if so how do I check that?

FiVo17:07:57

Sorry, maybe not clear from the above. I also have an example of call cond-let in macros.clj.

borkdude17:07:14

Try adding a println in your cond-let hook code

borkdude17:07:19

and see if it's properly being triggered

FiVo17:07:56

tried that, it doesn't

FiVo17:07:02

also changed hooks.macros/cond-let to hooks.cond-let/cond-let . I don't know if that is important.

borkdude17:07:58

it has to correspond to a hooks/cond_let.clj file in your .clj-kondo dir

borkdude17:07:02

in that case

FiVo18:07:22

also the with-bound example should change from {:keys [:node]} -> {:keys [node]}

FiVo18:07:35

in the argument list

borkdude18:07:25

both are valid

borkdude18:07:30

although keyword is less common

FiVo18:07:50

are sorry, didn't know that.

FiVo18:07:12

upgraded clj-kondo, getting a warning now

FiVo18:07:06

I got the thing to work from the command line, but in emacs + flycheck I am getting (in case of uneven forms, i.e. it should report an error):

Suspicious state from syntax checker clj-kondo-clj: Flycheck checker clj-kondo-clj returned 3, but its output contained no errors: /home/fv/Code/Clojure/ramper/src/clj/ramper/util/macros.clj::: error: cond-let requires an even number of forms
linting took 23ms, errors: 1, warnings: 0

Try installing a more recent version of clj-kondo-clj, and please open a bug report if the issue persists in the latest release.  Thanks!
How do I fix that? I upgraded my emacs packages. I am off for the day, so not urgent.

borkdude18:07:31

ah, it's missing location metadata on the node

borkdude18:07:43

you need to add that using with-meta

đź‘Ť 2
AJ Jaro20:07:05

There’s a reference. to clj-kondo.hooks-api in the https://github.com/clj-kondo/clj-kondo/blob/master/doc/hooks.md#custom-lint-warnings. Should that be a reference to a different namespace now?

borkdude20:07:44

@ajarosinski No. This namespace is exposed to hook code which is configured to run using the :hooks config

borkdude20:07:51

it is not exposed as a library to the JVM for general purpose Clojure programming

AJ Jaro20:07:23

@borkdude Thanks for the quick reply; I see. There’s some notification that when using api/sexpr it can’t be resolved, but maybe that’s a Cursive warning

AJ Jaro21:07:08

It seems like it might be possible to highlight a finding containing multiple nodes on a hook using a row , end-row, col, and end-col. I’m having a bit of trouble doing that. For example, below I’d like to highlight from [:img#pic] through [:#pic-col. Is that possible?

(m/deftemplate
  test-fn
  (resource "") 
  [{:keys [data test-data]}]
  [:img#pic] (if data (m/set :src data) nil)
  [:#pic-col])

AJ Jaro21:07:14

Here’s how I’m attempting to register the finding

(when-not (even? (count body))
      (let [{:keys [row col]} (some-> node :children (nth 4) meta)
            end-metadata (some-> node :children last meta)]
        (api/reg-finding! {:message "Must have an even number of arguments in the body"
                           :type    :m-template
                           :row     row
                           :end-row (:end-row end-metadata)
                           :col     col
                           :end-col (:end-col end-metadata)})))

AJ Jaro21:07:31

It registers the finding but only on the [:img#pic] node