Skip to content
This repository has been archived by the owner on Oct 22, 2022. It is now read-only.

add config for mockery #2

Merged
merged 1 commit into from
Sep 10, 2020
Merged

add config for mockery #2

merged 1 commit into from
Sep 10, 2020

Conversation

andreyorst
Copy link
Contributor

Here are my hooks for mockery that I'm using for a some time already. I'm not sure what to put into example, so I've put code from mockery's readme.

@borkdude borkdude merged commit 6c481cd into clj-kondo:master Sep 10, 2020
@borkdude
Copy link
Member

borkdude commented Sep 10, 2020

@andreyorst I think it would be good to annotate the example with the expected clj-kondo output, so next time we change something, we can see if we broke something.

I can't really figure out what the last example should do:

;; what is this example supposed to do?
(with-mocks
  [foo {:target ::test-fn} ;; unresolved symbol foo?
   bar {}] ;; unresolved symbol bar?
  (example/test-fn 1)
  (example/test-fn-2 1 2)
  (is (= @foo
         {:called? true
          :call-count 1
          :call-args '(1)
          :call-args-list '[(1)]
          :target ::test-fn}))
  (is (= @bar
         {:called? true
          :call-count 1
          :call-args '(1 2)
          :call-args-list '[(1 2)]
          :target ::test-fn-2})))

@borkdude
Copy link
Member

One other piece of feedback:

When calling sexpr on a node, this isn't free, so if you do it 4 or 5 times in one hook, consider using let.
It's even better to avoid calling sexpr when possible since it can crash on malformed nodes like {:a}.

@andreyorst andreyorst deleted the mockery branch September 11, 2020 17:11
@andreyorst
Copy link
Contributor Author

I can't really figure out what the last example should do

I wanted to display some errors reported by the hook, but also was unsure how to handle false positives of foo and bar unresolviness. Since these things should be linted as bindings, they are highlighted as unresolved when we have any error, so I've though maybe we should return some kind of expanded form in the catch as well, to highlight only the errors from the hook and prevent further linting of the code.

@andreyorst
Copy link
Contributor Author

When calling sexpr on a node, this isn't free, so if you do it 4 or 5 times in one hook, consider using let.
It's even better to avoid calling sexpr when possible since it can crash on malformed nodes like {:a}.

Got it, although I'm not sure how to lint complex expansions and avoid calling sexpr when we do need to check things to be qualified for example.

Should I open another PR with fixes for the problems mentioned here?

@borkdude
Copy link
Member

@andreyorst I've been making a few updates to the hooks already.

@borkdude
Copy link
Member

@andreyorst Also this issue should take care of relying less on api/sexpr:

clj-kondo/clj-kondo#1006

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants