Skip to content

Commit

Permalink
linter: account for shadowed JS globals, fixes #106
Browse files Browse the repository at this point in the history
  • Loading branch information
roman01la committed Apr 21, 2023
1 parent ec1a80a commit 2d11b81
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 9 deletions.
12 changes: 6 additions & 6 deletions core/deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
hiccup/hiccup {:mvn/version "1.0.5"}
rum/rum {:mvn/version "0.11.2"}}}
:test {:extra-paths ["test" "dev"]
:extra-deps {org.clojure/clojure {:mvn/version "1.10.3"}
org.clojure/clojurescript {:mvn/version "1.10.879"}
thheller/shadow-cljs {:mvn/version "2.15.5"}
:extra-deps {org.clojure/clojure {:mvn/version "1.11.1"}
org.clojure/clojurescript {:mvn/version "1.11.60"}
thheller/shadow-cljs {:mvn/version "2.23.1"}
uix.dom/uix.dom {:local/root "../dom"}
cljsjs/react-dom-server {:mvn/version "16.13.1-0"}
clj-diffmatchpatch/clj-diffmatchpatch {:mvn/version "0.0.9.3"}}}
:release {:extra-deps {appliedscience/deps-library {:mvn/version "0.3.4"}}
:main-opts ["-m" "deps-library.release"]}

:examples {:extra-paths ["dev"]
:extra-deps {org.clojure/clojure {:mvn/version "1.10.3"}
org.clojure/clojurescript {:mvn/version "1.10.879"}
thheller/shadow-cljs {:mvn/version "2.15.5"}
:extra-deps {org.clojure/clojure {:mvn/version "1.11.1"}
org.clojure/clojurescript {:mvn/version "1.11.60"}
thheller/shadow-cljs {:mvn/version "2.23.1"}
uix.dom/uix.dom {:local/root "../dom"}}}}}
2 changes: 1 addition & 1 deletion core/src/uix/compiler/attributes.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@
(or class props-class)
(assoc :class (class-names class props-class)))))

(defn convert-props
(defn ^js convert-props
"Converts `props` Clojure map into JS object suitable for
passing as `props` object into `React.createElement`
Expand Down
3 changes: 2 additions & 1 deletion core/src/uix/linter.clj
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,8 @@
(->> (ast->seq ast)
(filter #(and (= :local (:op %)) ;; should be a local
(get-in env [:locals (:name %) :name]) ;; from an outer scope
(-> % :info :shadow not) ;; but not a local shadowing locals from outer scope
(or (-> % :info :shadow not) ;; but not a local shadowing locals from outer scope
(-> % :info :shadow :ns (= 'js))) ;; except when shadowing JS global
(not (deps (:name %))))) ;; and not declared in deps vector
(map :name)
distinct)))
Expand Down
5 changes: 4 additions & 1 deletion core/test/uix/linter_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@
(is (str/includes? out-str "Inline styles are not allowed, put them into a CSS file instead")))

(testing "should dedupe missing deps"
(is (not (str/includes? out-str "[dsym dsym dsym]"))))))
(is (not (str/includes? out-str "[dsym dsym dsym]"))))

(testing "#106, should report when missing dep is shadowed JS global"
(is (str/includes? out-str "React Hook has missing dependencies: [document]")))))

;; === Subscribe call in JVM ===

Expand Down
7 changes: 7 additions & 0 deletions core/test/uix/linter_test.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,10 @@
(fn []
(prn dsym dsym dsym))
[]))

(defui test-106 [{:keys [x]}]
(let [document 1]
(uix.core/use-effect
(fn []
(println x document))
[x])))

0 comments on commit 2d11b81

Please sign in to comment.