diff --git a/cases/testcases/clojure_test.clj b/cases/testcases/clojure_test.clj new file mode 100644 index 00000000..4a433940 --- /dev/null +++ b/cases/testcases/clojure_test.clj @@ -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 +)))) diff --git a/changes.md b/changes.md index 7561f0a3..140e7622 100644 --- a/changes.md +++ b/changes.md @@ -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 diff --git a/resource/eastwood/config/clojure.clj b/resource/eastwood/config/clojure.clj index c67dc3f9..cf922994 100644 --- a/resource/eastwood/config/clojure.clj +++ b/resource/eastwood/config/clojure.clj @@ -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->>} diff --git a/src/eastwood/linters/typos.clj b/src/eastwood/linters/typos.clj index fc87905d..66a74910 100644 --- a/src/eastwood/linters/typos.clj +++ b/src/eastwood/linters/typos.clj @@ -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 @@ -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?" diff --git a/test/eastwood/lint_test.clj b/test/eastwood/lint_test.clj index c85b9710..5ff03aa3 100644 --- a/test/eastwood/lint_test.clj +++ b/test/eastwood/lint_test.clj @@ -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}))))))