Is there a good way to add a reader macro as a discouraged-var? I guess I could write a hook that looks for it in all forms, but there's probably a better way
Is there some way I can add a directory to the search path for hooks, please?
did you manage to find it out?
Hi. Yes, I did, thank you.
I can't change where things are, as they're in a codebase that I don't control
I wanted to find out how CircleCI wasn't having problems, and looked into that config. It turned out that they were just running a lein alias and the arguments there included --config-dir .circleci
That was the missing part. Once I had that in place, the config file with that name could be used to load the hooks
Then I discovered that other people using this script had been encountering errors and didn't know why
Thank you for the help
👍
We have a git hook for checking in that runs clj-kondo, providing a config edn file. The config file contains:
:hooks {:analyze-call {company.utils/pred->> hooks.pred-thread-last/pred-thread-last}}
This works for others, but for me, I get:
WARNING: file hooks/pred_thread_last not found while loading hook
WARNING: error while trying to read hook for company.utils/pred->>: Could not find namespace: hooks.pred-thread-last.yes, in .clj-kondo/config.edn you can add :config-paths ["../whatever"] . This directory is relative to the config file
but wait, why does it work for others and not fo r you
where is the hook code located
I don't know. The config file is in .circleci and the code is in .circleci/hooks/pred_thread_last.clj, which would seem to be in the right place relative to the config file
if you can make a repro I could try to look into it locally
you could try this, add :configs-paths [".circleci"] to $project/.clj-kondo/config.edn
Without having a repro it's harder to tell what's going on
Sure. I'm trying to cut it down to the basics in a new directory
I run it with:
clj-kondo --config .circleci/clj-kondo-ci-config.edn --lint src/company/service/model_service.clj This outputs the following:
WARNING: file hooks/pred_thread_last not found while loading hook
WARNING: error while trying to read hook for company.utils/pred->>: Could not find namespace: hooks.pred-thread-last.
src/company/service/model_service.clj:1:5: error: Namespace name does not match file name: comopany.service.model-service
src/company/service/model_service.clj:7:4: warning: unused binding ctx
src/company/service/model_service.clj:15:16: warning: unused binding action
src/company/service/model_service.clj:15:46: warning: unused binding op
src/company/service/model_service.clj:17:5: error: comopany.service.model-service/validate-flexibility is called with 2 args but expects 3
linting took 51ms, errors: 2, warnings: 3
oh, and I'm on clj-kondo v2025.01.16
ok, I'm going to have a look
It doesn't work for me either, but it starts working when I add to .clj-kondo/config.edn this:
{:config-paths ["../.circleci"]}I'm a bit surprised that it works for other people
there is one newer clj-kondo version but AFAIK nothing changed regarding this
Probably a better solution (for everyone is this):
clj-kondo --config '{:config-paths [".circleci"]}' --lint src/company/service/model_service.cljThis way you add both the code and the configuration file to the "classpath" of configurations
can we have multiple --config options then?
I couldn't make this work until I finally tried renaming clj-kondo-ci-config.edn to config.edn
oh, no sorry. It wasn't loading the config file at all.
I finally renamed the .circleci directory to .clj-kondo and now it works
maybe I need to make a copy of this file in .clj-kondo
> can we have multiple --config options then?
you don't need it
don't rename the directory
Just run this:
clj-kondo --config '{:config-paths [".circleci"]}' --lint src/company/service/model_service.clj
instead of what you were doing beforeso that --config option goes instead of --config .circleci/clj-kondo-ci-config.edn
but how do I get the full configuration? That's a lot to put on a command line
> but how do I get the full configuration? sorry, I don't follow
The file clj-kondo-ci-config.edn that I sent you is a minimal thing to reproduce the problem
The real file is 32 lines long with lots of config data
does the size of the configuration file matter? I still don't follow
have you tried what I suggested?
and do you understand why it works in your repro?
I specifically mean this solution: https://clojurians.slack.com/archives/CHY97NXE2/p1741983547061279?thread_ts=1741980298.265599&cid=CHY97NXE2
> have you tried what I suggested? On the minimal repro? Yes. It didn't pick the hook.
can you show the console output including the invocation on the command line?
let me remove the other warnings first
I see this in the original situation:
$ clj-kondo --config ./.circleci/clj-kondo-ci-config.edn --lint src/company/service/model_service.clj
WARNING: file hooks/pred_thread_last not found while loading hook
WARNING: error while trying to read hook for company.utils/pred->>: Could not find namespace: hooks.pred-thread-last.
src/company/service/model_service.clj:1:5: error: Namespace name does not match file name: comopany.service.model-service
src/company/service/model_service.clj:7:4: warning: unused binding ctx
src/company/service/model_service.clj:15:16: warning: unused binding action
src/company/service/model_service.clj:15:46: warning: unused binding op
src/company/service/model_service.clj:17:5: error: comopany.service.model-service/validate-flexibility is called with 2 args but expects 3
linting took 41ms, errors: 2, warnings: 3
and this in the "fixed" situation:
$ clj-kondo --config '{:config-paths [".circleci"]}' --lint src/company/service/model_service.clj
src/company/service/model_service.clj:1:5: error: Namespace name does not match file name: comopany.service.model-service
src/company/service/model_service.clj:7:4: warning: unused binding ctx
src/company/service/model_service.clj:15:16: warning: unused binding action
src/company/service/model_service.clj:15:46: warning: unused binding op
src/company/service/model_service.clj:17:5: error: comopany.service.model-service/validate-flexibility is called with 2 args but expects 3
linting took 33ms, errors: 2, warnings: 3
This proves to me that the hook code is being loaded nowthat looks good doesn't it?
That last one: src/company/service/model_service.clj:17:5: error: comopany.service.model-service/validate-flexibility is called with 2 args but expects 3 That does not show when the hook is loaded
can you do a println in the hook code
on the top level
this is also evidence that it's loaded (or not)
I'll be back later
See you later.
Meanwhile, here is an example where it works:
it realized that I wasn't using the new-entity binding that I'd left in the minimal code
you are right, the my solution didn't load the hook code, I didn't see the prn output either
I just put a println in there and it wasn't printed, yes
but I moved the directory:
the newer version of the code that it's linting:
(ns company.service.model-service
(:require
[company.client-utils :as client-utils]
[company.utils :as util]))
(defn validate-flexibility
[_ old-model new-model]
(if (and (:flexible old-model)
(not (:flexible new-model)))
old-model
new-model))
(defn processable?
[ctx {:keys [entity new-entity]}]
(util/pred->> (complement client-utils/error?) new-entity
(validate-flexibility ctx entity)))oh wait, I found it this works:
--config '{:config-paths [".circleci"]}'
but it expects the configuration file to be named config.edn inside of .circleci.
So if you pass an additional --config ./.circleci/clj-kondo-ci-config.edn (like you had before) then it should workso you need both
(or rename the config file to config.edn)
you're only using this configuration in CI?
anyway, I gtg for half an hour
I'll probably be gone, but no, none of this works. Also, while this gets used in CI, it's also being used locally. That's how I ran into it
When I say, "None of this works," what I mean is that I've tried every permutation I can think of around your suggestions. The only way I can get it to work is if I rename the .circleci directory to .clj-kondo. Maybe I should symlink the config file into there?
To recap. • I'm using your original tar file and unpacked it. • I added a prn on the top level like this in the hook code:
(ns hooks.pred-thread-last
(:require [clj-kondo.hooks-api :as api]))
(prn :x)
...
• when I run this:
$ clj-kondo --lint src/company/service/model_service.clj --config '{:config-paths [".circleci"]}' --config .circleci/clj-kondo-ci-config.edn
:x
src/company/service/model_service.clj:1:5: error: Namespace name does not match file name: comopany.service.model-service
src/company/service/model_service.clj:7:4: warning: unused binding ctx
src/company/service/model_service.clj:15:16: warning: unused binding action
src/company/service/model_service.clj:15:30: warning: unused binding new-entity
src/company/service/model_service.clj:15:46: warning: unused binding op
it seems like it's working correct on my side, yes?Why is that config even in another directory if it's also being used locally
and can you reproduce the exact steps above, no permutation, just the exact way I wrote it?
anyway, what should also work is:
• move the hook code to .clj-kondo/hooks/whatever
they don't take effect until you also add the :analyze-call configuration into the mix, but once you do that, the hook code can be properly found