venantius / yagni

A Leiningen plugin for finding dead code
Eclipse Public License 1.0
219 stars 10 forks source link

Ignores functions used inside 'extend-protocol' #41

Open thisdotrob opened 6 years ago

thisdotrob commented 6 years ago

For the following code, both ISO-date-format and java->joda-local-date are flagged as being unused.

(def ISO-date-format
  (tf/formatter "yyyy-MM-dd"))

(defn java->joda-local-date [java-local-date]
    (tf/parse-local-date ISO-date-format (.toString java-local-date)))

;; Prevent default behaviour of coercing sql-dates into clojure instants. A date in our database refers to a calendar day, not a moment in time, and coercing to an instant in time brings all manner of silly painful bugs.
;; https://dev.clojure.org/jira/browse/JDBC-35 for more details
(extend-protocol jdbc/IResultSetReadColumn
  java.sql.Date
  (result-set-read-column [val _ _]
    (java->joda-local-date (.toLocalDate val)))

  java.sql.Timestamp
  (result-set-read-column [val _ _]
    (.toInstant val))

  org.postgresql.jdbc4.Jdbc4Array
  (result-set-read-column [pgobj _ _]
    (vec (.getArray pgobj)))

  org.postgresql.util.PGobject
  (result-set-read-column [pgobj _ _]
    (if (= (.getType pgobj) "json")
      (json/read-str (.toString pgobj)
                     :key-fn (comp keyword name dbh/snake-case->kebab-case))
      pgobj)))