diff --git a/resource/config.clj b/resource/config.clj index f10739f4..0dc6b6be 100644 --- a/resource/config.clj +++ b/resource/config.clj @@ -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."}) diff --git a/src/eastwood/linters/unused.clj b/src/eastwood/linters/unused.clj index 72e4c197..afe693b4 100644 --- a/src/eastwood/linters/unused.clj +++ b/src/eastwood/linters/unused.clj @@ -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?) @@ -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 @@ -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? @@ -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 diff --git a/src/eastwood/util.clj b/src/eastwood/util.clj index a516ce21..3df5c48d 100644 --- a/src/eastwood/util.clj +++ b/src/eastwood/util.clj @@ -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)) @@ -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)))))