Hey @borkdude, I just noticed the :unused-namespace
type from :findings
in clj-kondo don't contain which namespace is unused, am I missing something?
for example a code like this:
(ns foo.bar (:require [bar :as b]))
Gives me the finding
:
{:type :unused-namespace,
:message "namespace bar is required but never used",
:level :warning,
:row 1,
:end-row 1,
:end-col 21,
:col 18,
:filename "/a.clj"}
it'd be nice to have a :ns bar
Findings generally don't have this information (since this is not output to linter editor integration in general) but I think we could add it, without breaking things :)
PR welcome
thanks 🙂 I don't know clj-kondo code, any tips on what/where change it? I'd love to help 🙂
grep for "is required but never used" and this should be relatively easy to plug in. Usually this is tested either in main_test.clj or unused_namespace_test.clj (or something like this). Grep should also show where this is tested
Thank you! 👀
hmm, but the tests round-trip from the text output, so a test calling the core namespace should be added separately to test for the :ns addition
Let me know if you have any questions
What do you think it's the best, merging https://github.com/clj-kondo/clj-kondo/blob/master/src/clj_kondo/impl/linters.clj#L405`node->line` with something like {:ns ns-sym}
and {:refer :refer-sym}
for unused-refer lint or adding a name
or extra
arg for node->line
?
(assoc ... :ns ns-sym)
merge
is best avoided, assoc
is faster ;)
nice!
Any reason why load the ns with cider fails because of missing deps me.raynes.conch
?
are you running with deps.edn?
You should include the :test
alias then
same for lein: with-profiles +test
I'm having a hard time to make cider use the test
lein profile :man-facepalming: 😂
This is why I never use cider-jack-in. I always use cider-connect
To be honest, with clj-kondo development, I almost never use a REPL. I always just use the command line
I got it, but yeah, I agree that could work too
maybe in a near future when clojure-lsp uses clj-kondo 😜
clojure -M:clj-kondo --lint - <<< '(+ 1 2 3)'
@borkdude the tests on main_test
don't return the added :ns
, I think this is what you meant above right?
how can I test that?
sorry for too many questions 😅
This is the draft atm https://github.com/clj-kondo/clj-kondo/pull/1132
@ericdallo yeah, instead of (lint! ...)
you just call (-> (with-in-str "your-code" (clj-kondo.core/run! {:lint ["-"]}) :findings)
so as an API call basically. lint!
mimics the command line usage (the primary way in which clj-kondo was initially used)
Got it, should I add that as a new deftest in core_test or a new test ns?
I think you can put it along with the other unused-ns tests
like unused_namespace_test.clj
ok
but also feel free to move the existing ones to unused_namespace_test.clj
if that doesn't exist yet
main_test is way too big
yes, I can do that 😄
Done @borkdude, thank you for the help during this 🙂 LMK if any issues with the PR: https://github.com/clj-kondo/clj-kondo/pull/1132
I merged a new linter called :unresolved-var
to master now. It will give a warning on the following: (require '[clojure.set :as set]) (set/onion #{1 2 3})
: "No such var: set/onion"
.
The default level is :off
but will be bumped to :error
when this is done (there are 2 TODO items left).
You can download a binary from the CircleCI builds if you would like to give this a spin in your daily dev (or use on the JVM). Testing is highly appreciated.