Skip to content

Commit

Permalink
Fix various false positives for clojure.test (#373)
Browse files Browse the repository at this point in the history
Close #116 (nothing had to be fixed; only proves that the bug is now absent)
Fixes #207
Fixes #313
  • Loading branch information
vemv authored May 1, 2021
1 parent b5f4625 commit 5d5b084
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 2 deletions.
26 changes: 26 additions & 0 deletions cases/testcases/clojure_test.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
(ns testcases.clojure-test
(:require
[clojure.test :refer [are assert-expr deftest do-report is join-fixtures testing use-fixtures]]))

(defmethod assert-expr 'truthy?
[msg [pred v]]
`(do-report (if ~v
{:type :pass, :message ~msg}
{:type :fail, :message ~msg})))

(defn throws-exception []
(throw (ex-info "" {})))

(defn func [f] "")

;; https://github.com/jonase/eastwood/issues/116
(deftest exercises-thrown
(is (thrown? Exception (throws-exception))))

;; https://github.com/jonase/eastwood/issues/313
(deftest exercises-truthy
(is (truthy? 42)))

;; https://github.com/jonase/eastwood/issues/207
(deftest b-test
(is (instance? String (func +))))
4 changes: 4 additions & 0 deletions changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

#### Bugfixes

* Fix false positive `suspicious-expression` for `clojure.test/is`
* Fixes https://github.com/jonase/eastwood/issues/207
* Support `clojure.test/assert-expr` better
* Fixes https://github.com/jonase/eastwood/issues/313
* Vanilla `defn`s having `:test` metadata don't result in false positives for the `:bad-arglists` linter anymore.

## Changes from 0.3.14 to 0.4.0
Expand Down
6 changes: 6 additions & 0 deletions resource/eastwood/config/clojure.clj
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@
:within-depth 8
:reason "clojure.spec's `coll-of` can contain `clojure.core/or` invocations with only one argument."})

(disable-warning
{:linter :constant-test
:if-inside-macroexpansion-of #{'clojure.test/is}
:within-depth 2
:reason "`is` can contain arbitrary exprs that are \"constant-looking\". They typically intend to exercise a predicate."})

(disable-warning
{:linter :constant-test
:if-inside-macroexpansion-of #{'clojure.core/cond-> 'clojure.core/cond->>}
Expand Down
5 changes: 3 additions & 2 deletions src/eastwood/linters/typos.clj
Original file line number Diff line number Diff line change
Expand Up @@ -692,7 +692,7 @@
:init ; in :op :binding
:args ; in :op :invoke for clojure.core/list
)
num-args (count fn-args-ast-vec)
num-args (some-> fn-args-ast-vec count)
fn-var (-> let-bindings-ast
second ; in vector of 2 bindings
:init ; in :op :binding
Expand Down Expand Up @@ -726,7 +726,8 @@
;; (println (format " loc=%s" loc))
;; )
]
:when (contains? suspicious-args num-args)]
:when (and num-args
(contains? suspicious-args num-args))]
{:loc loc
:linter :suspicious-expression
:msg (format "%s called with %d args. (%s%s) always returns %s. Perhaps there are misplaced parentheses?"
Expand Down
5 changes: 5 additions & 0 deletions test/eastwood/lint_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,8 @@ relative to a specific macroexpansion"

"only `true` is deemed an apt :qualifier value"
#{'testcases.are-true.red-three} {:some-warnings true}))

(deftest clojure-test-test
(testing "Some reported false positives against clojure.test"
(is (= {:some-warnings false}
(eastwood.lint/eastwood (assoc eastwood.lint/default-opts :namespaces #{'testcases.clojure-test}))))))

0 comments on commit 5d5b084

Please sign in to comment.