Fork me on GitHub
#clj-kondo
<
2021-01-18
>
ericdallo16:01:27

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?

ericdallo16:01:44

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"}

ericdallo16:01:14

it'd be nice to have a :ns bar

borkdude16:01:02

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 :)

ericdallo16:01:09

thanks 🙂 I don't know clj-kondo code, any tips on what/where change it? I'd love to help 🙂

borkdude16:01:05

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

ericdallo16:01:48

Thank you! 👀

borkdude16:01:01

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

borkdude16:01:18

Let me know if you have any questions

👍 3
ericdallo16:01:49

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 ?

borkdude16:01:34

(assoc ... :ns ns-sym)

borkdude16:01:49

merge is best avoided, assoc is faster ;)

ericdallo17:01:01

Any reason why load the ns with cider fails because of missing deps me.raynes.conch ?

borkdude17:01:32

are you running with deps.edn?

borkdude17:01:55

You should include the :test alias then

borkdude17:01:04

same for lein: with-profiles +test

ericdallo17:01:25

I'm having a hard time to make cider use the test lein profile :man-facepalming: 😂

borkdude17:01:02

This is why I never use cider-jack-in. I always use cider-connect

borkdude17:01:40

To be honest, with clj-kondo development, I almost never use a REPL. I always just use the command line

ericdallo17:01:42

I got it, but yeah, I agree that could work too

ericdallo17:01:58

maybe in a near future when clojure-lsp uses clj-kondo 😜

borkdude17:01:47

clojure -M:clj-kondo --lint - <<< '(+ 1 2 3)' 

ericdallo17:01:02

@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?

ericdallo17:01:21

sorry for too many questions 😅

borkdude18:01:22

@UKFSJSM38 yeah, instead of (lint! ...) you just call (-> (with-in-str "your-code" (clj-kondo.core/run! {:lint ["-"]}) :findings)

borkdude18:01:53

so as an API call basically. lint! mimics the command line usage (the primary way in which clj-kondo was initially used)

ericdallo18:01:20

Got it, should I add that as a new deftest in core_test or a new test ns?

borkdude18:01:37

I think you can put it along with the other unused-ns tests

ericdallo18:01:38

like unused_namespace_test.clj

borkdude18:01:02

but also feel free to move the existing ones to unused_namespace_test.clj if that doesn't exist yet

borkdude18:01:06

main_test is way too big

ericdallo18:01:16

yes, I can do that 😄

ericdallo19:01:35

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

borkdude22:01:02

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.