diff --git a/core/src/uix/linter.clj b/core/src/uix/linter.clj index 99e6ce5a..830a584c 100644 --- a/core/src/uix/linter.clj +++ b/core/src/uix/linter.clj @@ -17,6 +17,16 @@ (def ^:dynamic *in-branch?* false) (def ^:dynamic *in-loop?* false) +(defn- read-config [path] + (let [file (io/file ".uix/config.edn") + config (try + (if (.isFile file) + (clojure.edn/read-string (slurp file)) + {}) + (catch Exception e + {}))] + (get-in config path))) + (defn hook? [sym] (and (symbol? sym) (some? (re-find #"^use-|use[A-Z]" (name sym))))) @@ -79,8 +89,14 @@ (uix-element? expr) (missing-key? expr) (list? expr) (recur (last expr)))) +(def react-key-rule-enabled? + (if-some [v (read-config [:linters :react-key :enabled?])] + v + true)) + (defn- lint-missing-key! [kv sym body] - (when (contains? (get mapping-forms kv) sym) + (when (and react-key-rule-enabled? + (contains? (get mapping-forms kv) sym)) (lint-missing-key!* (last body)))) (declare lint-body!*) @@ -230,16 +246,6 @@ (symbol? (first form)) (= "subscribe" (name (first form))))) -(defn- read-config [path] - (let [file (io/file ".uix/config.edn") - config (try - (if (.isFile file) - (clojure.edn/read-string (slurp file)) - {}) - (catch Exception e - {}))] - (get-in config path))) - (defn- read-re-frame-config [] (-> (reduce-kv (fn [ret k v] (update ret v (fnil conj #{}) k)) @@ -247,11 +253,13 @@ (read-config [:linters :re-frame :resolve-as])) (get 're-frame.core/subscribe))) +(def re-frame-config + (read-re-frame-config)) + (defn lint-re-frame! [form env] - (let [config (read-re-frame-config) - sources (->> (uix.lib/find-form rf-subscribe-call? form) + (let [sources (->> (uix.lib/find-form rf-subscribe-call? form) (keep #(let [v (ana/resolve-var env (first %))] - (when (contains? config (:name v)) + (when (contains? re-frame-config (:name v)) (assoc v :source %)))))] (run! #(ana/warning ::non-reactive-re-frame-subscribe env %) sources))) diff --git a/docs/code-linting.md b/docs/code-linting.md index 53b02e11..d495cf6e 100644 --- a/docs/code-linting.md +++ b/docs/code-linting.md @@ -163,6 +163,15 @@ UIx will check for missing `:key` attribute when UIx element is rendered as a li ($ item {:title "hello" :x x :key x})) ;; no error ``` +## Config + +UIx's linter can be provided with external configuration that should live in `.uix/config.edn` file at the root of your project. + +```clojure +{:linters {:react-key {:enabled? false}}} +;; the rule is enabled by default +``` + # Reagent interop linter When migrating from Reagent + re-frame to UIx you might want to keep using re-frame or at least stick with it for some time, because migrating data management is not as simple as rewriting UI components. @@ -184,14 +193,10 @@ re-frame subscription (rf/subscribe [:user/id])) is non-reactive in UIx componen Read https://github.com/pitch-io/uix/blob/master/docs/interop-with-reagent.md#syncing-with-ratoms-and-re-frame for more context ``` -# Configuring the linter +## Config UIx's linter can be provided with external configuration that should live in `.uix/config.edn` file at the root of your project. -Currently the only onfiguration option available is for re-frame `subscribe` checks for cases when you are wrapping the function in application code. - -Example - ```clojure {:linters {:re-frame