borkdude / api-diff

Print API diffs between library versions
59 stars 2 forks source link

Consider reporting on callable <-> not-callable change #18

Open lread opened 3 years ago

lread commented 3 years ago

If v1 has

(defn becomes-def [])

And v2 has:

(def becomes-def 42)

An arity 0 deletion is currently reported. This is an indicator of breakage and might be good enough.

But if we swap v1 and v2 we get no report which is not ideal.

Perhaps we could instead report when something has become callable (or not callable) as a breakage.

test-resources/older/example.clj:x:y: error: example/becomes-def was callable.
test-resources/older/example.clj:x:y: error: example/becomes-defn was not callable.

(BTW: I'm not suggesting that we evaluate based on def vs defn but rather on the presence or absence of any call signatures found by clj-kondo).

borkdude commented 3 years ago

This seems rather unlikely? Also, the var could have become something like (def foo (partial bar 1)) so in theory it could still be a function.

lread commented 3 years ago

Oh right... hard to detect callability.

I had tried this def:

❯ clj-kondo --config '{:output {:format :edn :analysis true}}' --lint - <<< '(def bar (fn [x y x]))' | jet --pretty --query ':analysis :var-definitions'
[{:fixed-arities #{3},
  :end-row 1,
  :name-end-col 9,
  :name-end-row 1,
  :name-row 1,
  :ns user,
  :name bar,
  :defined-by clojure.core/def,
  :filename "<stdin>",
  :col 1,
  :name-col 6,
  :end-col 23,
  :row 1}]

And saw the arity, but of course, clj-kondo will only do so much here, when I try your example I see your point:

❯ clj-kondo --config '{:output {:format :edn :analysis true}}' --lint - <<< '(def foo (partial bar 1))' | jet --pretty --query ':analysis :var-definitions'
[{:end-row 1,
  :name-end-col 9,
  :name-end-row 1,
  :name-row 1,
  :ns user,
  :name foo,
  :defined-by clojure.core/def,
  :filename "<stdin>",
  :col 1,
  :name-col 6,
  :end-col 26,
  :row 1}]

I know this kind of diff is unlikely... but as I user, I see any potential API breakage as very interesting.

Ideas:

borkdude commented 3 years ago

Although the return type of partial is a function so we could still support that in clj-kondo, e.g with :ifn true or :ifn false or so.