Skip to content
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

unused bindings #173

Closed
9 tasks done
borkdude opened this issue May 17, 2019 · 15 comments
Closed
9 tasks done

unused bindings #173

borkdude opened this issue May 17, 2019 · 15 comments
Labels
enhancement New feature or request

Comments

@borkdude
Copy link
Member

borkdude commented May 17, 2019

Report unused bindings

TODO:

  • suppress warning when using a binding that starts with an underscore, e.g. (fn [_] "foo")
  • false positive: (fn [{:keys [x] :or {x 1}}] x)
  • false positive: (let [{:keys [patient/id order/id]} {}] id) (both are unused, while in reality only one is unused)
  • support loop, if-let, when-let
  • support for for, doseq, with-open
  • handle :let, :when and :while in for and doseq
  • look more closely to defmacro locals + syntax-quote
  • emit warnings when something is not a valid binding form
  • fix false positives with locals used in metadata

Linux binary: https://3192-176829714-gh.circle-artifacts.com/0/release/clj-kondo-2019.05.27-alpha-SNAPSHOT-linux-amd64.zip
Mac binary: https://3194-176829714-gh.circle-artifacts.com/0/release/clj-kondo-2019.05.27-alpha-SNAPSHOT-macos-amd64.zip

@borkdude borkdude added the enhancement New feature or request label May 17, 2019
@borkdude
Copy link
Member Author

borkdude commented May 28, 2019

@mynomoto A very preliminary version of unused bindings is supported in this linux binary (EDIT: link moved to opening comment)
Since you asked for this feature, I'd appreciate it if you could test a bit with it and report your findings. As of now it only reports unused bindings in let, if-let, when-let, fn, loop and defn.
unused-binding

@mynomoto
Copy link
Contributor

Sure, will do and report.

@mynomoto
Copy link
Contributor

Found one false positive

(defn false-positive-bind
  [{:keys [:x]}]
  (if-let [x (identity x)]
    x
    :y))

Reports: cljkondo.clj:2:12: warning: unused binding x

@mynomoto
Copy link
Contributor

Changing if-let to when-let causes the same problem. It's not related to the destructuring of :x.

@borkdude
Copy link
Member Author

@mynomoto Please ensure you're using the latest binary linked in the top comment. I believe I've already fixed this in the last few hours :-).

@mynomoto
Copy link
Contributor

I just finished linting a project from work and no more false positives after the upgrade. :shipit: Thanks!

@mynomoto
Copy link
Contributor

I would love for this to cover cats.core/mlet (it works just like a let) but I'm not sure if you intend to or not in this first version. I wonder if that could be configurable for well behaved forms.

@borkdude
Copy link
Member Author

@mynomoto That should work when using :lint-as {cats.core/mlet clojure.core/let} in the configuration.

@borkdude
Copy link
Member Author

Fixed with 6d9020a

@mynomoto
Copy link
Contributor

mynomoto commented May 30, 2019

@mynomoto That should work when using :lint-as {cats.core/mlet clojure.core/let} in the configuration.

Cool, I will try that! Thanks!

@mynomoto
Copy link
Contributor

mynomoto commented May 30, 2019

Found a false positive related to metadata:

(defn false-positive-metadata
  [a b]
  ^{:key (str a b)} [:other])

cljkondo.clj:2:4: warning: unused binding a
cljkondo.clj:2:6: warning: unused binding b

@borkdude
Copy link
Member Author

Good catch! I'll look into it.

@mynomoto
Copy link
Contributor

The false positive fix worked, as the :lint-as configuration. Thanks!

@svdo
Copy link
Contributor

svdo commented May 31, 2019

I think I'm getting a false positive on my CLJS code. I'm using a default import (:require ["react-native-view-overflow" :default ViewOverflow]) and this gives a warning: "namespace react-native-view-overflow is required but never used".

Other than that no surprises :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants