Fork me on GitHub
#clj-kondo
<
2020-04-07
>
Marc O'Morain12:04:33

In my projects, I get a lot of false positives for accessing private vars from tests. Is there a neat trick to change lint rules between src and test ?

borkdude12:04:19

@marc-omorain The way to get around this is to use #'foo/bar instead of foo/bar

borkdude12:04:51

I bet this is CLJS?

Marc O'Morain12:04:31

Nope, is regular Clojure. Looking deeper, it comes from using bond/with-stub from https://github.com/circleci/bond

borkdude12:04:52

hmm, in clojure you can't even do this, the compiler will throw

Marc O'Morain12:04:00

The #' trick might work, I’ll check.

borkdude12:04:45

fwiw you can bind private vars in clojure: (binding [foo/*bar* 1] ...) even if foo/*bar* is private and clj-kondo knows about this, so linting as that one might work - although the syntax of your stubbing lib seems slightly different, so I'm not sure if that will work

borkdude12:04:22

@marc-omorain Another solution is to turn off the private linter locally:

(ns foo)

(def ^:private x 1)
x

(ns bar
  {:clj-kondo/config {:linters {:private-call {:level :off}}}}
  (:require foo))

foo/x

borkdude12:04:47

the linter is called :private-call which should be renamed to :private-var-usage or something in the future, but we will keep backwards compatibility

borkdude12:04:10

would have been easier if the with-stub macro syntax was exactly the same as binding

borkdude12:04:22

maybe that can still be retrofitted without breaking the current contract

Marc O'Morain12:04:21

Thanks 🙏 I’ll take a look at those options.