-
-
Notifications
You must be signed in to change notification settings - Fork 292
Open
Description
To upvote this issue, give it a thumbs up. See this list for the most upvoted issues.
- I have read the Clojure etiquette and will respect it when communicating on this platform.
Is your feature request related to a problem? Please describe.
When editing tests, it can be easy to accidentally remove or not include the comparison function in the given form
, leaving a literal in the form
position. This is very easy when you don't write a msg
so the two values aren't compared but used as form
and msg
:
(deftest example-test
(is #{} (set (some-func a b c)))
instead of:
(deftest example-test
(is (= #{} (set (some-func a b c))))
Describe the solution you'd like
A simple check that the first element to clojure.test/is
is a list or symbol, aka not a data "literal".
Describe alternatives you've considered
Do nothing?
Additional context
I have a working hook for this, idk how easy it is to port that to clj-kondo itself.
(defn literal?
[node]
(or (#{:map :set :string :vector :regex} (api/tag node))
(api/keyword-node? node)
(and (api/token-node? node) (number? (:value node)))))
(defn -is
[{:keys [node]}]
(let [[_is form] (:children node)]
(when (literal? form)
(let [{:keys [row col end-row end-col]} (meta form)]
(api/reg-finding! {:message "`is` asserted a literal."
:type :muncher/is-literal
:row row
:col col
:end-row end-row
:end-col end-col})))))
NoahTheDuke and borkdude
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
Medium priority (new / enhance)