clj-kondo

https://github.com/clj-kondo/clj-kondo
ericdallo 2021-01-18T16:42:27.030300Z

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?

ericdallo 2021-01-18T16:43:44.030400Z

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

ericdallo 2021-01-18T16:44:14.030600Z

it'd be nice to have a :ns bar

borkdude 2021-01-18T16:46:02.030900Z

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

borkdude 2021-01-18T16:46:36.031100Z

PR welcome

ericdallo 2021-01-18T16:47:09.031300Z

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

borkdude 2021-01-18T16:48:05.031500Z

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

ericdallo 2021-01-18T16:48:48.031700Z

Thank you! 👀

borkdude 2021-01-18T16:49:01.031900Z

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

borkdude 2021-01-18T16:49:18.032100Z

Let me know if you have any questions

👍 1
ericdallo 2021-01-18T16:57:49.032400Z

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 ?

borkdude 2021-01-18T16:58:34.032700Z

(assoc ... :ns ns-sym)

borkdude 2021-01-18T16:58:49.032900Z

merge is best avoided, assoc is faster ;)

ericdallo 2021-01-18T16:59:07.033100Z

nice!

ericdallo 2021-01-18T17:15:01.033300Z

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

borkdude 2021-01-18T17:16:32.033500Z

are you running with deps.edn?

borkdude 2021-01-18T17:16:55.033700Z

You should include the :test alias then

borkdude 2021-01-18T17:17:04.033900Z

same for lein: with-profiles +test

ericdallo 2021-01-18T17:33:25.034100Z

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

borkdude 2021-01-18T17:34:02.034300Z

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

borkdude 2021-01-18T17:34:40.034500Z

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

ericdallo 2021-01-18T17:36:42.034700Z

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

ericdallo 2021-01-18T17:36:58.034900Z

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

borkdude 2021-01-18T17:37:47.035100Z

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

ericdallo 2021-01-18T17:55:02.035500Z

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

ericdallo 2021-01-18T17:55:21.035700Z

sorry for too many questions 😅

ericdallo 2021-01-18T18:00:12.035900Z

This is the draft atm https://github.com/clj-kondo/clj-kondo/pull/1132

borkdude 2021-01-18T18:43:22.036300Z

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

borkdude 2021-01-18T18:43:53.036500Z

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

ericdallo 2021-01-18T18:44:20.036800Z

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

borkdude 2021-01-18T18:44:37.037Z

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

ericdallo 2021-01-18T18:44:38.037200Z

like unused_namespace_test.clj

ericdallo 2021-01-18T18:44:42.037400Z

ok

borkdude 2021-01-18T18:45:02.037600Z

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

borkdude 2021-01-18T18:45:06.037800Z

main_test is way too big

ericdallo 2021-01-18T18:45:16.038Z

yes, I can do that 😄

ericdallo 2021-01-18T19:40:35.038200Z

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

borkdude 2021-01-18T22:36:02.040900Z

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.