From c198133769b9f140f057debe2391f844db12415e Mon Sep 17 00:00:00 2001 From: Icaro Motta Date: Mon, 28 Nov 2022 09:58:36 -0300 Subject: [PATCH] Update guidelines (#14445) --- doc/new-guidelines.md | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/doc/new-guidelines.md b/doc/new-guidelines.md index 9de12bf4b2..b3b61e26fb 100644 --- a/doc/new-guidelines.md +++ b/doc/new-guidelines.md @@ -62,6 +62,31 @@ with the source file using it. For a real example, see (do-something)]]) ``` +#### Styles def vs defn + +Always use `def` over `defn`, unless the style relies on dynamic values, such as +deref'ed atoms. + +```clojure +;; bad +(defn title-column [] + {:height 56}) + +;; good +(def title-column + {:height 56}) +``` + +```clojure +;; bad +(def community-card + {:background-color (colors/theme-colors colors/white colors/neutral-90)}) + +;; good +(defn community-card [] + {:background-color (colors/theme-colors colors/white colors/neutral-90)}) +``` + ### Using TODOs comments _TODO_ comments are used extensively in the codebase, but prefer to use them @@ -249,6 +274,31 @@ test macros `deftest` and `is`, which are ubiquitous in the Clojure community. (:require [cljs-time.coerce :as time.coerce])) ``` +### Namespace aliases + +Prefer the following namespace aliases: + +```clojure +[clojure.string :as string] +[taoensso.timbre :as log] +``` + +### Javascript interop + +Use [binaryage/oops](https://github.com/binaryage/cljs-oops) macros instead of +core interop macros. + +```clojure +;; bad +(fn [^js event] + (.-width (.-nativeEvent event))) + +;; good +(require '[oops.core :as oops]) +(fn [event] + (oops/oget event "nativeEvent.width")) +``` + ### Accessibility labels Use keywords instead of strings. As a bonus, remember keywords are cached in