Skip to content

Commit

Permalink
enable deps linter by default
Browse files Browse the repository at this point in the history
  • Loading branch information
roman01la committed Feb 3, 2023
1 parent 5567dce commit 25cc16a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
5 changes: 2 additions & 3 deletions core/src/uix/linter.clj
Original file line number Diff line number Diff line change
Expand Up @@ -482,11 +482,10 @@
;; when a reference to a function passed into a hook, should be an inline function instead
(not (fn-literal? f)) [::inline-function {:source form :env (find-env-for-form ::inline-function form)}]

(vector? deps)
(and (vector? deps) (not (:lint/disable (meta deps))))
(let [[missing-deps declared-unnecessary-deps suggested-deps] (find-missing-and-unnecessary-deps env f deps)]
;; when hook function is referencing vars from out scope that are missing in deps vector
(when (or (and (:lint-deps (meta deps)) (seq missing-deps))
(seq declared-unnecessary-deps))
(when (or (seq missing-deps) (seq declared-unnecessary-deps))
[::missing-deps {:missing-deps missing-deps
:unnecessary-deps declared-unnecessary-deps
:suggested-deps suggested-deps
Expand Down
8 changes: 4 additions & 4 deletions core/test/uix/linter_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
(:require [uix.core :refer [defui $]]))

(defui test-missing-deps [{:keys [x]}]
(uix.core/use-effect (fn [] x) ^:lint-deps []))
(uix.core/use-effect (fn [] x) []))

(defui test-missing-deps-disabled [{:keys [z]}]
(uix.core/use-effect (fn [] z) []))
(uix.core/use-effect (fn [] z) ^:lint/disable []))

(defui test-unnecessary-deps []
(let [ref (uix.core/use-ref)
Expand All @@ -21,7 +21,7 @@
(fn []
(let [y 1]
y))
^:lint-deps []))
[]))

(defui test-fn-ref-passed-into-hook []
(uix.core/use-effect identity))
Expand Down Expand Up @@ -81,4 +81,4 @@
(uix.core/use-effect
(fn []
(prn dsym dsym dsym))
^:lint-deps []))
[]))
2 changes: 1 addition & 1 deletion docs/code-linting.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ The rule here is to call the function at the top level of the component body.

### A hook doesn't meet its dependencies requirements

> This rule is currently experimental and disabled, it's possible to opt-in by adding `^:lint-deps` meta onto in front of the deps vector
> This rule is currently experimental, to opt-out add `^:lint/disable` meta in front of the deps vector
This rule will check for missing and unnecessary dependencies and suggest a correct deps vector.

Expand Down

0 comments on commit 25cc16a

Please sign in to comment.