clj-kondo

https://github.com/clj-kondo/clj-kondo
fiddlerwoaroof 2020-05-06T00:49:34.100200Z

Is there an exclusion list for unused imports?

fiddlerwoaroof 2020-05-06T00:51:33.100800Z

Also, was there a way to use Clojure metadata to configure clj-kondo?

seancorfield 2020-05-06T01:05:10.101500Z

@fiddlerwoaroof You can provide metadata on the ns form for per-file configuration overrides.

seancorfield 2020-05-06T01:05:37.101700Z

(ns worldsingles.expectations.mobile.user
  {:clj-kondo/config
   '{:lint-as
     {worldsingles.expectations.mobile.user/patch-notifications
      clj-kondo.lint-as/def-catch-all}}}
  (:require [clj-time.coerce :as tc]
            [clj-time.core :as t]
            [clj-time.format :as tf]
...

seancorfield 2020-05-06T01:05:55.102400Z

Note the ' so the symbol names do not get evaluated!

fiddlerwoaroof 2020-05-06T01:06:04.102700Z

Thanks, I really dislike the friction a separate config file adds

seancorfield 2020-05-06T01:06:36.103400Z

(metadata on ns can come before the namespace name if you use ^)

seancorfield 2020-05-06T01:07:14.104400Z

I have a config file in each project, at this point, with just that one override so far.

fiddlerwoaroof 2020-05-06T01:07:16.104500Z

My current issue is that I have to import a JDBC driver, but I never use it directly and I can't figure out how to hide the warning

seancorfield 2020-05-06T01:07:34.104800Z

Really? Why is that?

fiddlerwoaroof 2020-05-06T01:07:55.105500Z

Because it's used implicitly when the connection string is parsed

fiddlerwoaroof 2020-05-06T01:08:03.105800Z

Hmm, maybe I don't need the import

seancorfield 2020-05-06T01:08:06.105900Z

Neither clojure.java.jdbc nor next.jdbc need you to import the JDBC drivers.

fiddlerwoaroof 2020-05-06T01:08:38.106300Z

Cool, I wasn't thinking things through

seancorfield 2020-05-06T01:08:51.106600Z

Fixed your warning for you! 😆

fiddlerwoaroof 2020-05-06T16:05:24.106800Z

thanks

lread 2020-05-06T20:37:53.117600Z

Heya @borkdude! I am slowly dipping my toes back into rewrite-cljc. It has been a long while since I spent time with my old reliable and helpful clj-kondo. I have missed her and the reunion is delightful. I noticed 2 small things while updating to the latest clj-kondo (remember I have been away for literally months!): 1. clj-kondo --help does not show cljc as a valid option for --lang, should it? 2. I had to add "<stdin>" to my clj-kondo .config.edn->`:output` -> :include-files to get spacemacs to show clj-kondos findings. I now have :output {:include-files ["<stdin>" "^src" "^test" "^script"]}. If having to include <stdin> is by design, a note in the docs might be helpful. Am happy to make PRs for above if there is any work to do.

borkdude 2020-05-06T20:41:24.119Z

@lee 1) Yeah, it should. 2) Why are you excluding test files from linting in your editor? Clj-kondo is pretty helpful there too. Scripts: dunno. Maybe just try without the entire include-files thing and start over?

2020-05-06T20:53:21.122800Z

Hi, I’ve made a try-let abomination macro that needs to be linted as both a let and a try block. How can I configure it? Usage:

(try-let [a (db-connection)
          b (might-throw)]
  (process a b)
  (catch Exception e
    (when a (close a))
    (when b (close b))
    (throw e)))

lread 2020-05-06T20:55:43.122900Z

For 2) I have a single clj-kondo config to support CI scripts and my editor. My CI script runs clj-kondo with my project classpath but I only want to see clj-kondo warnings from my project sources. You helped me come up with this solution in the very early days, but that was long ago and maybe there is a better way.

borkdude 2020-05-06T20:56:33.123100Z

@lee In CI you can add the --config flag to pass additional config, they will be merged

lread 2020-05-06T20:56:59.123300Z

ah… ok, thanks will give that a go.

borkdude 2020-05-06T21:04:22.124Z

you can turn off linting with :unresolved-symbol {:exclude [(weird.macros/try-let)]}

lread 2020-05-06T21:07:04.124100Z

ya that works great, thanks @borkdude! :simple_smile:

borkdude 2020-05-06T21:09:00.124300Z

😄

2020-05-06T21:53:03.124600Z

Is it possible to extend the analyzer instead with a custom analyzer? I scanned the source briefly and I can’t find a way?

borkdude 2020-05-06T21:54:40.124900Z

not at the moment

seancorfield 2020-05-06T22:00:40.128Z

@yonatanel It won't help you but my opinion, after spending a bunch of time trying to get clj-kondo to "like" some of my macro-based code, is that it's a really good idea to make sure you don't create new syntax via macros that doesn't "match" something that is in Clojure already 🙂 It's made it clear to me just how hard it would be for someone new to my code to be able to read stuff that uses macros that have "unexpected" syntax. I'm seriously rethinking some of the syntax in my Expectations library at this point, after wrestling with clj-kondo!

❤️ 6
practicalli-john 2020-05-07T09:13:09.130700Z

First rule of macro club, don't create macro's (unless there is an extremely compelling reason)

2020-05-06T22:03:31.128200Z

True, we get carried away sometimes.