From 2d11b818b8948935feb0689387bf082b64e49db8 Mon Sep 17 00:00:00 2001 From: roman01la Date: Fri, 21 Apr 2023 13:33:54 +0300 Subject: [PATCH] linter: account for shadowed JS globals, fixes #106 --- core/deps.edn | 12 ++++++------ core/src/uix/compiler/attributes.cljs | 2 +- core/src/uix/linter.clj | 3 ++- core/test/uix/linter_test.clj | 5 ++++- core/test/uix/linter_test.cljs | 7 +++++++ 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/core/deps.edn b/core/deps.edn index f0b9bf45..c8d249db 100644 --- a/core/deps.edn +++ b/core/deps.edn @@ -8,9 +8,9 @@ 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"}}} @@ -18,7 +18,7 @@ :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"}}}}} diff --git a/core/src/uix/compiler/attributes.cljs b/core/src/uix/compiler/attributes.cljs index e136a353..3b4dd80b 100644 --- a/core/src/uix/compiler/attributes.cljs +++ b/core/src/uix/compiler/attributes.cljs @@ -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` diff --git a/core/src/uix/linter.clj b/core/src/uix/linter.clj index 8d165623..87d22a98 100644 --- a/core/src/uix/linter.clj +++ b/core/src/uix/linter.clj @@ -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))) diff --git a/core/test/uix/linter_test.clj b/core/test/uix/linter_test.clj index 87ad8ac1..4dd35e24 100644 --- a/core/test/uix/linter_test.clj +++ b/core/test/uix/linter_test.clj @@ -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 === diff --git a/core/test/uix/linter_test.cljs b/core/test/uix/linter_test.cljs index 5ba3d671..adeb2560 100644 --- a/core/test/uix/linter_test.cljs +++ b/core/test/uix/linter_test.cljs @@ -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])))