Skip to content

Commit

Permalink
Fix #118 - disable unused-ret-vals warnings via config of enclosing-m…
Browse files Browse the repository at this point in the history
…acros

This by itself seems not to be enough to determine whether it is
inside of (clojure.test/is (thrown? expr)) expression, though, due to
weirdness of clojure.test/is expansion.
  • Loading branch information
jafingerhut committed Dec 5, 2014
1 parent 8116bf6 commit 1b5d866
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
13 changes: 13 additions & 0 deletions resource/config.clj
Original file line number Diff line number Diff line change
Expand Up @@ -278,3 +278,16 @@
:arglists-for-linting
'([db table & options])
:reason "clojure.java.jdbc/insert! uses metadata to override the default value of :arglists for documentation purposes. This configuration tells Eastwood what the actual :arglists is, i.e. would have been without that."})

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Notes for warnings to disable in instaparse library, version 1.3.4
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(disable-warning
{:linter :unused-ret-vals
:for-value nil
:if-inside-macroexpansion-of #{'instaparse.gll/dprintln
'instaparse.gll/debug
'instaparse.gll/dpprint}
:within-depth 1
:reason "Instaparse macros debug, dprintln, and dpprint macroexpand to nil if debugging/printing are disabled."})
36 changes: 30 additions & 6 deletions src/eastwood/linters/unused.clj
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,10 @@ discarded inside null: null'."
(if (pass/void-method? (pass/get-method stmt))
:side-effect
:warn-if-ret-val-unused)
action)]
action)
linter (case location
:outside-try :unused-ret-vals
:inside-try :unused-ret-vals-in-try)]
(if (or (and stmt-in-try-body?
(= location :inside-try))
(and (not stmt-in-try-body?)
Expand All @@ -392,9 +395,8 @@ discarded inside null: null'."

(:lazy-fn :pure-fn :pure-fn-if-fn-args-pure :warn-if-ret-val-unused)
(util/add-loc-info loc
{:linter (case location
:outside-try :unused-ret-vals
:inside-try :unused-ret-vals-in-try)
{:linter linter
linter {:kind (:op stmt), :action action, :ast stmt}
:msg
(case action
:lazy-fn
Expand Down Expand Up @@ -487,6 +489,7 @@ discarded inside null: null'."
(pass/code-loc (pass/nearest-ast-with-loc stmt))))]
(util/add-loc-info loc
{:linter :unused-ret-vals
:unused-ret-vals {:kind (:op stmt), :ast stmt}
:msg (format "%s value is discarded%s: %s"
(op-desc (:op stmt))
(if name-found?
Expand Down Expand Up @@ -519,11 +522,32 @@ discarded inside null: null'."
(unused-ret-val-lint-result stmt "function call"
action v location)))))))


(defn unused-ret-vals* [location {:keys [asts] :as m} opt]
(let [warnings (unused-ret-vals-2 location m opt)]
(for [w warnings
:let [linter (:linter w)
info (get w linter)
ast (:ast info)
allow? (util/allow-warning w opt)]
:when allow?]
(do
(when (:debug-warning opt)
((util/make-msg-cb :debug opt)
(with-out-str
(println "This warning:")
(pp/pprint (dissoc w (:linter w)))
(println "was generated from code with the following enclosing macro expansions:")
(pp/pprint (->> (util/enclosing-macros ast)
(map #(dissoc % :ast :index)))))))
w))))


(defn unused-ret-vals [& args]
(apply unused-ret-vals-2 :outside-try args))
(apply unused-ret-vals* :outside-try args))

(defn unused-ret-vals-in-try [& args]
(apply unused-ret-vals-2 :inside-try args))
(apply unused-ret-vals* :inside-try args))


;; Unused metadata on macro invocations (depends upon macro
Expand Down
10 changes: 9 additions & 1 deletion src/eastwood/util.clj
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,10 @@ StringWriter."
conj (dissoc m :linter))
:wrong-arity
(assoc-in configs [linter (:function-symbol m)]
(dissoc m :linter :function-symbol))))
(dissoc m :linter :function-symbol))
(:unused-ret-vals :unused-ret-vals-in-try)
(update-in configs [linter]
conj (dissoc m :linter))))
{} warning-enable-config))


Expand Down Expand Up @@ -755,6 +758,11 @@ StringWriter."
suppress-conditions opt)))

:constant-test
(let [suppress-conditions (get-in opt [:warning-enable-config linter])]
(allow-warning-based-on-enclosing-macros
w linter "" suppress-conditions opt))

(:unused-ret-vals :unused-ret-vals-in-try)
(let [suppress-conditions (get-in opt [:warning-enable-config linter])]
(allow-warning-based-on-enclosing-macros
w linter "" suppress-conditions opt)))))
Expand Down

0 comments on commit 1b5d866

Please sign in to comment.