Update guidelines (#14445)
This commit is contained in:
parent
6d5ff4aa92
commit
c198133769
|
@ -62,6 +62,31 @@ with the source file using it. For a real example, see
|
||||||
(do-something)]])
|
(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
|
### Using TODOs comments
|
||||||
|
|
||||||
_TODO_ comments are used extensively in the codebase, but prefer to use them
|
_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]))
|
(: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
|
### Accessibility labels
|
||||||
|
|
||||||
Use keywords instead of strings. As a bonus, remember keywords are cached in
|
Use keywords instead of strings. As a bonus, remember keywords are cached in
|
||||||
|
|
Loading…
Reference in New Issue