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

Test expression is always true/false when setting :min-count for spec/every family of functions #435

Closed
clov0 opened this issue Jun 14, 2022 · 3 comments

Comments

@clov0
Copy link

clov0 commented Jun 14, 2022

Eastwood keeps getting me warnings for these spec lines :

(spec/map-of
    (spec/spec string?
               :gen (fn [] (gen/fmap
                             #(apply str %)
                             (gen/vector
                               gen/char-alpha
                               5 20))))
    (spec/coll-of
      (spec/tuple ::i-commons/source ::sub-type)
      :into #{}
      :min-count 2
      :gen-max 7)
    :min-count 2
    :gen-max   8)

the error is :

== Linting hermes.van-buren.core.event.rlc.model ==
src/hermes/van_buren/core/event/rlc/model.clj:201:3: constant-test: Test expression is always logical true or always logical false: 2 in form (if or__5533__auto__ or__5533__auto__ (clojure.core/or 0)).
src/hermes/van_buren/core/event/rlc/model.clj:201:3: constant-test: Test expression is always logical true or always logical false: nil in form (if nil (clojure.core/inc nil) 2).
src/hermes/van_buren/core/event/rlc/model.clj:201:3: constant-test: Test expression is always logical true or always logical false: nil in form (if or__5533__auto__ or__5533__auto__ (clojure.core/or java.lang.Integer/MAX_VALUE)).

Removing the :min-count option from the spec/map-of and the likes fixes the warning.

@vemv
Copy link
Collaborator

vemv commented Jun 14, 2022

Hi! Thanks for the report.

Are you using Eastwood latest?

After confirming that, are you familiar with the notion of "config files"? Here are the ones targeting clojure.spec:

(disable-warning
{:linter :suspicious-expression
:for-macro 'clojure.core/and
:if-inside-macroexpansion-of #{'clojure.spec/every 'clojure.spec.alpha/every
'clojure.spec/and 'clojure.spec.alpha/and
'clojure.spec/keys 'clojure.spec.alpha/keys
'clojure.spec/coll-of 'clojure.spec.alpha/coll-of}
:within-depth 6
:reason "clojure.spec's macros `keys`, `every`, and `and` often contain `clojure.core/and` invocations with only one argument."})
(disable-warning
{:linter :constant-test
:for-macro 'clojure.core/or
:if-inside-macroexpansion-of #{'clojure.spec/coll-of 'clojure.spec.alpha/coll-of}
:within-depth 8
:reason "clojure.spec's `coll-of` can contain `clojure.core/or` invocations with only one argument."})

It might be that they need to be updated in face of clojure.spec changes.

Feel free to play with adding your own :config-files [,,,]:

eastwood/README.md

Lines 409 to 413 in 5a55eff

Similarly you can specify `:config-files` in the options map to give
additional files to read. These are filenames that can be anywhere
in your file system, specified as strings, or if Eastwood is invoked
from the REPL, anything that can be passed to
`clojure.java.io/reader`.

If you find something that works, feel free to share. Otherwise I'll tackle this asap but not urgently.

Cheers - V

@clov0
Copy link
Author

clov0 commented Jun 14, 2022

Thanks vemv,
It seems adding the spec/every to the :if-inside-macroexpansion-of the disable-warning at line 52 fixes the issue :

(disable-warning
  {:linter                      :constant-test
   :for-macro                   'clojure.core/or
   :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."})

vemv added a commit that referenced this issue Jun 17, 2022
@vemv vemv closed this as completed in 7a7dbc0 Jun 17, 2022
@vemv
Copy link
Collaborator

vemv commented Jun 17, 2022

1.2.4 is being released this morning!

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

No branches or pull requests

2 participants