From 177080ef0583882dae440df9d4a63d2f13e669bb Mon Sep 17 00:00:00 2001 From: vemv Date: Fri, 17 Jun 2022 05:33:42 +0200 Subject: [PATCH] Fix false positive for `clojure.spec.alpha/every` Fixes https://github.com/jonase/eastwood/issues/435 --- .../constant_test/spec_every/green.clj | 21 +++++++++++++++++++ changes.md | 7 +++++++ resource/eastwood/config/clojure.clj | 5 ++++- test/eastwood/lint_test.clj | 11 +++++++++- 4 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 cases/testcases/constant_test/spec_every/green.clj diff --git a/cases/testcases/constant_test/spec_every/green.clj b/cases/testcases/constant_test/spec_every/green.clj new file mode 100644 index 00000000..ef2add71 --- /dev/null +++ b/cases/testcases/constant_test/spec_every/green.clj @@ -0,0 +1,21 @@ +(ns testcases.constant-test.spec-every.green + (:require + [clojure.spec.gen.alpha :as gen] + [clojure.test :refer [are deftest is join-fixtures testing use-fixtures]] + [clojure.spec.alpha :as spec])) + +;; https://github.com/jonase/eastwood/issues/435 +(spec/def ::some-spec (spec/map-of + (spec/spec string? + :gen (fn [] (gen/fmap + #(apply str %) + (gen/vector + gen/char-alpha + 5 20)))) + (spec/coll-of + (spec/tuple ::source ::sub-type) + :into #{} + :min-count 2 + :gen-max 7) + :min-count 2 + :gen-max 8)) diff --git a/changes.md b/changes.md index dde4ba27..d0e1d449 100644 --- a/changes.md +++ b/changes.md @@ -1,3 +1,10 @@ +## Changes from 1.2.3 to + +#### Bugfixes + +* Fix false positive for `clojure.spec.alpha/every`. + * Closes https://github.com/jonase/eastwood/issues/435 + ## Changes from 1.2.2 to 1.2.3 #### Bugfixes diff --git a/resource/eastwood/config/clojure.clj b/resource/eastwood/config/clojure.clj index d01334ce..b467853e 100644 --- a/resource/eastwood/config/clojure.clj +++ b/resource/eastwood/config/clojure.clj @@ -52,7 +52,10 @@ (disable-warning {:linter :constant-test :for-macro 'clojure.core/or - :if-inside-macroexpansion-of #{'clojure.spec/coll-of 'clojure.spec.alpha/coll-of} + :if-inside-macroexpansion-of #{'clojure.spec/coll-of + 'clojure.spec.alpha/coll-of + 'clojure.spec/every + 'clojure.spec.alpha/every} :within-depth 8 :reason "clojure.spec's `coll-of` can contain `clojure.core/or` invocations with only one argument."}) diff --git a/test/eastwood/lint_test.clj b/test/eastwood/lint_test.clj index de89e5bf..98074404 100644 --- a/test/eastwood/lint_test.clj +++ b/test/eastwood/lint_test.clj @@ -373,7 +373,16 @@ relative to a specific macroexpansion" ;; Suggested an improvement upstream here: ;; https://ask.clojure.org/index.php/10712/minor-performance-improvement-initial-values-known-compile #{'testcases.constant-test.some-thread-first.green} {:some-warnings false} - #{'testcases.constant-test.some-thread-last.green} {:some-warnings false}))) + #{'testcases.constant-test.some-thread-last.green} {:some-warnings false})) + + (testing "https://github.com/jonase/eastwood/issues/435" + (are [input expected] (testing input + (is (= (assoc expected :some-errors false) + (-> sut/default-opts + (assoc :namespaces input) + (sut/eastwood)))) + true) + #{'testcases.constant-test.spec-every.green} {:some-warnings false}))) (deftest unused-fn-args-test (testing "fn args within defmulti, see https://github.com/jonase/eastwood/issues/1"