This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-03-04
Channels
- # announcements (4)
- # asami (38)
- # babashka (20)
- # beginners (188)
- # cider (1)
- # clara (11)
- # clj-kondo (103)
- # cljs-dev (15)
- # cljtogether (1)
- # clojure (138)
- # clojure-australia (5)
- # clojure-europe (33)
- # clojure-france (1)
- # clojure-losangeles (5)
- # clojure-nl (4)
- # clojure-norway (11)
- # clojure-serbia (3)
- # clojure-uk (11)
- # clojurescript (45)
- # community-development (3)
- # conjure (22)
- # core-async (18)
- # datomic (44)
- # defnpodcast (4)
- # deps-new (1)
- # depstar (49)
- # events (2)
- # fulcro (33)
- # girouette (2)
- # honeysql (37)
- # jackdaw (5)
- # jobs-discuss (16)
- # kaocha (3)
- # leiningen (4)
- # lsp (77)
- # malli (55)
- # membrane (4)
- # off-topic (61)
- # polylith (5)
- # quil (5)
- # reagent (33)
- # reitit (12)
- # remote-jobs (1)
- # reveal (4)
- # rewrite-clj (2)
- # sci (16)
- # shadow-cljs (22)
- # sql (1)
- # test-check (27)
- # tools-deps (44)
Can I have a hook in my ~/.clj-kondo
dir? I'd like to create a hook for a common macro used on hundred of clojure projects
It might even better to check the hook code into those projects or into the libraries for which the hook code is written for, so your co-workers can re-use them too
Yes, we already have a common config for clj-kondo 🙂 my idea is add a hook there as well
Is there a example of a hook that defines a var-definition
?
I have a macro that behaves similar to defn with some minor differences, How can I tell to the clj-kondo in the hook that the first arg is the var-definition name ?
@ericdallo Write a hook that expands into a clojure.core/defn
or clojure.core/def
node
@ericdallo That is expected and documented. Maybe for your custom defn you also could have used {:lint-as {... clj-kondo.lint-as/def-catch-all}}
I was using that :lint-as
for months, but now I want to fix some things from that macro
We could maybe change the behavior of newly created nodes automatically taking over the position of the outer original node, but that might also confuse people when there is a linting warning on the wrong position
it's a integration test macro:
(defflow my-integration-test
[a (my-func)]
(some-flow)
[b (other-func)]
(other-flow))
oh, really cool! So I'd just need to add to my config the :hooks map, but not the hooks folder with the hooks since it'd be present on the lib, right?
The docs for this are here: https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md#exporting-and-importing-configuration
yes, and when you have a new version of your library, the hook code is updated as well
really amazing indeed, could I open a PR for https://github.com/clj-kondo/config/tree/master/resources/clj-kondo.exports/clj-kondo adding that state-flow
macro later?
Yes, I'll certainly add to the state-flow, so maybe we don't need to add to the clj-kondo/config so?
yeah, clj-kondo/config is only for hooks that are contributed without being it part of the libraries themselves
(defn ^:private defflow-bindings [nodes]
(->> nodes
(filter api/vector-node?)
(map (fn [node]
(let [[sym val] (:children node)]
[sym val])))
flatten
vec))
(defn ^:private defflow-flows [nodes]
(filter (complement api/vector-node?) nodes))
(defn defflow [{:keys [:node]}]
(let [[name & flows] (rest (:children node))
new-node (api/list-node
(list
(with-meta (api/token-node 'defn) (meta name))
(with-meta (api/token-node (api/sexpr name)) (meta name))
(api/vector-node [])
(api/list-node (list* (api/token-node 'let)
(api/vector-node (defflow-bindings flows))
(defflow-flows flows)))))]
(prn (api/sexpr new-node))
{:node new-node}))
And a sample of usage:
(defflow my-flow
[a (+ 1 2)]
(flow "flow-1"
(match? a
1))
[b (+ 1 2)]
(flow "flow-2"
(match? a
b)))
thanks!
I tried to change the defn
to clojure.test/deftest
but it seems to not work
you should probably generate (do (require 'clojure.test) (clojure.test/deftest ...))
in that case
does that looks correct for you? https://github.com/nubank/state-flow/pull/149
@ericdallo I would use a multi-segment namespace like nubank.state-flow
for the hook namespace
e.g. check here: https://github.com/clj-kondo/config/tree/master/resources/clj-kondo.exports/clj-kondo/claypoole
note that here clj-kondo is the org, because this hook is written on behalf of the clj-kondo org
Done, still looks odd to me the path:
resources/clj-kondo.exports/nubank/state-flow/nubank/state_flow.clj
is that right?Also I included a:
resources/clj-kondo.exports/nubank/state-flow/config.edn
not sure if this should be in the lib or manually set by useronly the parts that are relevant for the lib should be in there, including the hook config
I tried to add to my home config:
{ :hooks {:analyze-call {
state-flow.cljtest/defflow nubank.state-flow/defflow
state-flow.core/flow nubank.state-flow/flow}}}
You should not have to add this to your home config if you opt-in to your library config
Read the part about how to opt in: https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md#exporting-and-importing-configuration
I already did it, I tried adding a :config-paths ["nubank/state-flow"]
but didn't work 😕
So, that's what I did: • generated a local release in this branch: https://github.com/nubank/state-flow/pull/149/files • Changed a local project to usethe local release • when I start lsp on the file it does not handle the macro, it was handling when the hook was on my home dir before I move it to the lib
You should read the last part of https://github.com/clj-kondo/clj-kondo/blob/master/doc/config.md#exporting-and-importing-configuration better
sorry, that last part is not clear to me, should I add that
{:config-paths ["nubank/state-flow"]}
in the lib config.edn?oh found a log message on clojure-lsp:
WARNING: error while trying to read hook for integration.aux.init/defflow: Could not find namespace: nubank.state-flow.
Just try to walk through the docs step by step for the clj-kondo config project example, it should explain itself
It works now, I renamed only the hook file not the ns inside it :man-facepalming: Thanks for the help and sorry for bother you 🙂
is there any way to show globally unused publics in linting output? I think the answer is no, but I could swear there was a point in time where this was possible…
@devn This isn't supported out of the box, but you can do this using analysis output: https://github.com/clj-kondo/clj-kondo/blob/master/analysis/README.md#unused-vars Private unused vars are reported though.
There is also https://github.com/borkdude/carve to do this for you
nice. i was mostly asking because in older versions of clojure-lsp, it’d highlight public global unused vars, and that was very handy for knocking out dead code
yes, we could do the same logic from lenses indeed, just don't know if we should always present that as a warning
it could just be an "info" diagnostic as well, the level could maybe be similarly set as how clj-kondo does it
yeah, i can use the lens (and I have been), but the highlight was nice IMO. I’m actually a bit surprised y’all think the default should be disabled.
When I think about it, I’m not sure why you’d have an unused public fn that is part of an API that doesn’t have a matching test (even if the level of test is as simple as “it exists”).
Yeah, I think the same, I think I'll add something like :public-vars-lint-level :info
Detect unreachable specs - has this idea already been proposed / implemented? https://stackoverflow.com/questions/45819346/how-to-check-the-resolvability-of-clojure-specs
ah good point, I would was thinking more of used but undefined
like a (s/keys :req-un [::where])
that does not have corresponding (s/def ::where map?)