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
Warn about let shadowing vars #646
Comments
I believe it would be insightful for when shadowing the "wrong" thing, with the above case being a function, especially from |
Maybe a configurable list of fully qualified var names like |
https://twitter.com/souenzzo/status/1289967423039270912 This user suggests warning only when the local binding is used in a function call:
|
https://twitter.com/glenathan/status/1289973899837321216
This would just be an enhancement to the type checking. |
https://github.com/dakrone/lein-bikeshed has an option to warn about function args shadowing core functions |
From Alex Miller: https://twitter.com/puredanger/status/1290015991477366784
|
I like the idea of a warning by default when calling a shadowed symbol. My real-world example above would have been caught by that, as well as Alex Miller's example (which I've also encountered in real life!) An optional warning when |
I sometimes write partially applied shadow variants in |
It will be turned off by default, because else this would "break" a lot of valid code. I think an |
I think a "Name is forever nom." |
I think this linter should also warn about other vars than clojure.core. I was bitten by overriding a var in the current namespace with a local more than once (in fact, it just happened to me a few seconds ago). Proposed config: {:shadowed-var {:include [clojure.core my.ns/foo] ;; only warn for these, unqualified symbol = namespace, qualified symbol = var
:exclude [my.ns/foo] ;; don't warn about these vars
;; when include and exclude aren't set, warn on every shadowed var
:level :off ;; default, set to :warning to enable linter
:suggest {clojure.core/name nom}
}} |
New simplified version. I think I'll only support the (ns foo
{:clj-kondo/config
'{:linters {:shadowed-var
{:level :warning
:exclude [ns]
:suggest {name nom}}}}})
(defn foo [ns name] ;; warning
[ns name])
(let [name 1] ;; warning
name)
(defn bar [ns #_:clj-kondo/ignore name] ;; no warning
[ns name]) |
Without :suggest the message will be just “Shadowing var: clojure.core/name”? |
Correct. |
You can download binaries by going to the CircleCI artifacts of the commits of this branch: https://github.com/borkdude/clj-kondo/tree/shadow-binding-646 if you want to try this out. |
Merged to master: https://github.com/borkdude/clj-kondo/blob/master/doc/config.md#shadowed-var |
A friend of mine just spent an hour wondering why
filter
was not working properly. He just realised that he had code like(let [filter {a: 1}] … (filter pred some-list))
. This kind of shadowing has bitten me before too when I was learning.It would be great if clj-kondo could flag this as a warning, since it's almost never what you want.
The text was updated successfully, but these errors were encountered: