Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unused-ret-vals always warns about (is (thrown? Exception expr)) forms? #116

Closed
jafingerhut opened this issue Dec 4, 2014 · 2 comments · Fixed by #373
Closed

unused-ret-vals always warns about (is (thrown? Exception expr)) forms? #116

jafingerhut opened this issue Dec 4, 2014 · 2 comments · Fixed by #373

Comments

@jafingerhut
Copy link
Collaborator

Because the expr's return value is ignored? It seems pretty clear that the intention here is to verify that trying to evaluate the form throws an exception, so ignoring the return value seems quite reasonable here. Try to find a precise way to disable such warnings in this case.

One example warning of this kind:

src/test/clojure/clojure/data/finger_tree/tests.clj:120:18: unused-ret-vals-in-try: Pure function call return value is discarded inside body of try: (assoc (apply counted-double-list (range len)) n :x)

Another example:

src/test/clojure/clojure/data/json_compat_0_1_test.clj:69:26: unused-ret-vals-in-try: Should use return value of function call, but it is discarded inside body of try: (read-json "{26:"z"")

It should be possible to eliminate these via the enclosing-macros customization technique already implemented for suspicious-expression and constant-test linters. Overlap with #118 if so.

@jafingerhut
Copy link
Collaborator Author

Also consider suppressing all wrong-arity warnings inside of (is (thrown? exception expr)) forms, since it is reasonably common for expr to be a form that has a wrong number of args to a function call, to test that an exception is thrown.

@muhuk
Copy link

muhuk commented Mar 24, 2016

By trial and error the code below seems to disable this warning:

(disable-warning
 {:linter :unused-ret-vals-in-try
  :for-macro 'clojure.core/try
  :if-inside-macroexpansion-of #{'clojure.test/is}
  :within-depth 2
  :reason "thrown? & thrown-with-msg? doesn't care about return value by design."})

But unfortunately it disables for all is expansions, not just the case of thrown?/thrown-with-msg?.

bgalartza added a commit to gethop-dev/object-storage.s3 that referenced this issue Jul 8, 2019
Eastwood complains about unused returning values inside a try block. In our case, we just want
to check if an exception is thrown, so we don't need the returned value. This is known issue:
jonase/eastwood#116
vemv added a commit to reducecombine/eastwood that referenced this issue May 1, 2021
Close jonase#116 (nothing had to be fixed; only proves that the bug is now absent)
Fixes jonase#207
Fixes jonase#313
vemv added a commit to reducecombine/eastwood that referenced this issue May 1, 2021
Close jonase#116 (nothing had to be fixed; only proves that the bug is now absent)
Fixes jonase#207
Fixes jonase#313
slipset pushed a commit that referenced this issue May 1, 2021
Close #116 (nothing had to be fixed; only proves that the bug is now absent)
Fixes #207
Fixes #313
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants