Fork me on GitHub
#clj-kondo
<
2019-09-22
>
sogaiu00:09:37

i was thinking it would help to get people to try the feature out -- not too keen on having to write the annotations from scratch, but may be the barrier-to-entry might be sufficiently low if all i needed to do was edit some generated things 🙂 he he -- just being lazy

borkdude06:09:09

Yeah, spec provider might be used to generate an initial config. This can be a third party tool outside of clj-kondo

sogaiu07:09:35

i wonder if it's practical to generate the annotations for clj-kondo from at least some types of existing specs

sogaiu07:09:14

may be there's a way to automate getting part-way there -- and fill the rest in with core.logic? i can dream, can't i 🙂

borkdude09:09:24

feel free to experiment 🙂

glenjamin11:09:45

👋 Just wanted to expand on the success story @marc-omorain mentioned: This is an extracted code sample that represents what i actually had

(defn- make-api-call
  "Separate the logic from the call mechanism, even though there's only one call"
  [{:keys [api path body tags]}]
  (let [metric-result (promise)
        metric-status (promise)]
    (try
      (let [{:keys [status]}
            (clj-http.client/post ""
                                  {:form-params body})]
        (deliver metric-status status)
        (deliver metric-result :ok))
      (catch clojure.lang.ExceptionInfo ex
        (let [data (ex-data ex)]
          (when-let [status (:status data)]
            (deliver metric-status status)
            (deliver metric-result :http-error)
            (throw (ex-info "request failed"
                            (merge data {:api api
                                         :type :http})
                            ex)))
          (deliver metric-result)
          (throw ex)))
      (catch java.io.IOException ex
        (deliver metric-result :io-error)
        (throw (ex-info "connection failed"
                        {:api api
                         :type :transport}
                        ex)))
      (catch Throwable ex
        (deliver metric-result :error)
        (throw ex)))))
and this is the error clj-kondo found that i’d overlooked
error: wrong number of args (1) passed to clojure.core/deliver
My tests didn’t exercise that path, because it probably shouldn’t ever happen in practice.

borkdude11:09:46

ah, makes sense. thanks 🙂

borkdude11:09:44

This is the slide I've made out of it. Have to keep it brief, because I have only 20 minutes, so I'm going to mention it in passing. https://www.dropbox.com/s/mcptwz75u6bqcgz/Screenshot%202019-09-22%2013.57.24.png?dl=0

👌 1
glenjamin12:09:10

on a different note, is this scenario something that kondo could/should catch?

(deftest does-some-stuff
  (testing "it does-some-stuff"
    (let [path "resources/test/some/stuff"]
      (= (keywordize-keys (yaml/parse-string (slurp (str path "/config.yml"))))
         (do-stuff path {:parameters {:option false}})))))

borkdude12:09:13

yeah, it could. right now it only catches that if you use the predicate directly under deftest, but it could be made more intelligent

borkdude12:09:10

it always comes at a trade off of producing false negatives.

borkdude12:09:23

feel free to produce an issue on Github so I don't forget about it

glenjamin12:09:32

will do 👍

borkdude21:09:03

clj-kondo v2019.09.22-alpha ✨ Type checking and more. https://github.com/borkdude/clj-kondo/releases/tag/v2019.09.22-alpha