2023-01-05 14:58:37 +00:00
|
|
|
{:lint-as {status-im.utils.views/defview clojure.core/defn
|
|
|
|
status-im.utils.views/letsubs clojure.core/let
|
|
|
|
reagent.core/with-let clojure.core/let
|
|
|
|
status-im.utils.fx/defn clj-kondo.lint-as/def-catch-all
|
|
|
|
utils.re-frame/defn clj-kondo.lint-as/def-catch-all
|
|
|
|
quo.react/with-deps-check clojure.core/fn
|
|
|
|
quo.previews.preview/list-comp clojure.core/for
|
|
|
|
status-im.utils.styles/def clojure.core/def
|
|
|
|
status-im.utils.styles/defn clojure.core/defn
|
|
|
|
test-helpers.unit/deftest-sub clojure.core/defn
|
|
|
|
taoensso.tufte/defnp clojure.core/defn}
|
2022-12-20 13:42:50 +00:00
|
|
|
:linters {:consistent-alias {:level :error
|
|
|
|
:aliases {clojure.string string
|
2023-01-05 13:54:32 +00:00
|
|
|
clojure.set set
|
|
|
|
clojure.walk walk
|
2022-12-20 13:42:50 +00:00
|
|
|
taoensso.timbre log}}
|
Lint & fix some shadowed core Clojure(Script) vars (#16500)
It's well known that shadowing core Clojure vars can lead to unexpected bugs. In
fact, it's a common source of bugs in other languages too. In the status-mobile
repository there are, in total, 562 shadowed vars, ~500 are core vars. Excluding
the "old code" we still have 285 offenders.
In status-mobile I've already seen two bugs caused by shadowed vars, both with
the shadowed var "name". But probably other problems happened in the past, and
others will happen in the future if we don't do something about this. This PR is
also my response to my frustration trying to review PRs and checking for
shadowed vars, humans were not meant for that!
In this commit we are enabling ":shadowed-var" to lint certain (not all) core
vars as errors (not warnings). In future PRs we can gradually unshadow more
vars. For the record, name is shadowed 40 times in the new code and 130 in
total, and type is shadowed 93 times in the new code and 124 in total!
What about non-core vars, should we allow shadowing? There are ~70 non-core
shadowed vars. In my opinion, we should also lint and disallow shadowing
non-core vars, since it may cause the same kind of bugs of shadowing core vars.
But this decision can be left for another moment/issue, after we have fixed the
most prominent problem of shadowing core vars.
Which vars are unshadowed in this PR? I fixed 62 errors and unshadowed
cljs.core/iter, cljs.core/time, cljs.core/count, cljs.core/key,
clojure.core/key.
Resources:
- [clj-kondo linter: shadowed-var](https://github.com/clj-kondo/clj-kondo/blob/master/doc/linters.md#shadowed-var)
2023-07-06 10:28:07 +00:00
|
|
|
:shadowed-var {:level :error
|
|
|
|
;; We temporarily use :include to define an
|
|
|
|
;; allowlist of core Clojure vars. In the
|
|
|
|
;; future, as we progressively fix shadowed
|
|
|
|
;; vars, we should be able to delete this
|
|
|
|
;; option and lint all vars.
|
Unshadow more Clojure core vars (#16777)
This is a continuation of https://github.com/status-im/status-mobile/pull/16500 (Lint
& fix some shadowed core Clojure(Script) vars).
Notes: As a reminder, the goal is to eventually disallow shadowing core Clojure
vars entirely, but to get there and avoid rebase hell and regressions, we need
to do in smaller steps, especially because we can't safely automate the process
of unshadowing vars.
We are already down from ~500 shadowed core vars to 350 in total.
Why is this PR is using names such as "s", "v" or "sym"? Names such as s or v
are the so called idiomatic names, and are listed in the Clojure Style Guide
https://guide.clojure.style/#idiomatic-names. I used them whenever I felt
appropriate. For the var cljs.core/symbol I opted to use sym, even though the
symbol in question is not necessarily a Clojure symbol, I think the alias
conveys the meaning well enough
(https://www.clojure.org/guides/learn/syntax#_symbols_and_idents).
New vars linted:
- comparator
- identity
- str
- symbol
- val
Outstanding shadowed vars include type, name, hash, comp.
2023-07-26 11:26:12 +00:00
|
|
|
:include [comparator
|
|
|
|
count
|
|
|
|
identity
|
|
|
|
iter
|
|
|
|
key
|
|
|
|
str
|
|
|
|
symbol
|
|
|
|
time
|
|
|
|
val]}
|
2022-12-20 13:42:50 +00:00
|
|
|
:invalid-arity {:skip-args [status-im.utils.fx/defn utils.re-frame/defn]}
|
|
|
|
;; TODO remove number when this is fixed
|
|
|
|
;; https://github.com/borkdude/clj-kondo/issues/867
|
|
|
|
:unresolved-symbol {:exclude [PersistentPriorityMap.EMPTY
|
|
|
|
number
|
|
|
|
status-im.test-helpers/restore-app-db]}}
|
|
|
|
:config-in-ns {mocks.js-dependencies {:linters {:clojure-lsp/unused-public-var {:level :off}}}}}
|